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