This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyIndVar] Simplify non-overflowing saturating add/sub
ClosedPublic

Authored by nikic on Jun 2 2019, 2:01 AM.

Details

Summary

If we can detect that saturating math that depends on an IV cannot overflow, replace it with simple math. This is similar to the CVP optimization from D62703, just based on a different underlying analysis (SCEV vs LVI) that catches different cases.

One case this doesn't handle yet is if the IV calculation itself uses a saturating counter.

Diff Detail

Event Timeline

nikic created this revision.Jun 2 2019, 2:01 AM

This looks rather similar to the eliminateOverflowIntrinsic(), but i don't have knowledge about this pass.

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
475–476

Hm, this is because we didn't deal with non-ExtractValueInst uses of WO?
Since we know the overflow won't happen, those can be simply folded to a single insert, no?

nikic marked an inline comment as done.Jun 5 2019, 12:35 AM
nikic added inline comments.
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
475–476

That should be possible, and that's what we do in other places doing this optimization. I think that this code is going out of the way to replace the ExtractValues instead because SCEV cannot reason about aggregate operations.

reames accepted this revision.Jun 13 2019, 2:44 PM

LGTM

This revision is now accepted and ready to land.Jun 13 2019, 2:44 PM
This revision was automatically updated to reflect the committed changes.