@@ -264,11 +264,13 @@ bool mlir::getInnermostParallelLoops(Operation *rootOp,
264
264
static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend,
265
265
int64_t divisor) {
266
266
assert (divisor > 0 && " expected positive divisor" );
267
- assert (dividend.getType ().isIndex () && " expected index-typed value" );
267
+ assert (dividend.getType ().isIntOrIndex () &&
268
+ " expected integer or index-typed value" );
268
269
269
270
Value divisorMinusOneCst =
270
- builder.create <arith::ConstantIndexOp>(loc, divisor - 1 );
271
- Value divisorCst = builder.create <arith::ConstantIndexOp>(loc, divisor);
271
+ createIntOrIndexConstant (builder, loc, dividend.getType (), divisor - 1 );
272
+ Value divisorCst =
273
+ createIntOrIndexConstant (builder, loc, dividend.getType (), divisor);
272
274
Value sum = builder.create <arith::AddIOp>(loc, dividend, divisorMinusOneCst);
273
275
return builder.create <arith::DivUIOp>(loc, sum, divisorCst);
274
276
}
@@ -279,9 +281,9 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
279
281
// where divis is rounding-to-zero division.
280
282
static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend,
281
283
Value divisor) {
282
- assert (dividend.getType ().isIndex () && " expected index-typed value " );
283
-
284
- Value cstOne = builder. create <arith::ConstantIndexOp>(loc , 1 );
284
+ assert (dividend.getType ().isIntOrIndex () &&
285
+ " expected integer or index-typed value " );
286
+ Value cstOne = createIntOrIndexConstant ( builder, loc, dividend. getType () , 1 );
285
287
Value divisorMinusOne = builder.create <arith::SubIOp>(loc, divisor, cstOne);
286
288
Value sum = builder.create <arith::AddIOp>(loc, dividend, divisorMinusOne);
287
289
return builder.create <arith::DivUIOp>(loc, sum, divisor);
@@ -388,16 +390,17 @@ LogicalResult mlir::loopUnrollByFactor(
388
390
// Create constant for 'upperBoundUnrolled' and set epilogue loop flag.
389
391
generateEpilogueLoop = upperBoundUnrolledCst < ubCst;
390
392
if (generateEpilogueLoop)
391
- upperBoundUnrolled = boundsBuilder. create <arith::ConstantIndexOp> (
392
- loc, upperBoundUnrolledCst);
393
+ upperBoundUnrolled = createIntOrIndexConstant (
394
+ boundsBuilder, loc, forOp. getUpperBound (). getType () , upperBoundUnrolledCst);
393
395
else
394
396
upperBoundUnrolled = forOp.getUpperBound ();
395
397
396
398
// Create constant for 'stepUnrolled'.
397
- stepUnrolled = stepCst == stepUnrolledCst
398
- ? step
399
- : boundsBuilder.create <arith::ConstantIndexOp>(
400
- loc, stepUnrolledCst);
399
+ stepUnrolled =
400
+ stepCst == stepUnrolledCst
401
+ ? step
402
+ : createIntOrIndexConstant (boundsBuilder, loc, step.getType (),
403
+ stepUnrolledCst);
401
404
} else {
402
405
// Dynamic loop bounds computation.
403
406
// TODO: Add dynamic asserts for negative lb/ub/step, or
@@ -407,8 +410,8 @@ LogicalResult mlir::loopUnrollByFactor(
407
410
Value diff =
408
411
boundsBuilder.create <arith::SubIOp>(loc, upperBound, lowerBound);
409
412
Value tripCount = ceilDivPositive (boundsBuilder, loc, diff, step);
410
- Value unrollFactorCst =
411
- boundsBuilder. create <arith::ConstantIndexOp>(loc , unrollFactor);
413
+ Value unrollFactorCst = createIntOrIndexConstant (
414
+ boundsBuilder, loc, tripCount. getType () , unrollFactor);
412
415
Value tripCountRem =
413
416
boundsBuilder.create <arith::RemSIOp>(loc, tripCount, unrollFactorCst);
414
417
// Compute tripCountEvenMultiple = tripCount - (tripCount % unrollFactor)
@@ -455,7 +458,7 @@ LogicalResult mlir::loopUnrollByFactor(
455
458
[&](unsigned i, Value iv, OpBuilder b) {
456
459
// iv' = iv + step * i;
457
460
auto stride = b.create <arith::MulIOp>(
458
- loc, step, b. create <arith::ConstantIndexOp>(loc , i));
461
+ loc, step, createIntOrIndexConstant (b, loc, iv. getType () , i));
459
462
return b.create <arith::AddIOp>(loc, iv, stride);
460
463
},
461
464
annotateFn, iterArgs, yieldedValues);
0 commit comments