Chandler Carruth | 8ffa7c8 | 2012-04-22 10:11:26 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -reassociate -S | FileCheck %s |
Chris Lattner | f97c7f5 | 2006-03-04 09:35:02 +0000 | [diff] [blame] | 2 | |
Chandler Carruth | 8ffa7c8 | 2012-04-22 10:11:26 +0000 | [diff] [blame] | 3 | define i32 @test1(i32 %a, i32 %b) { |
| 4 | ; CHECK: @test1 |
| 5 | ; CHECK: mul i32 %a, %a |
| 6 | ; CHECK-NEXT: mul i32 %a, 2 |
| 7 | ; CHECK-NEXT: add |
| 8 | ; CHECK-NEXT: mul |
| 9 | ; CHECK-NEXT: add |
| 10 | ; CHECK-NEXT: ret |
Chandler Carruth | f6f5753 | 2012-04-22 10:11:23 +0000 | [diff] [blame] | 11 | |
| 12 | entry: |
| 13 | %tmp.2 = mul i32 %a, %a |
| 14 | %tmp.5 = shl i32 %a, 1 |
| 15 | %tmp.6 = mul i32 %tmp.5, %b |
| 16 | %tmp.10 = mul i32 %b, %b |
| 17 | %tmp.7 = add i32 %tmp.6, %tmp.2 |
| 18 | %tmp.11 = add i32 %tmp.7, %tmp.10 |
Tanya Lattner | 0ea4c8d | 2008-03-19 04:36:04 +0000 | [diff] [blame] | 19 | ret i32 %tmp.11 |
Chris Lattner | f97c7f5 | 2006-03-04 09:35:02 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Chandler Carruth | 8ffa7c8 | 2012-04-22 10:11:26 +0000 | [diff] [blame] | 22 | define i32 @test2(i32 %t) { |
| 23 | ; CHECK: @test2 |
| 24 | ; CHECK: mul |
| 25 | ; CHECK-NEXT: add |
| 26 | ; CHECK-NEXT: ret |
| 27 | |
| 28 | entry: |
| 29 | %a = mul i32 %t, 6 |
| 30 | %b = mul i32 %t, 36 |
| 31 | %c = add i32 %b, 15 |
| 32 | %d = add i32 %c, %a |
| 33 | ret i32 %d |
| 34 | } |
| 35 | |
Chandler Carruth | 739ef80 | 2012-04-26 05:30:30 +0000 | [diff] [blame^] | 36 | define i32 @test3(i32 %x) { |
| 37 | ; (x^8) |
| 38 | ; CHECK: @test3 |
| 39 | ; CHECK: mul |
| 40 | ; CHECK-NEXT: mul |
| 41 | ; CHECK-NEXT: mul |
| 42 | ; CHECK-NEXT: ret |
| 43 | |
| 44 | entry: |
| 45 | %a = mul i32 %x, %x |
| 46 | %b = mul i32 %a, %x |
| 47 | %c = mul i32 %b, %x |
| 48 | %d = mul i32 %c, %x |
| 49 | %e = mul i32 %d, %x |
| 50 | %f = mul i32 %e, %x |
| 51 | %g = mul i32 %f, %x |
| 52 | ret i32 %g |
| 53 | } |
| 54 | |
| 55 | define i32 @test4(i32 %x) { |
| 56 | ; (x^7) |
| 57 | ; CHECK: @test4 |
| 58 | ; CHECK: mul |
| 59 | ; CHECK-NEXT: mul |
| 60 | ; CHECK-NEXT: mul |
| 61 | ; CHECK-NEXT: mul |
| 62 | ; CHECK-NEXT: ret |
| 63 | |
| 64 | entry: |
| 65 | %a = mul i32 %x, %x |
| 66 | %b = mul i32 %a, %x |
| 67 | %c = mul i32 %b, %x |
| 68 | %d = mul i32 %c, %x |
| 69 | %e = mul i32 %d, %x |
| 70 | %f = mul i32 %e, %x |
| 71 | ret i32 %f |
| 72 | } |
| 73 | |
| 74 | define i32 @test5(i32 %x, i32 %y) { |
| 75 | ; (x^4) * (y^2) |
| 76 | ; CHECK: @test5 |
| 77 | ; CHECK: mul |
| 78 | ; CHECK-NEXT: mul |
| 79 | ; CHECK-NEXT: mul |
| 80 | ; CHECK-NEXT: ret |
| 81 | |
| 82 | entry: |
| 83 | %a = mul i32 %x, %y |
| 84 | %b = mul i32 %a, %y |
| 85 | %c = mul i32 %b, %x |
| 86 | %d = mul i32 %c, %x |
| 87 | %e = mul i32 %d, %x |
| 88 | ret i32 %e |
| 89 | } |
| 90 | |
| 91 | define i32 @test6(i32 %x, i32 %y, i32 %z) { |
| 92 | ; (x^5) * (y^3) * z |
| 93 | ; CHECK: @test6 |
| 94 | ; CHECK: mul |
| 95 | ; CHECK-NEXT: mul |
| 96 | ; CHECK-NEXT: mul |
| 97 | ; CHECK-NEXT: mul |
| 98 | ; CHECK-NEXT: mul |
| 99 | ; CHECK-NEXT: mul |
| 100 | ; CHECK-NEXT: ret |
| 101 | |
| 102 | entry: |
| 103 | %a = mul i32 %x, %y |
| 104 | %b = mul i32 %a, %x |
| 105 | %c = mul i32 %b, %y |
| 106 | %d = mul i32 %c, %x |
| 107 | %e = mul i32 %d, %y |
| 108 | %f = mul i32 %e, %x |
| 109 | %g = mul i32 %f, %z |
| 110 | %h = mul i32 %g, %x |
| 111 | ret i32 %h |
| 112 | } |
| 113 | |
| 114 | define i32 @test7(i32 %x, i32 %y, i32 %z) { |
| 115 | ; (x^4) * (y^3) * (z^2) |
| 116 | ; CHECK: @test7 |
| 117 | ; CHECK: mul |
| 118 | ; CHECK-NEXT: mul |
| 119 | ; CHECK-NEXT: mul |
| 120 | ; CHECK-NEXT: mul |
| 121 | ; CHECK-NEXT: mul |
| 122 | ; CHECK-NEXT: ret |
| 123 | |
| 124 | entry: |
| 125 | %a = mul i32 %y, %x |
| 126 | %b = mul i32 %a, %z |
| 127 | %c = mul i32 %b, %z |
| 128 | %d = mul i32 %c, %x |
| 129 | %e = mul i32 %d, %y |
| 130 | %f = mul i32 %e, %y |
| 131 | %g = mul i32 %f, %x |
| 132 | %h = mul i32 %g, %x |
| 133 | ret i32 %h |
| 134 | } |