OSDN Git Service

[InstCombine] canonicalize rotate patterns with cmp/select
authorSanjay Patel <spatel@rotateright.com>
Tue, 13 Nov 2018 22:47:24 +0000 (22:47 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 13 Nov 2018 22:47:24 +0000 (22:47 +0000)
commit3334995891e808518824f2fe8bbc434be7e67307
tree2ab63c82a3fd4b6576d0b6a730597d734f79ea5b
parent14f489a3e774db4d4ae400564762c4ff61a9fa10
[InstCombine] canonicalize rotate patterns with cmp/select

The cmp+branch variant of this pattern is shown in:
https://bugs.llvm.org/show_bug.cgi?id=34924
...and as discussed there, we probably can't transform
that without a rotate intrinsic. We do have that now
via funnel shift, but we're not quite ready to
canonicalize IR to that form yet. The case with 'select'
should already be transformed though, so that's this patch.

The sequence with negation followed by masking is what we
use in the backend and partly in clang (though that part
should be updated).

https://rise4fun.com/Alive/TplC
  %cmp = icmp eq i32 %shamt, 0
  %sub = sub i32 32, %shamt
  %shr = lshr i32 %x, %shamt
  %shl = shl i32 %x, %sub
  %or = or i32 %shr, %shl
  %r = select i1 %cmp, i32 %x, i32 %or
  =>
  %neg = sub i32 0, %shamt
  %masked = and i32 %shamt, 31
  %maskedneg = and i32 %neg, 31
  %shl2 = lshr i32 %x, %masked
  %shr2 = shl i32 %x, %maskedneg
  %r = or i32 %shl2, %shr2

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346807 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/rotate.ll