1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=reassociate -S | FileCheck %s
4 define i32 @test1(i32 %a, i32 %b) {
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]]
17 %t7 = add i32 %t6, %t2
18 %t11 = add i32 %t7, %t8
22 define 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]]
36 define 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]]
54 define 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]]
72 define 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]]
88 define 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]]
109 ; (x^4) * (y^3) * (z^2)
110 define 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]]