Skip to content

Commit 982ebeb

Browse files
committed
[X86] Pre-commit test case for bug in combineShiftRightArithmetic
It has been noticed that combineShiftRightArithmetic isn't dealing properly with large shift amounts, as demonstrated by the test case added in this commit. I think the problem partly is related to X86 using i8 as shift amount type during ISel. So shift amount larger then 127 may be treated as negative shift amounts if not being careful.
1 parent 8a84596 commit 982ebeb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

llvm/test/CodeGen/X86/sar_fold.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,47 @@ define i32 @shl24sar25(i32 %a) #0 {
4444
%2 = ashr exact i32 %1, 25
4545
ret i32 %2
4646
}
47+
48+
define void @shl144sar48(ptr %p) #0 {
49+
; CHECK-LABEL: shl144sar48:
50+
; CHECK: # %bb.0:
51+
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
52+
; CHECK-NEXT: movswl (%eax), %ecx
53+
; CHECK-NEXT: movl %ecx, %edx
54+
; CHECK-NEXT: sarl $31, %edx
55+
; CHECK-NEXT: shldl $2, %ecx, %edx
56+
; CHECK-NEXT: shll $2, %ecx
57+
; CHECK-NEXT: movl %ecx, 12(%eax)
58+
; CHECK-NEXT: movl %edx, 16(%eax)
59+
; CHECK-NEXT: movl $0, 8(%eax)
60+
; CHECK-NEXT: movl $0, 4(%eax)
61+
; CHECK-NEXT: movl $0, (%eax)
62+
; CHECK-NEXT: retl
63+
%a = load i160, ptr %p
64+
%1 = shl i160 %a, 144
65+
%2 = ashr exact i160 %1, 46
66+
store i160 %2, ptr %p
67+
ret void
68+
}
69+
70+
; This is incorrect. The 142 least significant bits in the stored value should
71+
; be zero, and but 142-157 should be taken from %a with a sign-extend into the
72+
; two most significant bits.
73+
define void @shl144sar2(ptr %p) #0 {
74+
; CHECK-LABEL: shl144sar2:
75+
; CHECK: # %bb.0:
76+
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
77+
; CHECK-NEXT: movswl (%eax), %ecx
78+
; CHECK-NEXT: sarl $31, %ecx
79+
; CHECK-NEXT: movl %ecx, 16(%eax)
80+
; CHECK-NEXT: movl %ecx, 8(%eax)
81+
; CHECK-NEXT: movl %ecx, 12(%eax)
82+
; CHECK-NEXT: movl %ecx, 4(%eax)
83+
; CHECK-NEXT: movl %ecx, (%eax)
84+
; CHECK-NEXT: retl
85+
%a = load i160, ptr %p
86+
%1 = shl i160 %a, 144
87+
%2 = ashr exact i160 %1, 2
88+
store i160 %2, ptr %p
89+
ret void
90+
}

0 commit comments

Comments
 (0)