This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Support pulling left shifts through a subtract with constant LHS
ClosedPublic

Authored by craig.topper on Aug 7 2017, 10:37 PM.

Diff Detail

Event Timeline

craig.topper created this revision.Aug 7 2017, 10:37 PM

Use Builder.CreateShl since we know this is a left shift.

efriedma edited edge metadata.Aug 8 2017, 11:13 AM

For reference, http://rise4fun.com/Alive/8l5 .

This transform throws nsw/nuw flags; can we preserve them in some situations?

lib/Transforms/InstCombine/InstCombineShifts.cpp
525

Maybe add a comment writing out the transform in mathematical terms? (e.g. "2 * (A - B)" -> "2 * A - 2 * B").

test/Transforms/InstCombine/sub.ll
1082

This could use a couple more tests, to specifically show the transform this patch adds.

zzheng added a subscriber: zzheng.Aug 8 2017, 11:45 AM

Add a simpler test case and a more mathematical comment.

Not sure how to preserve NSW/NUW without calling computeKnownBits. Any ideas?

efriedma accepted this revision.Aug 8 2017, 1:03 PM

LGTM, with one small question.

lib/Transforms/InstCombine/InstCombineShifts.cpp
518

It looks like this can match a vector? If it can, please add a vector testcase.

This revision is now accepted and ready to land.Aug 8 2017, 1:03 PM

Good catch. I'll add a vector test.

This revision was automatically updated to reflect the committed changes.