This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Folding of shifts by the sum of positive values
ClosedPublic

Authored by RKSimon on Oct 26 2016, 10:59 AM.

Details

Summary

This patch introduces the combine:

(C1 shift (A add C2)) -> ((C1 shift C2) shift A)
iff A and C2 are both positive

If both A and C2 are know to be positive then we can safely split into 2 shifts, permitting the folding of the Inner shift.

Fix for the spec benchmark case mentioned by @nadav on PR15141 (assuming we can prove that the inputs as positive).

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon updated this revision to Diff 75917.Oct 26 2016, 10:59 AM
RKSimon retitled this revision from to [InstCombine] Folding of shifts by the sum of positive values.
RKSimon updated this object.
RKSimon added reviewers: majnemer, nadav, spatel, filcab, andreadb.
RKSimon set the repository for this revision to rL LLVM.
RKSimon added subscribers: llvm-commits, nadav.
davide added a subscriber: davide.Oct 26 2016, 11:04 AM
davide added inline comments.
lib/Transforms/InstCombine/InstCombineShifts.cpp
53–54 ↗(On Diff #75917)

Can probably fold Inner (and so avoid the braces for the if)

majnemer added inline comments.Oct 26 2016, 11:06 AM
lib/Transforms/InstCombine/InstCombineShifts.cpp
48–52 ↗(On Diff #75917)

I think this could be simplified a little by using isKnownNonNegative.

RKSimon updated this revision to Diff 75948.Oct 26 2016, 2:12 PM

Updated based on Davide and David's comments.

davide accepted this revision.Oct 31 2016, 11:30 PM
davide added a reviewer: davide.

lgtm

This revision is now accepted and ready to land.Oct 31 2016, 11:30 PM
This revision was automatically updated to reflect the committed changes.