@@ -270,11 +270,13 @@ bool mlir::getInnermostParallelLoops(Operation *rootOp,
270270static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend,
271271 int64_t divisor) {
272272 assert (divisor > 0 && " expected positive divisor" );
273- assert (dividend.getType ().isIndex () && " expected index-typed value" );
273+ assert (dividend.getType ().isIntOrIndex () &&
274+ " expected integer or index-typed value" );
274275
275- Value divisorMinusOneCst =
276- builder.create <arith::ConstantIndexOp>(loc, divisor - 1 );
277- Value divisorCst = builder.create <arith::ConstantIndexOp>(loc, divisor);
276+ Value divisorMinusOneCst = builder.create <arith::ConstantOp>(
277+ loc, builder.getIntegerAttr (dividend.getType (), divisor - 1 ));
278+ Value divisorCst = builder.create <arith::ConstantOp>(
279+ loc, builder.getIntegerAttr (dividend.getType (), divisor));
278280 Value sum = builder.create <arith::AddIOp>(loc, dividend, divisorMinusOneCst);
279281 return builder.create <arith::DivUIOp>(loc, sum, divisorCst);
280282}
@@ -285,9 +287,10 @@ static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend,
285287// where divis is rounding-to-zero division.
286288static Value ceilDivPositive (OpBuilder &builder, Location loc, Value dividend,
287289 Value divisor) {
288- assert (dividend.getType ().isIndex () && " expected index-typed value" );
289-
290- Value cstOne = builder.create <arith::ConstantIndexOp>(loc, 1 );
290+ assert (dividend.getType ().isIntOrIndex () &&
291+ " expected integer or index-typed value" );
292+ Value cstOne = builder.create <arith::ConstantOp>(
293+ loc, builder.getOneAttr (dividend.getType ()));
291294 Value divisorMinusOne = builder.create <arith::SubIOp>(loc, divisor, cstOne);
292295 Value sum = builder.create <arith::AddIOp>(loc, dividend, divisorMinusOne);
293296 return builder.create <arith::DivUIOp>(loc, sum, divisor);
@@ -409,16 +412,18 @@ LogicalResult mlir::loopUnrollByFactor(
409412 // Create constant for 'upperBoundUnrolled' and set epilogue loop flag.
410413 generateEpilogueLoop = upperBoundUnrolledCst < ubCst;
411414 if (generateEpilogueLoop)
412- upperBoundUnrolled = boundsBuilder.create <arith::ConstantIndexOp>(
413- loc, upperBoundUnrolledCst);
415+ upperBoundUnrolled = boundsBuilder.create <arith::ConstantOp>(
416+ loc, boundsBuilder.getIntegerAttr (forOp.getUpperBound ().getType (),
417+ upperBoundUnrolledCst));
414418 else
415419 upperBoundUnrolled = forOp.getUpperBound ();
416420
417421 // Create constant for 'stepUnrolled'.
418422 stepUnrolled = stepCst == stepUnrolledCst
419423 ? step
420- : boundsBuilder.create <arith::ConstantIndexOp>(
421- loc, stepUnrolledCst);
424+ : boundsBuilder.create <arith::ConstantOp>(
425+ loc, boundsBuilder.getIntegerAttr (
426+ step.getType (), stepUnrolledCst));
422427 } else {
423428 // Dynamic loop bounds computation.
424429 // TODO: Add dynamic asserts for negative lb/ub/step, or
@@ -428,8 +433,8 @@ LogicalResult mlir::loopUnrollByFactor(
428433 Value diff =
429434 boundsBuilder.create <arith::SubIOp>(loc, upperBound, lowerBound);
430435 Value tripCount = ceilDivPositive (boundsBuilder, loc, diff, step);
431- Value unrollFactorCst =
432- boundsBuilder.create <arith::ConstantIndexOp>(loc , unrollFactor);
436+ Value unrollFactorCst = boundsBuilder. create <arith::ConstantOp>(
437+ loc, boundsBuilder.getIntegerAttr (tripCount. getType () , unrollFactor) );
433438 Value tripCountRem =
434439 boundsBuilder.create <arith::RemSIOp>(loc, tripCount, unrollFactorCst);
435440 // Compute tripCountEvenMultiple = tripCount - (tripCount % unrollFactor)
@@ -476,7 +481,9 @@ LogicalResult mlir::loopUnrollByFactor(
476481 [&](unsigned i, Value iv, OpBuilder b) {
477482 // iv' = iv + step * i;
478483 auto stride = b.create <arith::MulIOp>(
479- loc, step, b.create <arith::ConstantIndexOp>(loc, i));
484+ loc, step,
485+ b.create <arith::ConstantOp>(loc,
486+ b.getIntegerAttr (iv.getType (), i)));
480487 return b.create <arith::AddIOp>(loc, iv, stride);
481488 },
482489 annotateFn, iterArgs, yieldedValues);
0 commit comments