Teach SCCP to create notconstant lattice values from inequality comparisons and nonnull metadata, and update getConstant() to make use of them. Additionally isOverdefined() needs to be changed to consider notconstant an overdefined value.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Transforms/Scalar/SCCP.cpp | ||
---|---|---|
1345 | This is assuming branch on undef is UB, which other parts of LLVM still have issues with; see https://bugs.llvm.org/show_bug.cgi?id=46144 . |
Okay, taking this off the queue for now. It should be noted though that we already perform this optimization in quite a few places (inequalities are recognized by LVI and thus optimized in JT/CVP and nonnull inequalities in particular are recognized by ValueTracking, and as such optimized all over the place.)
Restrict patch to MayIncludeUndef=false, which is metadata and assumes, but not comparisons. This puts the basic machinery in place, and will get fully enabled once the MayIncludeUndef flag for branches gets flipped.
LGTM, thanks! I think avoiding this for branches for now should make us avoid PR46144, as we do in other places. Might be good to wait a day or so, in case Eli has further comments.
I think we could also try to model dereferenced pointers as non-null with a new predicate. In particular, we could create ssa_copys for dereferenced pointers, attach a predicate and rename all dominated uses. Not sure how useful/expensive that would be though. Also, ideally we would want to rename all pointers to the same underlying object.
This is assuming branch on undef is UB, which other parts of LLVM still have issues with; see https://bugs.llvm.org/show_bug.cgi?id=46144 .