OSDN Git Service

[InstCombine] allow peeking through zext of shift amount to match rotate idioms ...
authorSanjay Patel <spatel@rotateright.com>
Mon, 20 Jul 2020 19:49:01 +0000 (15:49 -0400)
committerSanjay Patel <spatel@rotateright.com>
Mon, 20 Jul 2020 20:18:11 +0000 (16:18 -0400)
commit750f4c591d6c3a62887250783e2a63af0daaa630
tree3ab53d9acaf8227e698994cd7ff0ff6b0f845bba
parent92ec0c5da69e47c449499d9414b8f5ac8481abdb
[InstCombine] allow peeking through zext of shift amount to match rotate idioms (PR45701)

We might want to also allow trunc of the shift amount, but that seems less likely?

  define i32 @src(i32 %x, i1 %y) {
  %0:
    %rem = and i1 %y, 1
    %cmp = icmp eq i1 %rem, 0
    %sh_prom = zext i1 %rem to i32
    %sub = sub nsw nuw i1 0, %rem
    %sh_prom1 = zext i1 %sub to i32
    %shr = lshr i32 %x, %sh_prom1
    %shl = shl i32 %x, %sh_prom
    %or = or i32 %shl, %shr
    %r = select i1 %cmp, i32 %x, i32 %or
    ret i32 %r
  }
  =>
  define i32 @tgt(i32 %x, i1 %y) {
  %0:
    %t = zext i1 %y to i32
    %r = fshl i32 %x, i32 %x, i32 %t
    ret i32 %r
  }

  Transformation seems to be correct!

https://alive2.llvm.org/ce/z/xgMvE3

http://bugs.llvm.org/PR45701
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/rotate.ll