Skip to content

Commit 9e856fa

Browse files
committed
Merging r348461:
------------------------------------------------------------------------ r348461 | lebedevri | 2018-12-06 00:11:20 -0800 (Thu, 06 Dec 2018) | 4 lines [NFC][InstCombine] Add more miscompile tests for foldICmpWithLowBitMaskedVal() We also have to me aware of vector constants. If at least one element is -1, we can't transform. ------------------------------------------------------------------------ llvm-svn: 348535
1 parent 2ea572a commit 9e856fa

File tree

2 files changed

+74
-26
lines changed

2 files changed

+74
-26
lines changed

llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ define i1 @p0(i8 %x) {
2323
ret i1 %ret
2424
}
2525

26-
define i1 @pv(i8 %x, i8 %y) {
27-
; CHECK-LABEL: @pv(
28-
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
29-
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
30-
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[TMP1]], [[X]]
31-
; CHECK-NEXT: ret i1 [[RET]]
32-
;
33-
%tmp0 = lshr i8 -1, %y
34-
%tmp1 = and i8 %tmp0, %x
35-
%ret = icmp sge i8 %tmp1, %x
36-
ret i1 %ret
37-
}
38-
3926
; ============================================================================ ;
4027
; Vector tests
4128
; ============================================================================ ;
@@ -198,3 +185,40 @@ define <2 x i1> @n2(<2 x i8> %x) {
198185
%ret = icmp sge <2 x i8> %tmp0, %x
199186
ret <2 x i1> %ret
200187
}
188+
189+
; ============================================================================ ;
190+
; Potential miscompiles.
191+
; ============================================================================ ;
192+
193+
define i1 @nv(i8 %x, i8 %y) {
194+
; CHECK-LABEL: @nv(
195+
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
196+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
197+
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[TMP1]], [[X]]
198+
; CHECK-NEXT: ret i1 [[RET]]
199+
;
200+
%tmp0 = lshr i8 -1, %y
201+
%tmp1 = and i8 %tmp0, %x
202+
%ret = icmp sge i8 %tmp1, %x
203+
ret i1 %ret
204+
}
205+
206+
define <2 x i1> @n3_vec(<2 x i8> %x) {
207+
; CHECK-LABEL: @n3_vec(
208+
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <2 x i8> [[X:%.*]], <i8 4, i8 0>
209+
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
210+
;
211+
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
212+
%ret = icmp sge <2 x i8> %tmp0, %x
213+
ret <2 x i1> %ret
214+
}
215+
216+
define <3 x i1> @n4_vec(<3 x i8> %x) {
217+
; CHECK-LABEL: @n4_vec(
218+
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 0>
219+
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
220+
;
221+
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 -1>
222+
%ret = icmp sge <3 x i8> %tmp0, %x
223+
ret <3 x i1> %ret
224+
}

llvm/test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ define i1 @p0(i8 %x) {
2323
ret i1 %ret
2424
}
2525

26-
define i1 @pv(i8 %x, i8 %y) {
27-
; CHECK-LABEL: @pv(
28-
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
29-
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
30-
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
31-
; CHECK-NEXT: ret i1 [[RET]]
32-
;
33-
%tmp0 = lshr i8 -1, %y
34-
%tmp1 = and i8 %tmp0, %x
35-
%ret = icmp slt i8 %tmp1, %x
36-
ret i1 %ret
37-
}
38-
3926
; ============================================================================ ;
4027
; Vector tests
4128
; ============================================================================ ;
@@ -198,3 +185,40 @@ define <2 x i1> @n2(<2 x i8> %x) {
198185
%ret = icmp slt <2 x i8> %tmp0, %x
199186
ret <2 x i1> %ret
200187
}
188+
189+
; ============================================================================ ;
190+
; Potential miscompiles.
191+
; ============================================================================ ;
192+
193+
define i1 @nv(i8 %x, i8 %y) {
194+
; CHECK-LABEL: @nv(
195+
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
196+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
197+
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
198+
; CHECK-NEXT: ret i1 [[RET]]
199+
;
200+
%tmp0 = lshr i8 -1, %y
201+
%tmp1 = and i8 %tmp0, %x
202+
%ret = icmp slt i8 %tmp1, %x
203+
ret i1 %ret
204+
}
205+
206+
define <2 x i1> @n3(<2 x i8> %x) {
207+
; CHECK-LABEL: @n3(
208+
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 3, i8 -1>
209+
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
210+
;
211+
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
212+
%ret = icmp slt <2 x i8> %tmp0, %x
213+
ret <2 x i1> %ret
214+
}
215+
216+
define <3 x i1> @n4(<3 x i8> %x) {
217+
; CHECK-LABEL: @n4(
218+
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 -1>
219+
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
220+
;
221+
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 -1>
222+
%ret = icmp slt <3 x i8> %tmp0, %x
223+
ret <3 x i1> %ret
224+
}

0 commit comments

Comments
 (0)