This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Use range metadata for loads and calls
ClosedPublic

Authored by nikic on Jul 5 2020, 12:51 PM.

Details

Summary

When all else fails, use range metadata to constrain the result of loads and calls. It should also be possible to use !nonnull, but that would require some general support for inequalities in SCCP first.

Diff Detail

Event Timeline

nikic created this revision.Jul 5 2020, 12:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2020, 12:51 PM
fhahn accepted this revision.Jul 6 2020, 2:31 PM

LGTM, thanks.

It should also be possible to use !nonnull

using ValueLattice::getNot/markNotConstant should possibly just work? For icmps we use ValueLattice's helpers, they should be able to deal with it, unless we bail out for pointers somewhere in SCCP.

llvm/lib/Transforms/Scalar/SCCP.cpp
1107

I think we have something similar in LVI. Might be good to move the common logic to ValueLattice

1121

For volatile loads, I think we could still use the range info if present? We are just not allowed to remove the volatile operation, right?

This revision is now accepted and ready to land.Jul 6 2020, 2:31 PM
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.Jul 7 2020, 12:17 PM
nikic added inline comments.
llvm/lib/Transforms/Scalar/SCCP.cpp
1121

This would be safe. I briefly tried this, but found that SCCP would zap the volatile load, because it only uses isSafeToRemove() to determine whether instructions can be dropped. We would have to replace that with something stronger, like isInstructionTriviallyDead(). Do you think that would be worthwhile?