67
67
br label %loop
68
68
}
69
69
70
-
71
- ; Hoist ADD and copy NUW if both ops have it. Commutative version .
70
+ ; Hoist ADD and copy NUW if both ops have it.
71
+ ; Version where operands are commuted .
72
72
define void @add_nuw_comm (i64 %c1 , i64 %c2 ) {
73
73
; CHECK-LABEL: @add_nuw_comm(
74
74
; CHECK-NEXT: entry:
92
92
br label %loop
93
93
}
94
94
95
+ ; Hoist ADD and copy NUW if both ops have it.
96
+ ; Another version where operands are commuted.
97
+ define void @add_nuw_comm2 (i64 %c1 , i64 %c2 ) {
98
+ ; CHECK-LABEL: @add_nuw_comm2(
99
+ ; CHECK-NEXT: entry:
100
+ ; CHECK-NEXT: [[INVARIANT_OP:%.*]] = add nuw i64 [[C2:%.*]], [[C1:%.*]]
101
+ ; CHECK-NEXT: br label [[LOOP:%.*]]
102
+ ; CHECK: loop:
103
+ ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT_REASS:%.*]], [[LOOP]] ]
104
+ ; CHECK-NEXT: [[STEP_ADD:%.*]] = add nuw i64 [[INDEX]], [[C1]]
105
+ ; CHECK-NEXT: call void @use(i64 [[STEP_ADD]])
106
+ ; CHECK-NEXT: [[INDEX_NEXT_REASS]] = add nuw i64 [[INVARIANT_OP]], [[INDEX]]
107
+ ; CHECK-NEXT: br label [[LOOP]]
108
+ ;
109
+ entry:
110
+ br label %loop
111
+
112
+ loop:
113
+ %index = phi i64 [ 0 , %entry ], [ %index.next , %loop ]
114
+ %step.add = add nuw i64 %index , %c1
115
+ call void @use (i64 %step.add )
116
+ %index.next = add nuw i64 %c2 , %step.add
117
+ br label %loop
118
+ }
119
+
120
+ ; Hoist ADD and copy NUW if both ops have it.
121
+ ; Another version where operands are commuted.
122
+ define void @add_nuw_comm3 (i64 %c1 , i64 %c2 ) {
123
+ ; CHECK-LABEL: @add_nuw_comm3(
124
+ ; CHECK-NEXT: entry:
125
+ ; CHECK-NEXT: [[INVARIANT_OP:%.*]] = add nuw i64 [[C2:%.*]], [[C1:%.*]]
126
+ ; CHECK-NEXT: br label [[LOOP:%.*]]
127
+ ; CHECK: loop:
128
+ ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT_REASS:%.*]], [[LOOP]] ]
129
+ ; CHECK-NEXT: [[STEP_ADD:%.*]] = add nuw i64 [[C1]], [[INDEX]]
130
+ ; CHECK-NEXT: call void @use(i64 [[STEP_ADD]])
131
+ ; CHECK-NEXT: [[INDEX_NEXT_REASS]] = add nuw i64 [[INVARIANT_OP]], [[INDEX]]
132
+ ; CHECK-NEXT: br label [[LOOP]]
133
+ ;
134
+ entry:
135
+ br label %loop
136
+
137
+ loop:
138
+ %index = phi i64 [ 0 , %entry ], [ %index.next , %loop ]
139
+ %step.add = add nuw i64 %c1 , %index
140
+ call void @use (i64 %step.add )
141
+ %index.next = add nuw i64 %c2 , %step.add
142
+ br label %loop
143
+ }
144
+
95
145
; Hoist MUL and drop NUW even if both ops have it.
96
146
define void @mul_nuw (i64 %c1 , i64 %c2 ) {
97
147
; CHECK-LABEL: @mul_nuw(
@@ -116,7 +166,8 @@ loop:
116
166
br label %loop
117
167
}
118
168
119
- ; Hoist MUL and drop NUW even if both ops have it. Commutative version.
169
+ ; Hoist MUL and drop NUW even if both ops have it.
170
+ ; Version where operands are commuted.
120
171
define void @mul_nuw_comm (i64 %c1 , i64 %c2 ) {
121
172
; CHECK-LABEL: @mul_nuw_comm(
122
173
; CHECK-NEXT: entry:
@@ -140,6 +191,56 @@ loop:
140
191
br label %loop
141
192
}
142
193
194
+ ; Hoist MUL and drop NUW even if both ops have it.
195
+ ; Another version where operands are commuted.
196
+ define void @mul_nuw_comm2 (i64 %c1 , i64 %c2 ) {
197
+ ; CHECK-LABEL: @mul_nuw_comm2(
198
+ ; CHECK-NEXT: entry:
199
+ ; CHECK-NEXT: [[INVARIANT_OP:%.*]] = mul i64 [[C2:%.*]], [[C1:%.*]]
200
+ ; CHECK-NEXT: br label [[LOOP:%.*]]
201
+ ; CHECK: loop:
202
+ ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT_REASS:%.*]], [[LOOP]] ]
203
+ ; CHECK-NEXT: [[STEP_ADD:%.*]] = mul nuw i64 [[INDEX]], [[C1]]
204
+ ; CHECK-NEXT: call void @use(i64 [[STEP_ADD]])
205
+ ; CHECK-NEXT: [[INDEX_NEXT_REASS]] = mul i64 [[INVARIANT_OP]], [[INDEX]]
206
+ ; CHECK-NEXT: br label [[LOOP]]
207
+ ;
208
+ entry:
209
+ br label %loop
210
+
211
+ loop:
212
+ %index = phi i64 [ 0 , %entry ], [ %index.next , %loop ]
213
+ %step.add = mul nuw i64 %index , %c1
214
+ call void @use (i64 %step.add )
215
+ %index.next = mul nuw i64 %c2 , %step.add
216
+ br label %loop
217
+ }
218
+
219
+ ; Hoist MUL and drop NUW even if both ops have it.
220
+ ; Another version where operands are commuted.
221
+ define void @mul_nuw_comm3 (i64 %c1 , i64 %c2 ) {
222
+ ; CHECK-LABEL: @mul_nuw_comm3(
223
+ ; CHECK-NEXT: entry:
224
+ ; CHECK-NEXT: [[INVARIANT_OP:%.*]] = mul i64 [[C2:%.*]], [[C1:%.*]]
225
+ ; CHECK-NEXT: br label [[LOOP:%.*]]
226
+ ; CHECK: loop:
227
+ ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT_REASS:%.*]], [[LOOP]] ]
228
+ ; CHECK-NEXT: [[STEP_ADD:%.*]] = mul nuw i64 [[C1]], [[INDEX]]
229
+ ; CHECK-NEXT: call void @use(i64 [[STEP_ADD]])
230
+ ; CHECK-NEXT: [[INDEX_NEXT_REASS]] = mul i64 [[INVARIANT_OP]], [[INDEX]]
231
+ ; CHECK-NEXT: br label [[LOOP]]
232
+ ;
233
+ entry:
234
+ br label %loop
235
+
236
+ loop:
237
+ %index = phi i64 [ 0 , %entry ], [ %index.next , %loop ]
238
+ %step.add = mul nuw i64 %c1 , %index
239
+ call void @use (i64 %step.add )
240
+ %index.next = mul nuw i64 %c2 , %step.add
241
+ br label %loop
242
+ }
243
+
143
244
; Hoist ADD but don't copy NUW if only one op has it.
144
245
define void @add_no_nuw (i64 %c1 , i64 %c2 ) {
145
246
; CHECK-LABEL: @add_no_nuw(
0 commit comments