This is an archive of the discontinued LLVM Phabricator instance.

[SeparateConstOffsetFromGEP] sext(a)+sext(b) => sext(a+b) when a+b can't sign-overflow.
ClosedPublic

Authored by jingyue on Aug 13 2015, 10:50 AM.

Details

Summary

This patch implements my promised optimization to reunites certain sexts from
operands after we extract the constant offset. See the header comment of
reuniteExts for its motivation.

One key building block that enables this optimization is Bjarke's poison value
analysis (D11212). That helps to prove "a +nsw b" can't overflow.

Diff Detail

Event Timeline

jingyue updated this revision to Diff 32080.Aug 13 2015, 10:50 AM
jingyue retitled this revision from to [SeparateConstOffsetFromGEP] sext(a)+sext(b) => sext(a+b) when a+b can't sign-overflow..
jingyue updated this object.
jingyue added a reviewer: broune.
jingyue added a subscriber: llvm-commits.
broune added inline comments.Aug 13 2015, 2:47 PM
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
1098

a -> an

1101

I think that you also need to check that I has a NSW or NUW flag.

I wonder if it would be faster to insert all the add/sub dominators with such a flag and then check isKnownNotFullPoison(I) only when an instruction is returned from findClosestMatchingDominator().

jingyue added inline comments.Aug 13 2015, 2:58 PM
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
1101

I did check that I has a NSW flag by using m_NSWAdd and m_NSWSub.

It's hard to tell. In the current way, the hash table is smaller and findClosestMatchingDominator more likely returns nullptr. Though I agree it calls isKnownNotFullPoison more if matched SCEVs are rare.

broune accepted this revision.Aug 13 2015, 5:06 PM
broune edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Aug 13 2015, 5:06 PM
jingyue updated this revision to Diff 32114.Aug 13 2015, 5:14 PM
jingyue edited edge metadata.

fixed a typo and add more comments on the test

jingyue updated this revision to Diff 32117.Aug 13 2015, 5:30 PM

rebase against master

jingyue closed this revision.Aug 13 2015, 7:02 PM