@@ -2387,6 +2387,9 @@ struct XArrayCoorOpConversion
2387
2387
const bool baseIsBoxed = coor.getMemref ().getType ().isa <fir::BaseBoxType>();
2388
2388
TypePair baseBoxTyPair =
2389
2389
baseIsBoxed ? getBoxTypePair (coor.getMemref ().getType ()) : TypePair{};
2390
+ mlir::LLVM::IntegerOverflowFlagsAttr nsw =
2391
+ mlir::LLVM::IntegerOverflowFlagsAttr::get (
2392
+ rewriter.getContext (), mlir::LLVM::IntegerOverflowFlags::nsw);
2390
2393
2391
2394
// For each dimension of the array, generate the offset calculation.
2392
2395
for (unsigned i = 0 ; i < rank; ++i, ++indexOffset, ++shapeOffset,
@@ -2407,32 +2410,37 @@ struct XArrayCoorOpConversion
2407
2410
if (normalSlice)
2408
2411
step = integerCast (loc, rewriter, idxTy, operands[sliceOffset + 2 ]);
2409
2412
}
2410
- auto idx = rewriter.create <mlir::LLVM::SubOp>(loc, idxTy, index, lb);
2413
+ auto idx = rewriter.create <mlir::LLVM::SubOp>(loc, idxTy, index, lb, nsw );
2411
2414
mlir::Value diff =
2412
- rewriter.create <mlir::LLVM::MulOp>(loc, idxTy, idx, step);
2415
+ rewriter.create <mlir::LLVM::MulOp>(loc, idxTy, idx, step, nsw );
2413
2416
if (normalSlice) {
2414
2417
mlir::Value sliceLb =
2415
2418
integerCast (loc, rewriter, idxTy, operands[sliceOffset]);
2416
- auto adj = rewriter.create <mlir::LLVM::SubOp>(loc, idxTy, sliceLb, lb);
2417
- diff = rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, diff, adj);
2419
+ auto adj =
2420
+ rewriter.create <mlir::LLVM::SubOp>(loc, idxTy, sliceLb, lb, nsw);
2421
+ diff = rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, diff, adj, nsw);
2418
2422
}
2419
2423
// Update the offset given the stride and the zero based index `diff`
2420
2424
// that was just computed.
2421
2425
if (baseIsBoxed) {
2422
2426
// Use stride in bytes from the descriptor.
2423
2427
mlir::Value stride =
2424
2428
getStrideFromBox (loc, baseBoxTyPair, operands[0 ], i, rewriter);
2425
- auto sc = rewriter.create <mlir::LLVM::MulOp>(loc, idxTy, diff, stride);
2426
- offset = rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, sc, offset);
2429
+ auto sc =
2430
+ rewriter.create <mlir::LLVM::MulOp>(loc, idxTy, diff, stride, nsw);
2431
+ offset =
2432
+ rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, sc, offset, nsw);
2427
2433
} else {
2428
2434
// Use stride computed at last iteration.
2429
- auto sc = rewriter.create <mlir::LLVM::MulOp>(loc, idxTy, diff, prevExt);
2430
- offset = rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, sc, offset);
2435
+ auto sc =
2436
+ rewriter.create <mlir::LLVM::MulOp>(loc, idxTy, diff, prevExt, nsw);
2437
+ offset =
2438
+ rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, sc, offset, nsw);
2431
2439
// Compute next stride assuming contiguity of the base array
2432
2440
// (in element number).
2433
2441
auto nextExt = integerCast (loc, rewriter, idxTy, operands[shapeOffset]);
2434
- prevExt =
2435
- rewriter. create <mlir::LLVM::MulOp>(loc, idxTy, prevExt, nextExt);
2442
+ prevExt = rewriter. create <mlir::LLVM::MulOp>(loc, idxTy, prevExt,
2443
+ nextExt, nsw );
2436
2444
}
2437
2445
}
2438
2446
@@ -2491,8 +2499,8 @@ struct XArrayCoorOpConversion
2491
2499
assert (coor.getLenParams ().size () == 1 );
2492
2500
auto length = integerCast (loc, rewriter, idxTy,
2493
2501
operands[coor.lenParamsOffset ()]);
2494
- offset =
2495
- rewriter. create <mlir::LLVM::MulOp>(loc, idxTy, offset, length);
2502
+ offset = rewriter. create <mlir::LLVM::MulOp>(loc, idxTy, offset,
2503
+ length, nsw );
2496
2504
} else {
2497
2505
TODO (loc, " compute size of derived type with type parameters" );
2498
2506
}
@@ -2665,6 +2673,9 @@ struct CoordinateOpConversion
2665
2673
auto cpnTy = fir::dyn_cast_ptrOrBoxEleTy (boxObjTy);
2666
2674
mlir::Type llvmPtrTy = ::getLlvmPtrType (coor.getContext ());
2667
2675
mlir::Type byteTy = ::getI8Type (coor.getContext ());
2676
+ mlir::LLVM::IntegerOverflowFlagsAttr nsw =
2677
+ mlir::LLVM::IntegerOverflowFlagsAttr::get (
2678
+ rewriter.getContext (), mlir::LLVM::IntegerOverflowFlags::nsw);
2668
2679
2669
2680
for (unsigned i = 1 , last = operands.size (); i < last; ++i) {
2670
2681
if (auto arrTy = cpnTy.dyn_cast <fir::SequenceType>()) {
@@ -2680,9 +2691,9 @@ struct CoordinateOpConversion
2680
2691
index < lastIndex; ++index) {
2681
2692
mlir::Value stride = getStrideFromBox (loc, boxTyPair, operands[0 ],
2682
2693
index - i, rewriter);
2683
- auto sc = rewriter.create <mlir::LLVM::MulOp>(loc, idxTy,
2684
- operands[index], stride);
2685
- off = rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, sc, off);
2694
+ auto sc = rewriter.create <mlir::LLVM::MulOp>(
2695
+ loc, idxTy, operands[index], stride, nsw );
2696
+ off = rewriter.create <mlir::LLVM::AddOp>(loc, idxTy, sc, off, nsw );
2686
2697
}
2687
2698
resultAddr = rewriter.create <mlir::LLVM::GEPOp>(
2688
2699
loc, llvmPtrTy, byteTy, resultAddr,
0 commit comments