1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instsimplify -S | FileCheck %s
4 define i32 @test1(i32 %A) {
6 ; CHECK-NEXT: ret i32 %A
12 define i32 @all_ones(i32 %A) {
13 ; CHECK-LABEL: @all_ones(
14 ; CHECK-NEXT: ret i32 -1
20 define <3 x i8> @all_ones_vec_with_undef_elt(<3 x i8> %A) {
21 ; CHECK-LABEL: @all_ones_vec_with_undef_elt(
22 ; CHECK-NEXT: ret <3 x i8> <i8 -1, i8 -1, i8 -1>
24 %B = or <3 x i8> %A, <i8 -1, i8 undef, i8 -1>
28 define i1 @test3(i1 %A) {
29 ; CHECK-LABEL: @test3(
30 ; CHECK-NEXT: ret i1 %A
36 define i1 @test4(i1 %A) {
37 ; CHECK-LABEL: @test4(
38 ; CHECK-NEXT: ret i1 true
44 define i1 @test5(i1 %A) {
45 ; CHECK-LABEL: @test5(
46 ; CHECK-NEXT: ret i1 %A
52 define i32 @test6(i32 %A) {
53 ; CHECK-LABEL: @test6(
54 ; CHECK-NEXT: ret i32 %A
61 define i32 @test7(i32 %A) {
62 ; CHECK-LABEL: @test7(
63 ; CHECK-NEXT: ret i32 -1
65 %NotA = xor i32 %A, -1
70 define i8 @test8(i8 %A) {
71 ; CHECK-LABEL: @test8(
72 ; CHECK-NEXT: ret i8 -1
79 ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2)
80 define i8 @test9(i8 %A, i8 %B) {
81 ; CHECK-LABEL: @test9(
82 ; CHECK-NEXT: ret i8 -1
90 define i8 @test10(i8 %A) {
91 ; CHECK-LABEL: @test10(
92 ; CHECK-NEXT: ret i8 -2
96 ; (X & C1) | C2 --> (X | C2) & (C1|C2)
101 define i8 @test11(i8 %A) {
102 ; CHECK-LABEL: @test11(
103 ; CHECK-NEXT: ret i8 -1
107 ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
113 ; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
114 define i39 @test1_apint(i39 %V, i39 %M) {
115 ; CHECK-LABEL: @test1_apint(
116 ; CHECK: [[N:%.*]] = and i39 %M, -274877906944
117 ; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]]
118 ; CHECK-NEXT: ret i39 [[A]]
120 ;; If we have: ((V + N) & C1) | (V & C2)
121 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
123 %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943
124 %N = and i39 %M, 274877906944
127 %D = and i39 %V, 274877906943
132 define i7 @test2_apint(i7 %X) {
133 ; CHECK-LABEL: @test2_apint(
140 define i17 @test3_apint(i17 %X) {
141 ; CHECK-LABEL: @test3_apint(
148 ; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
149 define i399 @test4_apint(i399 %V, i399 %M) {
150 ; CHECK-LABEL: @test4_apint(
151 ; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840
152 ; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]]
153 ; CHECK-NEXT: ret i399 [[A]]
155 ;; If we have: ((V + N) & C1) | (V & C2)
156 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
158 %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943
159 %N = and i399 %M, 18446742974197923840
161 %B = and i399 %A, %C1
162 %D = and i399 %V, 274877906943
167 define i777 @test5_apint(i777 %X) {
168 ; CHECK-LABEL: @test5_apint(
175 define i117 @test6_apint(i117 %X) {
176 ; CHECK-LABEL: @test6_apint(
183 ; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0.
184 ; Vector version of test1_apint with the add commuted
185 define <2 x i39> @test7_apint(<2 x i39> %V, <2 x i39> %M) {
186 ; CHECK-LABEL: @test7_apint(
187 ; CHECK-NEXT: [[N:%.*]] = and <2 x i39> [[M:%.*]], <i39 -274877906944, i39 -274877906944>
188 ; CHECK-NEXT: [[A:%.*]] = add <2 x i39> [[N]], [[V:%.*]]
189 ; CHECK-NEXT: ret <2 x i39> [[A]]
191 ;; If we have: ((V + N) & C1) | (V & C2)
192 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
194 %C1 = xor <2 x i39> <i39 274877906943, i39 274877906943>, <i39 -1, i39 -1> ;; C2 = 274877906943
195 %N = and <2 x i39> %M, <i39 274877906944, i39 274877906944>
196 %A = add <2 x i39> %N, %V
197 %B = and <2 x i39> %A, %C1
198 %D = and <2 x i39> %V, <i39 274877906943, i39 274877906943>
199 %R = or <2 x i39> %B, %D
203 ; Test the case where Integer BitWidth > 64 && BitWidth <= 1024.
204 ; Vector version of test4_apint with the add and the or commuted
205 define <2 x i399> @test8_apint(<2 x i399> %V, <2 x i399> %M) {
206 ; CHECK-LABEL: @test8_apint(
207 ; CHECK-NEXT: [[N:%.*]] = and <2 x i399> [[M:%.*]], <i399 18446742974197923840, i399 18446742974197923840>
208 ; CHECK-NEXT: [[A:%.*]] = add <2 x i399> [[N]], [[V:%.*]]
209 ; CHECK-NEXT: ret <2 x i399> [[A]]
211 ;; If we have: ((V + N) & C1) | (V & C2)
212 ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0
214 %C1 = xor <2 x i399> <i399 274877906943, i399 274877906943>, <i399 -1, i399 -1> ;; C2 = 274877906943
215 %N = and <2 x i399> %M, <i399 18446742974197923840, i399 18446742974197923840>
216 %A = add <2 x i399> %N, %V
217 %B = and <2 x i399> %A, %C1
218 %D = and <2 x i399> %V, <i399 274877906943, i399 274877906943>
219 %R = or <2 x i399> %D, %B