This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Propagate inequalities
ClosedPublic

Authored by nikic on Jul 12 2020, 8:53 AM.

Details

Summary

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.

Diff Detail

Event Timeline

nikic created this revision.Jul 12 2020, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2020, 8:53 AM
efriedma added inline comments.Jul 13 2020, 2:16 PM
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 .

nikic planned changes to this revision.Jul 16 2020, 12:26 PM

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.)

nikic updated this revision to Diff 280677.Jul 25 2020, 7:07 AM

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.

fhahn accepted this revision.Aug 2 2020, 2:13 PM

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.

This revision is now accepted and ready to land.Aug 2 2020, 2:13 PM
fhahn added a comment.Aug 3 2020, 10:26 AM

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.

efriedma accepted this revision.Aug 3 2020, 1:21 PM

LGTM

This revision was automatically updated to reflect the committed changes.