[X86] Use SARX/SHLX/SHLX instructions for (shift x (and y, (BitWidth-1)))

Fixes PR33841.

llvm-svn: 308591
This commit is contained in:
Craig Topper 2017-07-20 06:19:55 +00:00
parent bdd114ef9d
commit 33225ef314
3 changed files with 44 additions and 28 deletions

View File

@ -1680,6 +1680,37 @@ multiclass MaskedDoubleShiftAmountPats<SDNode frag, string name> {
defm : MaskedDoubleShiftAmountPats<X86shld, "SHLD">;
defm : MaskedDoubleShiftAmountPats<X86shrd, "SHRD">;
let Predicates = [HasBMI2] in {
let AddedComplexity = 1 in {
def : Pat<(sra GR32:$src1, (and GR8:$src2, immShift32)),
(SARX32rr GR32:$src1,
(INSERT_SUBREG
(i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
def : Pat<(sra GR64:$src1, (and GR8:$src2, immShift64)),
(SARX64rr GR64:$src1,
(INSERT_SUBREG
(i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
def : Pat<(srl GR32:$src1, (and GR8:$src2, immShift32)),
(SHRX32rr GR32:$src1,
(INSERT_SUBREG
(i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
def : Pat<(srl GR64:$src1, (and GR8:$src2, immShift64)),
(SHRX64rr GR64:$src1,
(INSERT_SUBREG
(i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
def : Pat<(shl GR32:$src1, (and GR8:$src2, immShift32)),
(SHLX32rr GR32:$src1,
(INSERT_SUBREG
(i32 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
def : Pat<(shl GR64:$src1, (and GR8:$src2, immShift64)),
(SHLX64rr GR64:$src1,
(INSERT_SUBREG
(i64 (IMPLICIT_DEF)), GR8:$src2, sub_8bit))>;
}
}
// (anyext (setcc_carry)) -> (setcc_carry)
def : Pat<(i16 (anyext (i8 (X86setcc_c X86_COND_B, EFLAGS)))),
(SETB_C16r)>;

View File

@ -52,7 +52,7 @@ define void @foo() local_unnamed_addr {
; X86-NEXT: movl $9, %esi
; X86-NEXT: xorl %ebp, %ebp
; X86-NEXT: shldl %cl, %esi, %ebp
; X86-NEXT: shll %cl, %esi
; X86-NEXT: shlxl %ecx, %esi, %esi
; X86-NEXT: testb $32, %cl
; X86-NEXT: cmovnel %esi, %ebp
; X86-NEXT: movl $0, %ecx

View File

@ -213,16 +213,13 @@ define i64 @ashr64p(i64* %p, i64 %shamt) nounwind uwtable readnone {
define i32 @shl32and(i32 %t, i32 %val) nounwind {
; BMI2-LABEL: shl32and:
; BMI2: # BB#0:
; BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
; BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
; BMI2-NEXT: shll %cl, %eax
; BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
; BMI2-NEXT: shlxl %eax, {{[0-9]+}}(%esp), %eax
; BMI2-NEXT: retl
;
; BMI264-LABEL: shl32and:
; BMI264: # BB#0:
; BMI264-NEXT: movl %edi, %ecx
; BMI264-NEXT: shll %cl, %esi
; BMI264-NEXT: movl %esi, %eax
; BMI264-NEXT: shlxl %edi, %esi, %eax
; BMI264-NEXT: retq
%shamt = and i32 %t, 31
%res = shl i32 %val, %shamt
@ -232,9 +229,7 @@ define i32 @shl32and(i32 %t, i32 %val) nounwind {
define i64 @shl64and(i64 %t, i64 %val) nounwind {
; BMI264-LABEL: shl64and:
; BMI264: # BB#0:
; BMI264-NEXT: movl %edi, %ecx
; BMI264-NEXT: shlq %cl, %rsi
; BMI264-NEXT: movq %rsi, %rax
; BMI264-NEXT: shlxq %rdi, %rsi, %rax
; BMI264-NEXT: retq
%shamt = and i64 %t, 63
%res = shl i64 %val, %shamt
@ -244,16 +239,13 @@ define i64 @shl64and(i64 %t, i64 %val) nounwind {
define i32 @lshr32and(i32 %t, i32 %val) nounwind {
; BMI2-LABEL: lshr32and:
; BMI2: # BB#0:
; BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
; BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
; BMI2-NEXT: shrl %cl, %eax
; BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
; BMI2-NEXT: shrxl %eax, {{[0-9]+}}(%esp), %eax
; BMI2-NEXT: retl
;
; BMI264-LABEL: lshr32and:
; BMI264: # BB#0:
; BMI264-NEXT: movl %edi, %ecx
; BMI264-NEXT: shrl %cl, %esi
; BMI264-NEXT: movl %esi, %eax
; BMI264-NEXT: shrxl %edi, %esi, %eax
; BMI264-NEXT: retq
%shamt = and i32 %t, 31
%res = lshr i32 %val, %shamt
@ -263,9 +255,7 @@ define i32 @lshr32and(i32 %t, i32 %val) nounwind {
define i64 @lshr64and(i64 %t, i64 %val) nounwind {
; BMI264-LABEL: lshr64and:
; BMI264: # BB#0:
; BMI264-NEXT: movl %edi, %ecx
; BMI264-NEXT: shrq %cl, %rsi
; BMI264-NEXT: movq %rsi, %rax
; BMI264-NEXT: shrxq %rdi, %rsi, %rax
; BMI264-NEXT: retq
%shamt = and i64 %t, 63
%res = lshr i64 %val, %shamt
@ -275,16 +265,13 @@ define i64 @lshr64and(i64 %t, i64 %val) nounwind {
define i32 @ashr32and(i32 %t, i32 %val) nounwind {
; BMI2-LABEL: ashr32and:
; BMI2: # BB#0:
; BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
; BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
; BMI2-NEXT: sarl %cl, %eax
; BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
; BMI2-NEXT: sarxl %eax, {{[0-9]+}}(%esp), %eax
; BMI2-NEXT: retl
;
; BMI264-LABEL: ashr32and:
; BMI264: # BB#0:
; BMI264-NEXT: movl %edi, %ecx
; BMI264-NEXT: sarl %cl, %esi
; BMI264-NEXT: movl %esi, %eax
; BMI264-NEXT: sarxl %edi, %esi, %eax
; BMI264-NEXT: retq
%shamt = and i32 %t, 31
%res = ashr i32 %val, %shamt
@ -294,9 +281,7 @@ define i32 @ashr32and(i32 %t, i32 %val) nounwind {
define i64 @ashr64and(i64 %t, i64 %val) nounwind {
; BMI264-LABEL: ashr64and:
; BMI264: # BB#0:
; BMI264-NEXT: movl %edi, %ecx
; BMI264-NEXT: sarq %cl, %rsi
; BMI264-NEXT: movq %rsi, %rax
; BMI264-NEXT: sarxq %rdi, %rsi, %rax
; BMI264-NEXT: retq
%shamt = and i64 %t, 63
%res = ashr i64 %val, %shamt