1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -reassociate -S | FileCheck %s
3
4define i32 @test1(i32 %a, i32 %b) {
5; CHECK-LABEL: @test1(
6; CHECK-NEXT:    [[T2:%.*]] = mul i32 [[A:%.*]], [[A]]
7; CHECK-NEXT:    [[T6:%.*]] = mul i32 [[A]], 2
8; CHECK-NEXT:    [[REASS_ADD:%.*]] = add i32 [[T6]], [[B:%.*]]
9; CHECK-NEXT:    [[REASS_MUL:%.*]] = mul i32 [[REASS_ADD]], [[B]]
10; CHECK-NEXT:    [[T11:%.*]] = add i32 [[REASS_MUL]], [[T2]]
11; CHECK-NEXT:    ret i32 [[T11]]
12;
13  %t2 = mul i32 %a, %a
14  %t5 = shl i32 %a, 1
15  %t6 = mul i32 %t5, %b
16  %t8 = mul i32 %b, %b
17  %t7 = add i32 %t6, %t2
18  %t11 = add i32 %t7, %t8
19  ret i32 %t11
20}
21
22define i32 @test2(i32 %t) {
23; CHECK-LABEL: @test2(
24; CHECK-NEXT:    [[REASS_MUL:%.*]] = mul i32 [[T:%.*]], 42
25; CHECK-NEXT:    [[D:%.*]] = add i32 [[REASS_MUL]], 15
26; CHECK-NEXT:    ret i32 [[D]]
27;
28  %a = mul i32 %t, 6
29  %b = mul i32 %t, 36
30  %c = add i32 %b, 15
31  %d = add i32 %c, %a
32  ret i32 %d
33}
34
35; (x^8)
36define i32 @test3(i32 %x) {
37; CHECK-LABEL: @test3(
38; CHECK-NEXT:    [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
39; CHECK-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[TMP1]]
40; CHECK-NEXT:    [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
41; CHECK-NEXT:    ret i32 [[TMP3]]
42;
43  %a = mul i32 %x, %x
44  %b = mul i32 %a, %x
45  %c = mul i32 %b, %x
46  %d = mul i32 %c, %x
47  %e = mul i32 %d, %x
48  %f = mul i32 %e, %x
49  %g = mul i32 %f, %x
50  ret i32 %g
51}
52
53; (x^7)
54define i32 @test4(i32 %x) {
55; CHECK-LABEL: @test4(
56; CHECK-NEXT:    [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
57; CHECK-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[X]]
58; CHECK-NEXT:    [[TMP3:%.*]] = mul i32 [[TMP2]], [[X]]
59; CHECK-NEXT:    [[F:%.*]] = mul i32 [[TMP3]], [[TMP2]]
60; CHECK-NEXT:    ret i32 [[F]]
61;
62  %a = mul i32 %x, %x
63  %b = mul i32 %a, %x
64  %c = mul i32 %b, %x
65  %d = mul i32 %c, %x
66  %e = mul i32 %d, %x
67  %f = mul i32 %e, %x
68  ret i32 %f
69}
70
71; (x^4) * (y^2)
72define i32 @test5(i32 %x, i32 %y) {
73; CHECK-LABEL: @test5(
74; CHECK-NEXT:    [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
75; CHECK-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[Y:%.*]]
76; CHECK-NEXT:    [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP2]]
77; CHECK-NEXT:    ret i32 [[TMP3]]
78;
79  %a = mul i32 %x, %y
80  %b = mul i32 %a, %y
81  %c = mul i32 %b, %x
82  %d = mul i32 %c, %x
83  %e = mul i32 %d, %x
84  ret i32 %e
85}
86
87; (x^5) * (y^3) * z
88define i32 @test6(i32 %x, i32 %y, i32 %z) {
89; CHECK-LABEL: @test6(
90; CHECK-NEXT:    [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
91; CHECK-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[Y:%.*]]
92; CHECK-NEXT:    [[F:%.*]] = mul i32 [[Y]], [[X]]
93; CHECK-NEXT:    [[G:%.*]] = mul i32 [[F]], [[TMP2]]
94; CHECK-NEXT:    [[TMP3:%.*]] = mul i32 [[G]], [[TMP2]]
95; CHECK-NEXT:    [[H:%.*]] = mul i32 [[TMP3]], [[Z:%.*]]
96; CHECK-NEXT:    ret i32 [[H]]
97;
98  %a = mul i32 %x, %y
99  %b = mul i32 %a, %x
100  %c = mul i32 %b, %y
101  %d = mul i32 %c, %x
102  %e = mul i32 %d, %y
103  %f = mul i32 %e, %x
104  %g = mul i32 %f, %z
105  %h = mul i32 %g, %x
106  ret i32 %h
107}
108
109; (x^4) * (y^3) * (z^2)
110define i32 @test7(i32 %x, i32 %y, i32 %z) {
111; CHECK-LABEL: @test7(
112; CHECK-NEXT:    [[TMP1:%.*]] = mul i32 [[X:%.*]], [[X]]
113; CHECK-NEXT:    [[TMP2:%.*]] = mul i32 [[TMP1]], [[Y:%.*]]
114; CHECK-NEXT:    [[TMP3:%.*]] = mul i32 [[TMP2]], [[Z:%.*]]
115; CHECK-NEXT:    [[TMP4:%.*]] = mul i32 [[TMP3]], [[Y]]
116; CHECK-NEXT:    [[H:%.*]] = mul i32 [[TMP4]], [[TMP3]]
117; CHECK-NEXT:    ret i32 [[H]]
118;
119  %a = mul i32 %y, %x
120  %b = mul i32 %a, %z
121  %c = mul i32 %b, %z
122  %d = mul i32 %c, %x
123  %e = mul i32 %d, %y
124  %f = mul i32 %e, %y
125  %g = mul i32 %f, %x
126  %h = mul i32 %g, %x
127  ret i32 %h
128}
129
130