[SelectionDAG] fix bug in translating funnel shift with non-power-of-2 type
authorSanjay Patel <spatel@rotateright.com>
Wed, 1 Aug 2018 17:17:08 +0000 (17:17 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 1 Aug 2018 17:17:08 +0000 (17:17 +0000)
commit8aac22e06a196541961cd6d6cc46ffd4f39b60c3
treece54e012d6bc3a7d3f1e697f5ab4cdd9fdb69bbd
parent0bb8d83c89321c0bfe955c5e2b2069a2870912d4
[SelectionDAG] fix bug in translating funnel shift with non-power-of-2 type

The bug is visible in the constant-folded x86 tests. We can't use the
negated shift amount when the type is not power-of-2:
https://rise4fun.com/Alive/US1r

...so in that case, use the regular lowering that includes a select
to guard against a shift-by-bitwidth. This path is improved by only
calculating the modulo shift amount once now.

Also, improve the rotate (with power-of-2 size) lowering to use
a negate rather than subtract from bitwidth. This improves the
codegen whether we have a rotate instruction or not (although
we can still see that we're not matching to a legal rotate in
all cases).

llvm-svn: 338592
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/test/CodeGen/AArch64/funnel-shift-rot.ll
llvm/test/CodeGen/AArch64/funnel-shift.ll
llvm/test/CodeGen/PowerPC/funnel-shift-rot.ll
llvm/test/CodeGen/PowerPC/funnel-shift.ll
llvm/test/CodeGen/X86/funnel-shift-rot.ll
llvm/test/CodeGen/X86/funnel-shift.ll