Skip to content

Conversation

@AmrDeveloper
Copy link
Member

@AmrDeveloper AmrDeveloper commented Jan 29, 2025

Fixing Lit test after rebasing

CIRToLLVMPtrStrideOpLowering will not emit casting in this case because the width is equal to *layoutWidth

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".
auto sub = dyn_cast<mlir::LLVM::SubOp>(indexOp);
auto unary = dyn_cast_if_present<cir::UnaryOp>(
ptrStrideOp.getStride().getDefiningOp());
bool rewriteSub =
unary && unary.getKind() == cir::UnaryOpKind::Minus && sub;
if (rewriteSub)
index = indexOp->getOperand(1);
// Handle the cast
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 = rewriter.create<mlir::LLVM::SubOp>(
index.getLoc(), index.getType(),
rewriter.create<mlir::LLVM::ConstantOp>(
index.getLoc(), index.getType(),
mlir::IntegerAttr::get(index.getType(), 0)),
index);
rewriter.eraseOp(sub);
}
}
rewriter.replaceOpWithNewOp<mlir::LLVM::GEPOp>(
ptrStrideOp, resultTy, elementTy, adaptor.getBase(), index);
return mlir::success();

Fixes: #1295

@AmrDeveloper
Copy link
Member Author

Is there a reason to expect a cast instruction in this case? From my understanding should emit GEPOp?

@bcardosolopes, @lanza

@bcardosolopes bcardosolopes merged commit c4e5842 into llvm:main Jan 31, 2025
7 checks passed
lanza pushed a commit that referenced this pull request Mar 18, 2025
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lowering/ptrstride.cir has been xfailed while rebasing

2 participants