Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by update_test_checks.py |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
Nick Lewycky | 8561a49 | 2014-06-19 03:51:46 +0000 | [diff] [blame] | 3 | |
| 4 | ; Test the case where integer BitWidth <= 64 && BitWidth % 2 != 0. |
| 5 | define i39 @test1(i39 %V, i39 %M) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 6 | ; CHECK-LABEL: @test1( |
| 7 | ; CHECK: [[N:%.*]] = and i39 %M, -274877906944 |
| 8 | ; CHECK-NEXT: [[A:%.*]] = add i39 %V, [[N]] |
| 9 | ; CHECK-NEXT: ret i39 [[A]] |
| 10 | ; |
Nick Lewycky | 8561a49 | 2014-06-19 03:51:46 +0000 | [diff] [blame] | 11 | ;; If we have: ((V + N) & C1) | (V & C2) |
| 12 | ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 |
| 13 | ;; replace with V+N. |
| 14 | %C1 = xor i39 274877906943, -1 ;; C2 = 274877906943 |
| 15 | %N = and i39 %M, 274877906944 |
| 16 | %A = add i39 %V, %N |
| 17 | %B = and i39 %A, %C1 |
| 18 | %D = and i39 %V, 274877906943 |
| 19 | %R = or i39 %B, %D |
| 20 | ret i39 %R |
Nick Lewycky | 8561a49 | 2014-06-19 03:51:46 +0000 | [diff] [blame] | 21 | } |
| 22 | |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 23 | define i7 @test2(i7 %X) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 24 | ; CHECK-LABEL: @test2( |
| 25 | ; CHECK: ret i7 %X |
| 26 | ; |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 27 | %Y = or i7 %X, 0 |
| 28 | ret i7 %Y |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | define i17 @test3(i17 %X) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 32 | ; CHECK-LABEL: @test3( |
| 33 | ; CHECK: ret i17 -1 |
| 34 | ; |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 35 | %Y = or i17 %X, -1 |
| 36 | ret i17 %Y |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 39 | ; Test the case where Integer BitWidth > 64 && BitWidth <= 1024. |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 40 | define i399 @test4(i399 %V, i399 %M) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 41 | ; CHECK-LABEL: @test4( |
| 42 | ; CHECK: [[N:%.*]] = and i399 %M, 18446742974197923840 |
| 43 | ; CHECK-NEXT: [[A:%.*]] = add i399 %V, [[N]] |
| 44 | ; CHECK-NEXT: ret i399 [[A]] |
| 45 | ; |
Nick Lewycky | 8561a49 | 2014-06-19 03:51:46 +0000 | [diff] [blame] | 46 | ;; If we have: ((V + N) & C1) | (V & C2) |
| 47 | ;; .. and C2 = ~C1 and C2 is 0+1+ and (N & C2) == 0 |
| 48 | ;; replace with V+N. |
| 49 | %C1 = xor i399 274877906943, -1 ;; C2 = 274877906943 |
| 50 | %N = and i399 %M, 18446742974197923840 |
| 51 | %A = add i399 %V, %N |
| 52 | %B = and i399 %A, %C1 |
| 53 | %D = and i399 %V, 274877906943 |
| 54 | %R = or i399 %B, %D |
| 55 | ret i399 %R |
Nick Lewycky | 8561a49 | 2014-06-19 03:51:46 +0000 | [diff] [blame] | 56 | } |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 57 | |
| 58 | define i777 @test5(i777 %X) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 59 | ; CHECK-LABEL: @test5( |
| 60 | ; CHECK: ret i777 %X |
| 61 | ; |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 62 | %Y = or i777 %X, 0 |
| 63 | ret i777 %Y |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | define i117 @test6(i117 %X) { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 67 | ; CHECK-LABEL: @test6( |
| 68 | ; CHECK: ret i117 -1 |
| 69 | ; |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 70 | %Y = or i117 %X, -1 |
| 71 | ret i117 %Y |
Benjamin Kramer | c3c1835 | 2015-09-08 18:36:56 +0000 | [diff] [blame] | 72 | } |