[Mlir-commits] [mlir] [MLIR][LLVM] Support inrange in GEP (PR #220424)
Letu Ren
llvmlistbot at llvm.org
Sat Sep 12 20:18:06 PDT 2026
================
@@ -1973,7 +1973,19 @@ FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) {
}));
if (failed(processInstruction(inst)))
return failure();
- return lookupValue(inst);
+ Value result = lookupValue(inst);
+ // getAsInstruction() does not preserve GEP `inrange`, which exists only on
+ // constant expressions. Reattach it to the imported GEPOp.
+ if (constExpr->getOpcode() == llvm::Instruction::GetElementPtr) {
+ if (std::optional<llvm::ConstantRange> inRange =
+ llvm::cast<llvm::GEPOperator>(constExpr)->getInRange()) {
+ auto gepOp = result.getDefiningOp<GEPOp>();
+ assert(gepOp && "expected GEPOp for getelementptr constexpr");
+ gepOp.setInrangeAttr(LLVM::ConstantRangeAttr::get(
+ context, inRange->getLower(), inRange->getUpper()));
+ }
+ }
+ return result;
----------------
FantasqueX wrote:
https://github.com/llvm/llvm-project/blob/474b7358a90e4f22b04e6a0933381d239fb7044e/llvm/lib/IR/Constants.cpp#L3693-L3697
This one doesn't accept inrange attr and I need to add a large amount of code :(
https://github.com/llvm/llvm-project/pull/220424
More information about the Mlir-commits
mailing list