[llvm] [SCEV] Add poison/undef canonicalization for SCEVAddExpr, SCEVAddRecExpr. (PR #170741)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 4 23:58:06 PST 2025
https://github.com/nikic requested changes to this pull request.
At least for undef, I'd really rather not go there. The problem is that undef folds are generally based on non-determinism, and non-deterministic folds can generally only be performed if the non-deterministic choice is actually materialized in IR, otherwise it's possible to make multiple conflicting choices where only one is allowed. As SCEV does abstract modelling that is not reflected in IR, it is generally prohibited from performing nondet reasoning (see AllowNonDeterministic=false flags in use).
For example, taking the `{start,+,undef} -> start` fold, this requires the assumption that `undef = 0`. If SCEV makes this assumption and performs transforms based on it, but later some other code decides that this `undef` is actually 1, this will result in a miscompile.
I think the other two folds might be fine because they are undef -> undef folds and thus don't require a specific choice, but unless these undef folds are super useful, I don't think this is worth the risk.
https://github.com/llvm/llvm-project/pull/170741
More information about the llvm-commits
mailing list