Skip to content

Commit

Permalink
[X86] Add peephole for masked rotate amount
Browse files Browse the repository at this point in the history
Extend what's currently done for shift because the HW performs this masking
implicitly:

   (rotl:i32 x, (and y, 31)) -> (rotl:i32 x, y)

I use the newly factored out multiclass that was only supporting shifts so
far.

For testing I extended my testcase for the new rotation idiom.

<rdar://problem/15295856>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203718 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
anemet committed Mar 12, 2014
1 parent 9367c49 commit a65ca9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Target/X86/X86InstrCompiler.td
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,8 @@ multiclass MaskedShiftAmountPats<SDNode frag, string name> {
defm : MaskedShiftAmountPats<shl, "SHL">;
defm : MaskedShiftAmountPats<srl, "SHR">;
defm : MaskedShiftAmountPats<sra, "SAR">;
defm : MaskedShiftAmountPats<rotl, "ROL">;
defm : MaskedShiftAmountPats<rotr, "ROR">;

// (anyext (setcc_carry)) -> (setcc_carry)
def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
Expand Down
8 changes: 8 additions & 0 deletions test/CodeGen/X86/rotate4.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

define i32 @rotate_left_32(i32 %a, i32 %b) {
; CHECK-LABEL: rotate_left_32:
; CHECK-NOT: and
; CHECK: roll
entry:
%and = and i32 %b, 31
Expand All @@ -18,6 +19,7 @@ entry:

define i32 @rotate_right_32(i32 %a, i32 %b) {
; CHECK-LABEL: rotate_right_32:
; CHECK-NOT: and
; CHECK: rorl
entry:
%and = and i32 %b, 31
Expand All @@ -31,6 +33,7 @@ entry:

define i64 @rotate_left_64(i64 %a, i64 %b) {
; CHECK-LABEL: rotate_left_64:
; CHECK-NOT: and
; CHECK: rolq
entry:
%and = and i64 %b, 63
Expand All @@ -44,6 +47,7 @@ entry:

define i64 @rotate_right_64(i64 %a, i64 %b) {
; CHECK-LABEL: rotate_right_64:
; CHECK-NOT: and
; CHECK: rorq
entry:
%and = and i64 %b, 63
Expand All @@ -59,6 +63,7 @@ entry:

define void @rotate_left_m32(i32 *%pa, i32 %b) {
; CHECK-LABEL: rotate_left_m32:
; CHECK-NOT: and
; CHECK: roll
; no store:
; CHECK-NOT: mov
Expand All @@ -76,6 +81,7 @@ entry:

define void @rotate_right_m32(i32 *%pa, i32 %b) {
; CHECK-LABEL: rotate_right_m32:
; CHECK-NOT: and
; CHECK: rorl
; no store:
; CHECK-NOT: mov
Expand All @@ -93,6 +99,7 @@ entry:

define void @rotate_left_m64(i64 *%pa, i64 %b) {
; CHECK-LABEL: rotate_left_m64:
; CHECK-NOT: and
; CHECK: rolq
; no store:
; CHECK-NOT: mov
Expand All @@ -110,6 +117,7 @@ entry:

define void @rotate_right_m64(i64 *%pa, i64 %b) {
; CHECK-LABEL: rotate_right_m64:
; CHECK-NOT: and
; CHECK: rorq
; no store:
; CHECK-NOT: mov
Expand Down

0 comments on commit a65ca9d

Please sign in to comment.