reassociate-nuw.ll
5.18 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S %s | FileCheck %s
define i32 @reassoc_add_nuw(i32 %x) {
; CHECK-LABEL: @reassoc_add_nuw(
; CHECK-NEXT: [[ADD1:%.*]] = add nuw i32 [[X:%.*]], 68
; CHECK-NEXT: ret i32 [[ADD1]]
;
%add0 = add nuw i32 %x, 4
%add1 = add nuw i32 %add0, 64
ret i32 %add1
}
; This does the wrong thing because the sub is turned into an add of a
; negative constant first which drops the nuw.
define i32 @reassoc_sub_nuw(i32 %x) {
; CHECK-LABEL: @reassoc_sub_nuw(
; CHECK-NEXT: [[SUB1:%.*]] = add i32 [[X:%.*]], -68
; CHECK-NEXT: ret i32 [[SUB1]]
;
%sub0 = sub nuw i32 %x, 4
%sub1 = sub nuw i32 %sub0, 64
ret i32 %sub1
}
define i32 @reassoc_mul_nuw(i32 %x) {
; CHECK-LABEL: @reassoc_mul_nuw(
; CHECK-NEXT: [[MUL1:%.*]] = mul nuw i32 [[X:%.*]], 260
; CHECK-NEXT: ret i32 [[MUL1]]
;
%mul0 = mul nuw i32 %x, 4
%mul1 = mul nuw i32 %mul0, 65
ret i32 %mul1
}
define i32 @no_reassoc_add_nuw_none(i32 %x) {
; CHECK-LABEL: @no_reassoc_add_nuw_none(
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[X:%.*]], 68
; CHECK-NEXT: ret i32 [[ADD1]]
;
%add0 = add i32 %x, 4
%add1 = add nuw i32 %add0, 64
ret i32 %add1
}
define i32 @no_reassoc_add_none_nuw(i32 %x) {
; CHECK-LABEL: @no_reassoc_add_none_nuw(
; CHECK-NEXT: [[ADD1:%.*]] = add i32 [[X:%.*]], 68
; CHECK-NEXT: ret i32 [[ADD1]]
;
%add0 = add nuw i32 %x, 4
%add1 = add i32 %add0, 64
ret i32 %add1
}
define i32 @reassoc_x2_add_nuw(i32 %x, i32 %y) {
; CHECK-LABEL: @reassoc_x2_add_nuw(
; CHECK-NEXT: [[ADD1:%.*]] = add nuw i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[ADD2:%.*]] = add nuw i32 [[ADD1]], 12
; CHECK-NEXT: ret i32 [[ADD2]]
;
%add0 = add nuw i32 %x, 4
%add1 = add nuw i32 %y, 8
%add2 = add nuw i32 %add0, %add1
ret i32 %add2
}
define i32 @reassoc_x2_mul_nuw(i32 %x, i32 %y) {
; CHECK-LABEL: @reassoc_x2_mul_nuw(
; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[MUL2:%.*]] = mul nuw i32 [[MUL1]], 45
; CHECK-NEXT: ret i32 [[MUL2]]
;
%mul0 = mul nuw i32 %x, 5
%mul1 = mul nuw i32 %y, 9
%mul2 = mul nuw i32 %mul0, %mul1
ret i32 %mul2
}
define i32 @reassoc_x2_sub_nuw(i32 %x, i32 %y) {
; CHECK-LABEL: @reassoc_x2_sub_nuw(
; CHECK-NEXT: [[SUB0:%.*]] = add i32 [[X:%.*]], -4
; CHECK-NEXT: [[SUB1:%.*]] = add i32 [[Y:%.*]], -8
; CHECK-NEXT: [[SUB2:%.*]] = sub nuw i32 [[SUB0]], [[SUB1]]
; CHECK-NEXT: ret i32 [[SUB2]]
;
%sub0 = sub nuw i32 %x, 4
%sub1 = sub nuw i32 %y, 8
%sub2 = sub nuw i32 %sub0, %sub1
ret i32 %sub2
}
define i32 @tryFactorization_add_nuw_mul_nuw(i32 %x) {
; CHECK-LABEL: @tryFactorization_add_nuw_mul_nuw(
; CHECK-NEXT: [[ADD2:%.*]] = shl nuw i32 [[X:%.*]], 2
; CHECK-NEXT: ret i32 [[ADD2]]
;
%mul1 = mul nuw i32 %x, 3
%add2 = add nuw i32 %mul1, %x
ret i32 %add2
}
define i32 @tryFactorization_add_nuw_mul_nuw_int_max(i32 %x) {
; CHECK-LABEL: @tryFactorization_add_nuw_mul_nuw_int_max(
; CHECK-NEXT: [[ADD2:%.*]] = shl nuw i32 [[X:%.*]], 31
; CHECK-NEXT: ret i32 [[ADD2]]
;
%mul1 = mul nuw i32 %x, 2147483647
%add2 = add nuw i32 %mul1, %x
ret i32 %add2
}
define i32 @tryFactorization_add_mul_nuw(i32 %x) {
; CHECK-LABEL: @tryFactorization_add_mul_nuw(
; CHECK-NEXT: [[ADD2:%.*]] = shl i32 [[X:%.*]], 2
; CHECK-NEXT: ret i32 [[ADD2]]
;
%mul1 = mul i32 %x, 3
%add2 = add nuw i32 %mul1, %x
ret i32 %add2
}
define i32 @tryFactorization_add_nuw_mul(i32 %x) {
; CHECK-LABEL: @tryFactorization_add_nuw_mul(
; CHECK-NEXT: [[ADD2:%.*]] = shl i32 [[X:%.*]], 2
; CHECK-NEXT: ret i32 [[ADD2]]
;
%mul1 = mul nuw i32 %x, 3
%add2 = add i32 %mul1, %x
ret i32 %add2
}
define i32 @tryFactorization_add_nuw_mul_nuw_mul_nuw_var(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @tryFactorization_add_nuw_mul_nuw_mul_nuw_var(
; CHECK-NEXT: [[MUL21:%.*]] = add i32 [[Y:%.*]], [[Z:%.*]]
; CHECK-NEXT: [[ADD1:%.*]] = mul nuw i32 [[MUL21]], [[X:%.*]]
; CHECK-NEXT: ret i32 [[ADD1]]
;
%mul1 = mul nuw i32 %x, %y
%mul2 = mul nuw i32 %x, %z
%add1 = add nuw i32 %mul1, %mul2
ret i32 %add1
}
define i32 @tryFactorization_add_nuw_mul_mul_nuw_var(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @tryFactorization_add_nuw_mul_mul_nuw_var(
; CHECK-NEXT: [[MUL21:%.*]] = add i32 [[Y:%.*]], [[Z:%.*]]
; CHECK-NEXT: [[ADD1:%.*]] = mul i32 [[MUL21]], [[X:%.*]]
; CHECK-NEXT: ret i32 [[ADD1]]
;
%mul1 = mul i32 %x, %y
%mul2 = mul nuw i32 %x, %z
%add1 = add nuw i32 %mul1, %mul2
ret i32 %add1
}
define i32 @tryFactorization_add_nuw_mul_nuw_mul_var(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @tryFactorization_add_nuw_mul_nuw_mul_var(
; CHECK-NEXT: [[MUL21:%.*]] = add i32 [[Y:%.*]], [[Z:%.*]]
; CHECK-NEXT: [[ADD1:%.*]] = mul i32 [[MUL21]], [[X:%.*]]
; CHECK-NEXT: ret i32 [[ADD1]]
;
%mul1 = mul nuw i32 %x, %y
%mul2 = mul i32 %x, %z
%add1 = add nuw i32 %mul1, %mul2
ret i32 %add1
}
define i32 @tryFactorization_add_mul_nuw_mul_var(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @tryFactorization_add_mul_nuw_mul_var(
; CHECK-NEXT: [[MUL21:%.*]] = add i32 [[Y:%.*]], [[Z:%.*]]
; CHECK-NEXT: [[ADD1:%.*]] = mul i32 [[MUL21]], [[X:%.*]]
; CHECK-NEXT: ret i32 [[ADD1]]
;
%mul1 = mul nuw i32 %x, %y
%mul2 = mul nuw i32 %x, %z
%add1 = add i32 %mul1, %mul2
ret i32 %add1
}