HomePhabricator

[InstCombine] allow peeking through zext of shift amount to match rotate idioms…

Authored by spatel on Mon, Jul 20, 12:49 PM.

Description

[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

Details

Committed
spatelMon, Jul 20, 1:18 PM
Parents
rG92ec0c5da69e: [InstCombine] add tests for funnel shift/rotate with narrow shift amount; NFC
Branches
Unknown
Tags
Unknown