Skip to content

Commit 8f1c940

Browse files
committed
[InstCombine] Add tests for combining (icmp eq/ne (and X, P2), (and X, -P2)); NFC
1 parent 1e92ad4 commit 8f1c940

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

llvm/test/Transforms/InstCombine/and-compare.ll

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
55
target triple = "x86_64-unknown-linux-gnu"
66

7+
declare void @use.i8(i8)
8+
79
; Should be optimized to one and.
810
define i1 @test1(i32 %a, i32 %b) {
911
; CHECK-LABEL: @test1(
@@ -75,3 +77,100 @@ define <2 x i1> @test3vec(<2 x i64> %A) {
7577
ret <2 x i1> %cmp
7678
}
7779

80+
define i1 @test_ne_cp2(i8 %x, i8 %yy) {
81+
; CHECK-LABEL: @test_ne_cp2(
82+
; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -16
83+
; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 16
84+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]])
85+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]])
86+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]]
87+
; CHECK-NEXT: ret i1 [[R]]
88+
;
89+
%and_x_neg_y = and i8 %x, -16
90+
%and_x_y = and i8 %x, 16
91+
call void @use.i8(i8 %and_x_neg_y)
92+
call void @use.i8(i8 %and_x_y)
93+
%r = icmp ne i8 %and_x_neg_y, %and_x_y
94+
ret i1 %r
95+
}
96+
97+
define i1 @test_ne_cp2_2(i8 %x, i8 %yy) {
98+
; CHECK-LABEL: @test_ne_cp2_2(
99+
; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -4
100+
; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 4
101+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]])
102+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]])
103+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND_X_Y]], [[AND_X_NEG_Y]]
104+
; CHECK-NEXT: ret i1 [[R]]
105+
;
106+
%and_x_neg_y = and i8 %x, -4
107+
%and_x_y = and i8 %x, 4
108+
call void @use.i8(i8 %and_x_neg_y)
109+
call void @use.i8(i8 %and_x_y)
110+
%r = icmp eq i8 %and_x_y, %and_x_neg_y
111+
ret i1 %r
112+
}
113+
114+
define i1 @test_ne_cp2_other_fail(i8 %x, i8 %yy) {
115+
; CHECK-LABEL: @test_ne_cp2_other_fail(
116+
; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -17
117+
; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 16
118+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]])
119+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]])
120+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]]
121+
; CHECK-NEXT: ret i1 [[R]]
122+
;
123+
%and_x_neg_y = and i8 %x, -17
124+
%and_x_y = and i8 %x, 16
125+
call void @use.i8(i8 %and_x_neg_y)
126+
call void @use.i8(i8 %and_x_y)
127+
%r = icmp ne i8 %and_x_neg_y, %and_x_y
128+
ret i1 %r
129+
}
130+
131+
define i1 @test_ne_cp2_other_fail2(i8 %x, i8 %yy) {
132+
; CHECK-LABEL: @test_ne_cp2_other_fail2(
133+
; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -16
134+
; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 17
135+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]])
136+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]])
137+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]]
138+
; CHECK-NEXT: ret i1 [[R]]
139+
;
140+
%and_x_neg_y = and i8 %x, -16
141+
%and_x_y = and i8 %x, 17
142+
call void @use.i8(i8 %and_x_neg_y)
143+
call void @use.i8(i8 %and_x_y)
144+
%r = icmp ne i8 %and_x_neg_y, %and_x_y
145+
ret i1 %r
146+
}
147+
148+
define i1 @test_ne_cp2_other_okay(i8 %x, i8 %yy) {
149+
; CHECK-LABEL: @test_ne_cp2_other_okay(
150+
; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -17
151+
; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 16
152+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]])
153+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]]
154+
; CHECK-NEXT: ret i1 [[R]]
155+
;
156+
%and_x_neg_y = and i8 %x, -17
157+
%and_x_y = and i8 %x, 16
158+
call void @use.i8(i8 %and_x_y)
159+
%r = icmp ne i8 %and_x_neg_y, %and_x_y
160+
ret i1 %r
161+
}
162+
163+
define i1 @test_ne_cp2_other_okay2(i8 %x, i8 %yy) {
164+
; CHECK-LABEL: @test_ne_cp2_other_okay2(
165+
; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -17
166+
; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 16
167+
; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]])
168+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_Y]], [[AND_X_NEG_Y]]
169+
; CHECK-NEXT: ret i1 [[R]]
170+
;
171+
%and_x_neg_y = and i8 %x, -17
172+
%and_x_y = and i8 %x, 16
173+
call void @use.i8(i8 %and_x_y)
174+
%r = icmp ne i8 %and_x_y, %and_x_neg_y
175+
ret i1 %r
176+
}

0 commit comments

Comments
 (0)