This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold funnel shift amount based on demanded bits
ClosedPublic

Authored by spatel on Nov 13 2018, 9:15 AM.

Details

Summary

The shift amount of a funnel shift is modulo the scalar bitwidth:
http://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic
...so we can use demanded bits analysis on that operand to simplify it.

This is another step towards canonicalizing {shift/shift/or} to the intrinsic in IR.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Nov 13 2018, 9:15 AM
fabiang added inline comments.Nov 13 2018, 10:00 AM
lib/Transforms/InstCombine/InstCombineCalls.cpp
1998 ↗(On Diff #173862)

Need to check whether BitWidth is a power of 2 here, this is incorrect for non-pow2. Take the BitWidth=33 case in the tests below.

A mod-33 funnel shift by say 65 should shift by 65-33=32 not 65 % 64 = 1.

test/Transforms/InstCombine/fsh.ll
46 ↗(On Diff #173862)

Can't eliminate the AND here, the reduction mod 64 doesn't interact with the mod-33 funnel shift amount in a useful way. (That I can see.)

57 ↗(On Diff #173862)

Same here.

spatel added inline comments.Nov 13 2018, 10:21 AM
lib/Transforms/InstCombine/InstCombineCalls.cpp
1998 ↗(On Diff #173862)

Oops, yes. Will fix here and the test comments.

spatel updated this revision to Diff 173889.Nov 13 2018, 11:23 AM
spatel marked 3 inline comments as done.

Patch updated:
Fix the logic - for non-power-of-2 bitwidths, all bets are off.

fabiang accepted this revision.Nov 13 2018, 11:28 AM

This one looks good!

This revision is now accepted and ready to land.Nov 13 2018, 11:28 AM

This one looks good!

Thank you for catching the logic bug...I think that's the 2nd time I fell on that!

This revision was automatically updated to reflect the committed changes.