oracle/graal · error · GraalError

Wrong usage of branch probability injection + this

Error message

Wrong usage of branch probability injection  + this

What it means

After simplification, if the BranchProbabilityNode's condition was consumed but some usage remains that is not the recognized pattern, simplify() throws 'Wrong usage of branch probability injection' — unless isSubstitutionGraph() (exactly one usage which is a ReturnNode) holds, which supports returning the probability value itself from snippets. The error means the intrinsic result was consumed in a way that never feeds an if-condition, so the probability can never be injected.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/BranchProbabilityNode.java:239

                                    ((ConditionalNode) currentCondition).trueValue().isConstant() && ((ConditionalNode) currentCondition).falseValue().isConstant()) {
                        for (IntegerEqualsNode eq : currentCondition.usages().filter(IntegerEqualsNode.class).snapshot()) {
                            if (eq.getY().isConstant() || eq.getX().isConstant()) {
                                ValueNode canonical = eq.canonical(tool);
                                if (canonical != eq && canonical != null) {
                                    tool.addToWorkList(eq.usages());
                                    eq.replaceAtUsages(graph().addOrUnique(canonical));
                                    GraphUtil.killWithUnusedFloatingInputs(eq);
                                }
                            }
                        }
                    }
                    if (currentCondition.hasUsages()) {
                        tool.addToWorkList(currentCondition.usages());
                    }
                }
            } else {
                if (!isSubstitutionGraph()) {
                    throw new GraalError("Wrong usage of branch probability injection " + this);
                }
            }
        }
    }

    private boolean isSubstitutionGraph() {
        return hasExactlyOneUsage() && usages().first() instanceof ReturnNode;
    }

    /**
     * Normally a branch probability should be consumed directly as a condition, but in some cases
     * it can be used as a value itself. For example:
     *
     * <pre>
     * boolean helper() {
     *     if (probability(a, ...) || probability(b, ...) || probability(c, condition)) {
     *         return true;
     *     } else {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Use the intrinsic result directly as the if condition: if (probability(p, cond)) { ... }
  2. If you need the value returned (substitution graph), keep exactly one usage that is the ReturnNode — any other shape throws
  3. Remove the intrinsic if you only need the boolean, not the probability

Example fix

// before
boolean b = BranchProbabilityNode.probability(p, cond);
map.put(k, b);          // non-condition usage -> error
if (map.get(k)) { ... }

// after
if (BranchProbabilityNode.probability(p, cond)) { ... }
Defensive patterns

Strategy: validation

Validate before calling

// Structural check: the intrinsic result must feed an if-condition (or a single return)
// lint rule / review check: forbid assignments or map/list insertions of probability(...) results
boolean ok = usage instanceof IfNode condition || (singleUsage && usage instanceof ReturnNode);

Prevention

When it happens

Trigger: Using probability(p, cond)'s boolean result in non-condition positions: storing it in a variable, passing it to another method, combining it with && / || in ways the simplifier cannot rewrite, or using it as a value — while not matching the single-ReturnNode substitution exception.

Common situations: Refactoring a snippet so the intrinsic result flows through a phi or helper before reaching an if; new snippet authors assuming probability() works like a plain boolean; using it inside complex boolean expressions.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/429852a1ddf12ec1. Report an issue: GitHub.