You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This set of examples shows that undefined ‘select’ (and conditional branch) conditions can go either way, but they have to come from one of the two operands
Later on in this section, the following is stated:
Branching on an undefined value is undefined behavior. This explains optimizations that depend on branch conditions to construct predicates, such as Correlated Value Propagation and Global Value Numbering. In case of switch instruction, the branch condition should be frozen, otherwise it is undefined behavior.
The first quote seems to suggest that a conditional branch on undef is a non-deterministic jump. The second statement claims that it is in fact UB, unless the undef value has been frozen first.
My interpretation of what is meant is the following:
select instructions don't count as branches, and selecting with an undef condition is allowed.
Branching on an undef value is UB (i.e., if the value represents multiple values, branching on it is UB).
Under this interpretation the first quote isn't necessarily wrong (the program can do anything when UB is encountered, including going down one of the branches), but I assume that isn't the intention, and maybe this should be rephrased to be more clear --- perhaps we should just remove the "(and conditional branch)" part?
Would love to hear what other people think, especially if I'm misunderstanding something!
Thanks!
The text was updated successfully, but these errors were encountered:
In the section on undefined values https://llvm.org/docs/LangRef.html#undefined-values
LangRef provides the following example:
And states:
Later on in this section, the following is stated:
The first quote seems to suggest that a conditional branch on
undef
is a non-deterministic jump. The second statement claims that it is in fact UB, unless theundef
value has been frozen first.My interpretation of what is meant is the following:
select
instructions don't count as branches, and selecting with anundef
condition is allowed.undef
value is UB (i.e., if the value represents multiple values, branching on it is UB).Under this interpretation the first quote isn't necessarily wrong (the program can do anything when UB is encountered, including going down one of the branches), but I assume that isn't the intention, and maybe this should be rephrased to be more clear --- perhaps we should just remove the "(and conditional branch)" part?
Would love to hear what other people think, especially if I'm misunderstanding something!
Thanks!
The text was updated successfully, but these errors were encountered: