1 ; RUN: opt < %s -reassociate -S | FileCheck %s
3 define i32 @test1(i32 %a, i32 %b) {
5 ; CHECK-NEXT: [[T2:%.*]] = mul i32 %a, %a
6 ; CHECK-NEXT: [[T6:%.*]] = mul i32 %a, 2
7 ; CHECK-NEXT: [[REASS_ADD:%.*]] = add i32 [[T6]], %b
8 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], %b
9 ; CHECK-NEXT: [[T11:%.*]] = add i32 [[REASS_MUL]], [[T2]]
10 ; CHECK-NEXT: ret i32 [[T11]]
16 %t7 = add i32 %t6, %t2
17 %t11 = add i32 %t7, %t8
21 define i32 @test2(i32 %t) {
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: [[REASS_MUL:%.*]] = mul i32 %t, 42
24 ; CHECK-NEXT: [[D:%.*]] = add i32 [[REASS_MUL]], 15
25 ; CHECK-NEXT: ret i32 [[D]]
35 define i32 @test3(i32 %x) {
36 ; CHECK-LABEL: @test3(
37 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
38 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
39 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
40 ; CHECK-NEXT: ret i32 [[TMP3]]
53 define i32 @test4(i32 %x) {
54 ; CHECK-LABEL: @test4(
55 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
56 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %x
57 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], %x
58 ; CHECK-NEXT: [[F:%.*]] = mul i32 [[TMP3]], [[TMP2]]
59 ; CHECK-NEXT: ret i32 [[F]]
71 define i32 @test5(i32 %x, i32 %y) {
72 ; CHECK-LABEL: @test5(
73 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
74 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
75 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
76 ; CHECK-NEXT: ret i32 [[TMP3]]
87 define i32 @test6(i32 %x, i32 %y, i32 %z) {
88 ; CHECK-LABEL: @test6(
89 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
90 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
91 ; CHECK-NEXT: [[F:%.*]] = mul i32 %y, %x
92 ; CHECK-NEXT: [[G:%.*]] = mul i32 [[F]], [[TMP2]]
93 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[G]], [[TMP2]]
94 ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP3]], %z
95 ; CHECK-NEXT: ret i32 [[H]]
108 ; (x^4) * (y^3) * (z^2)
109 define i32 @test7(i32 %x, i32 %y, i32 %z) {
110 ; CHECK-LABEL: @test7(
111 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 %x, %x
112 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], %y
113 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], %z
114 ; CHECK-NEXT: [[TMP4:%.*]] = mul i32 [[TMP3]], %y
115 ; CHECK-NEXT: [[H:%.*]] = mul i32 [[TMP4]], [[TMP3]]
116 ; CHECK-NEXT: ret i32 [[H]]