Sanjay Patel | 0b24b7e | 2017-05-10 15:57:47 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | |
| 3 | define i32 @test1(i32 %A) { |
| 4 | ; CHECK-LABEL: @test1( |
| 5 | ; CHECK-NEXT: ret i32 %A |
| 6 | ; |
| 7 | %B = or i32 %A, 0 |
| 8 | ret i32 %B |
| 9 | } |
| 10 | |
| 11 | define i32 @test2(i32 %A) { |
| 12 | ; CHECK-LABEL: @test2( |
| 13 | ; CHECK-NEXT: ret i32 -1 |
| 14 | ; |
| 15 | %B = or i32 %A, -1 |
| 16 | ret i32 %B |
| 17 | } |
| 18 | |
| 19 | define i8 @test2a(i8 %A) { |
| 20 | ; CHECK-LABEL: @test2a( |
| 21 | ; CHECK-NEXT: ret i8 -1 |
| 22 | ; |
| 23 | %B = or i8 %A, -1 |
| 24 | ret i8 %B |
| 25 | } |
| 26 | |
| 27 | define i1 @test3(i1 %A) { |
| 28 | ; CHECK-LABEL: @test3( |
| 29 | ; CHECK-NEXT: ret i1 %A |
| 30 | ; |
| 31 | %B = or i1 %A, false |
| 32 | ret i1 %B |
| 33 | } |
| 34 | |
| 35 | define i1 @test4(i1 %A) { |
| 36 | ; CHECK-LABEL: @test4( |
| 37 | ; CHECK-NEXT: ret i1 true |
| 38 | ; |
| 39 | %B = or i1 %A, true |
| 40 | ret i1 %B |
| 41 | } |
| 42 | |
| 43 | define i1 @test5(i1 %A) { |
| 44 | ; CHECK-LABEL: @test5( |
| 45 | ; CHECK-NEXT: ret i1 %A |
| 46 | ; |
| 47 | %B = or i1 %A, %A |
| 48 | ret i1 %B |
| 49 | } |
| 50 | |
| 51 | define i32 @test6(i32 %A) { |
| 52 | ; CHECK-LABEL: @test6( |
| 53 | ; CHECK-NEXT: ret i32 %A |
| 54 | ; |
| 55 | %B = or i32 %A, %A |
| 56 | ret i32 %B |
| 57 | } |
| 58 | |
| 59 | ; A | ~A == -1 |
| 60 | define i32 @test7(i32 %A) { |
| 61 | ; CHECK-LABEL: @test7( |
| 62 | ; CHECK-NEXT: ret i32 -1 |
| 63 | ; |
| 64 | %NotA = xor i32 %A, -1 |
| 65 | %B = or i32 %A, %NotA |
| 66 | ret i32 %B |
| 67 | } |
| 68 | |
| 69 | define i8 @test8(i8 %A) { |
| 70 | ; CHECK-LABEL: @test8( |
| 71 | ; CHECK-NEXT: ret i8 -1 |
| 72 | ; |
| 73 | %B = or i8 %A, -2 |
| 74 | %C = or i8 %B, 1 |
| 75 | ret i8 %C |
| 76 | } |
| 77 | |
| 78 | ; Test that (A|c1)|(B|c2) == (A|B)|(c1|c2) |
| 79 | define i8 @test9(i8 %A, i8 %B) { |
| 80 | ; CHECK-LABEL: @test9( |
| 81 | ; CHECK-NEXT: ret i8 -1 |
| 82 | ; |
| 83 | %C = or i8 %A, 1 |
| 84 | %D = or i8 %B, -2 |
| 85 | %E = or i8 %C, %D |
| 86 | ret i8 %E |
| 87 | } |
| 88 | |
| 89 | define i8 @test10(i8 %A) { |
| 90 | ; CHECK-LABEL: @test10( |
| 91 | ; CHECK-NEXT: ret i8 -2 |
| 92 | ; |
| 93 | %B = or i8 %A, 1 |
| 94 | %C = and i8 %B, -2 |
| 95 | ; (X & C1) | C2 --> (X | C2) & (C1|C2) |
| 96 | %D = or i8 %C, -2 |
| 97 | ret i8 %D |
| 98 | } |
| 99 | |
| 100 | define i8 @test11(i8 %A) { |
| 101 | ; CHECK-LABEL: @test11( |
| 102 | ; CHECK-NEXT: ret i8 -1 |
| 103 | ; |
| 104 | %B = or i8 %A, -2 |
| 105 | %C = xor i8 %B, 13 |
| 106 | ; (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2) |
| 107 | %D = or i8 %C, 1 |
| 108 | %E = xor i8 %D, 12 |
| 109 | ret i8 %E |
| 110 | } |
| 111 | |
| 112 | ; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. |
| 113 | define i39 @test1_apint(i39 %V, i39 %M) { |
| 114 | ; CHECK-LABEL: @test1_apint( |
| 115 | ; CHECK: [[N:%.*]] = and i39 %M, -274877906944 |
| 116 | ; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]] |
| 117 | ; CHECK-NEXT: ret i39 [[A]] |
| 118 | ; |
| 119 | ;; If we have: ((V + N) & C1) | (V & C2) |
| 120 | ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 |
| 121 | ;; replace with V+N. |
| 122 | %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943 |
| 123 | %N = and i39 %M, 274877906944 |
| 124 | %A = add i39 %V, %N |
| 125 | %B = and i39 %A, %C1 |
| 126 | %D = and i39 %V, 274877906943 |
| 127 | %R = or i39 %B, %D |
| 128 | ret i39 %R |
| 129 | } |
| 130 | |
| 131 | define i7 @test2_apint(i7 %X) { |
| 132 | ; CHECK-LABEL: @test2_apint( |
| 133 | ; CHECK: ret i7 %X |
| 134 | ; |
| 135 | %Y = or i7 %X, 0 |
| 136 | ret i7 %Y |
| 137 | } |
| 138 | |
| 139 | define i17 @test3_apint(i17 %X) { |
| 140 | ; CHECK-LABEL: @test3_apint( |
| 141 | ; CHECK: ret i17 -1 |
| 142 | ; |
| 143 | %Y = or i17 %X, -1 |
| 144 | ret i17 %Y |
| 145 | } |
| 146 | |
| 147 | ; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. |
| 148 | define i399 @test4_apint(i399 %V, i399 %M) { |
| 149 | ; CHECK-LABEL: @test4_apint( |
| 150 | ; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840 |
| 151 | ; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]] |
| 152 | ; CHECK-NEXT: ret i399 [[A]] |
| 153 | ; |
| 154 | ;; If we have: ((V + N) & C1) | (V & C2) |
| 155 | ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 |
| 156 | ;; replace with V+N. |
| 157 | %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943 |
| 158 | %N = and i399 %M, 18446742974197923840 |
| 159 | %A = add i399 %V, %N |
| 160 | %B = and i399 %A, %C1 |
| 161 | %D = and i399 %V, 274877906943 |
Craig Topper | 1da22c3 | 2017-05-26 19:03:53 +0000 | [diff] [blame] | 162 | %R = or i399 %D, %B |
Sanjay Patel | 0b24b7e | 2017-05-10 15:57:47 +0000 | [diff] [blame] | 163 | ret i399 %R |
| 164 | } |
| 165 | |
| 166 | define i777 @test5_apint(i777 %X) { |
| 167 | ; CHECK-LABEL: @test5_apint( |
| 168 | ; CHECK: ret i777 %X |
| 169 | ; |
| 170 | %Y = or i777 %X, 0 |
| 171 | ret i777 %Y |
| 172 | } |
| 173 | |
| 174 | define i117 @test6_apint(i117 %X) { |
| 175 | ; CHECK-LABEL: @test6_apint( |
| 176 | ; CHECK: ret i117 -1 |
| 177 | ; |
| 178 | %Y = or i117 %X, -1 |
| 179 | ret i117 %Y |
| 180 | } |
| 181 | |
Craig Topper | 1da22c3 | 2017-05-26 19:03:53 +0000 | [diff] [blame] | 182 | ; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. |
| 183 | ; Vector version of test1_apint with the add commuted |
| 184 | define <2 x i39> @test7_apint(<2 x i39> %V, <2 x i39> %M) { |
| 185 | ; CHECK-LABEL: @test7_apint( |
| 186 | ; CHECK-NEXT: [[N:%.*]] = and <2 x i39> [[M:%.*]], <i39 -274877906944, i39 -274877906944> |
| 187 | ; CHECK-NEXT: [[A:%.*]] = add <2 x i39> [[N]], [[V:%.*]] |
| 188 | ; CHECK-NEXT: ret <2 x i39> [[A]] |
| 189 | ; |
| 190 | ;; If we have: ((V + N) & C1) | (V & C2) |
| 191 | ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 |
| 192 | ;; replace with V+N. |
| 193 | %C1 = xor <2 x i39> <i39 274877906943, i39 274877906943>, <i39 -1, i39 -1> ;; C2 = 274877906943 |
| 194 | %N = and <2 x i39> %M, <i39 274877906944, i39 274877906944> |
| 195 | %A = add <2 x i39> %N, %V |
| 196 | %B = and <2 x i39> %A, %C1 |
| 197 | %D = and <2 x i39> %V, <i39 274877906943, i39 274877906943> |
| 198 | %R = or <2 x i39> %B, %D |
| 199 | ret <2 x i39> %R |
| 200 | } |
| 201 | |
| 202 | ; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. |
| 203 | ; Vector version of test4_apint with the add and the or commuted |
| 204 | define <2 x i399> @test8_apint(<2 x i399> %V, <2 x i399> %M) { |
| 205 | ; CHECK-LABEL: @test8_apint( |
| 206 | ; CHECK-NEXT: [[N:%.*]] = and <2 x i399> [[M:%.*]], <i399 18446742974197923840, i399 18446742974197923840> |
| 207 | ; CHECK-NEXT: [[A:%.*]] = add <2 x i399> [[N]], [[V:%.*]] |
| 208 | ; CHECK-NEXT: ret <2 x i399> [[A]] |
| 209 | ; |
| 210 | ;; If we have: ((V + N) & C1) | (V & C2) |
| 211 | ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 |
| 212 | ;; replace with V+N. |
| 213 | %C1 = xor <2 x i399> <i399 274877906943, i399 274877906943>, <i399 -1, i399 -1> ;; C2 = 274877906943 |
| 214 | %N = and <2 x i399> %M, <i399 18446742974197923840, i399 18446742974197923840> |
| 215 | %A = add <2 x i399> %N, %V |
| 216 | %B = and <2 x i399> %A, %C1 |
| 217 | %D = and <2 x i399> %V, <i399 274877906943, i399 274877906943> |
| 218 | %R = or <2 x i399> %D, %B |
| 219 | ret <2 x i399> %R |
| 220 | } |