================
@@ -1376,45 +1424,52 @@ mlir::LogicalResult
CIRToLLVMPtrStrideOpLowering::matchAndRewrite(
mlir::IntegerType::Signless);
// Zero-extend, sign-extend or trunc the pointer value.
mlir::Value index = adaptor.getStride();
- const unsigned width =
- mlir::cast<mlir::IntegerType>(index.getType()).getWidth();
- const std::optional<std::uint64_t> layoutWidth =
- dataLayout.getTypeIndexBitwidth(adaptor.getBase().getType());
-
- mlir::Operation *indexOp = index.getDefiningOp();
- if (indexOp && layoutWidth && width != *layoutWidth) {
- // If the index comes from a subtraction, make sure the extension happens
- // before it. To achieve that, look at unary minus, which already got
- // lowered to "sub 0, x".
- const auto sub = dyn_cast<mlir::LLVM::SubOp>(indexOp);
- auto unary = ptrStrideOp.getStride().getDefiningOp<cir::UnaryOp>();
- bool rewriteSub =
- unary && unary.getKind() == cir::UnaryOpKind::Minus && sub;
- if (rewriteSub)
- index = indexOp->getOperand(1);
-
- // Handle the cast
- const auto llvmDstType = mlir::IntegerType::get(ctx, *layoutWidth);
- index = getLLVMIntCast(rewriter, index, llvmDstType,
- ptrStrideOp.getStride().getType().isUnsigned(),
- width, *layoutWidth);
-
- // Rewrite the sub in front of extensions/trunc
- if (rewriteSub) {
- index = mlir::LLVM::SubOp::create(
- rewriter, index.getLoc(), index.getType(),
- mlir::LLVM::ConstantOp::create(rewriter, index.getLoc(),
- index.getType(), 0),
- index);
- rewriter.eraseOp(sub);
- }
- }
+ index = convertToIndexTy(
+ rewriter, ptrStrideOp->getParentOfType<mlir::ModuleOp>(), index,
+ adaptor.getBase().getType(),
+ dyn_cast<cir::IntType>(ptrStrideOp.getOperand(1).getType()));
----------------
erichkeane wrote:
This one I couldn't actually do, the 'stride' includes a cast to 'int', and
since we're working on the op, it sometimes ends up in the 'wrong' type, thus
`getStride` asserts (as it doesn't have a CIR::IntType in it). @andykaylor
mentions that this is because we are sometimes in a 'in between' state at this
time, which causes the problem.
https://github.com/llvm/llvm-project/pull/172897
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits