1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; https://bugs.llvm.org/show_bug.cgi?id=38123
8 ; Should be transformed into:
10 ; Iff: isPowerOf2(C + 1)
12 ; ============================================================================ ;
13 ; Basic positive tests
14 ; ============================================================================ ;
16 define i1 @p0(i8 %x) {
18 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X:%.*]], 3
19 ; CHECK-NEXT: ret i1 [[TMP1]]
22 %ret = icmp ne i8 %tmp0, %x
26 define i1 @pv(i8 %x, i8 %y) {
28 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
29 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X:%.*]]
30 ; CHECK-NEXT: ret i1 [[TMP1]]
32 %tmp0 = lshr i8 -1, %y
33 %tmp1 = and i8 %tmp0, %x
34 %ret = icmp ne i8 %tmp1, %x
38 ; ============================================================================ ;
40 ; ============================================================================ ;
42 define <2 x i1> @p1_vec_splat(<2 x i8> %x) {
43 ; CHECK-LABEL: @p1_vec_splat(
44 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 3>
45 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
47 %tmp0 = and <2 x i8> %x, <i8 3, i8 3>
48 %ret = icmp ne <2 x i8> %tmp0, %x
52 define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
53 ; CHECK-LABEL: @p2_vec_nonsplat(
54 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 15>
55 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
57 %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.
58 %ret = icmp ne <2 x i8> %tmp0, %x
62 define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
63 ; CHECK-LABEL: @p3_vec_splat_undef(
64 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>
65 ; CHECK-NEXT: ret <3 x i1> [[TMP1]]
67 %tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
68 %ret = icmp ne <3 x i8> %tmp0, %x
72 ; ============================================================================ ;
73 ; Commutativity tests.
74 ; ============================================================================ ;
80 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
81 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
82 ; CHECK-NEXT: ret i1 [[TMP1]]
86 %ret = icmp ne i8 %x, %tmp0 ; swapped order
90 ; ============================================================================ ;
91 ; Commutativity tests with variable
92 ; ============================================================================ ;
94 define i1 @cv0(i8 %y) {
96 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
97 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
98 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
99 ; CHECK-NEXT: ret i1 [[TMP1]]
102 %tmp0 = lshr i8 -1, %y
103 %tmp1 = and i8 %x, %tmp0 ; swapped order
104 %ret = icmp ne i8 %tmp1, %x
108 define i1 @cv1(i8 %y) {
110 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
111 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
112 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
113 ; CHECK-NEXT: ret i1 [[TMP1]]
116 %tmp0 = lshr i8 -1, %y
117 %tmp1 = and i8 %tmp0, %x
118 %ret = icmp ne i8 %x, %tmp1 ; swapped order
122 define i1 @cv2(i8 %y) {
124 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
125 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
126 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
127 ; CHECK-NEXT: ret i1 [[TMP1]]
130 %tmp0 = lshr i8 -1, %y
131 %tmp1 = and i8 %x, %tmp0 ; swapped order
132 %ret = icmp ne i8 %x, %tmp1 ; swapped order
136 ; ============================================================================ ;
137 ; One-use tests. We don't care about multi-uses here.
138 ; ============================================================================ ;
140 declare void @use8(i8)
142 define i1 @oneuse0(i8 %x) {
143 ; CHECK-LABEL: @oneuse0(
144 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
145 ; CHECK-NEXT: call void @use8(i8 [[TMP0]])
146 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
147 ; CHECK-NEXT: ret i1 [[TMP1]]
150 call void @use8(i8 %tmp0)
151 %ret = icmp ne i8 %tmp0, %x
155 ; ============================================================================ ;
157 ; ============================================================================ ;
159 define i1 @n0(i8 %x) {
161 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 4
162 ; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP0]], [[X]]
163 ; CHECK-NEXT: ret i1 [[RET]]
165 %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
166 %ret = icmp ne i8 %tmp0, %x
170 define i1 @n1(i8 %x, i8 %y, i8 %notx) {
172 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
173 ; CHECK-NEXT: [[RET:%.*]] = icmp ne i8 [[TMP0]], [[NOTX:%.*]]
174 ; CHECK-NEXT: ret i1 [[RET]]
177 %ret = icmp ne i8 %tmp0, %notx ; not %x
181 define <2 x i1> @n2(<2 x i8> %x) {
183 ; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 16>
184 ; CHECK-NEXT: [[RET:%.*]] = icmp ne <2 x i8> [[TMP0]], [[X]]
185 ; CHECK-NEXT: ret <2 x i1> [[RET]]
187 %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
188 %ret = icmp ne <2 x i8> %tmp0, %x