Skip to content

Commit 499109d

Browse files
committed
Revert "GEP with a constant offset should have inbounds attribute."
This reverts commit 5415cbc.
1 parent 2660600 commit 499109d

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
296296
let skipDefaultBuilders = 1;
297297

298298
let description = [{
299-
This operation mirrors LLVM IR's 'getelementptr' operation that is used to
299+
This operation mirrors LLVM IRs 'getelementptr' operation that is used to
300300
perform pointer arithmetic.
301301

302302
Like in LLVM IR, it is possible to use both constants as well as SSA values
@@ -334,28 +334,16 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
334334
indices.reserve($rawConstantIndices.size());
335335
GEPIndicesAdaptor<decltype($dynamicIndices)>
336336
gepIndices(op.getRawConstantIndicesAttr(), $dynamicIndices);
337-
338-
for (const auto &valueOrAttr : gepIndices) {
339-
if (llvm::isa<mlir::IntegerAttr>(valueOrAttr)) {
340-
auto intAttr = valueOrAttr.get<mlir::IntegerAttr>();
341-
indices.push_back(builder.getInt32(intAttr.getInt()));
342-
} else {
343-
indices.push_back(valueOrAttr.get<llvm::Value*>());
344-
}
345-
}
346-
347-
bool allIndicesConstant = true;
348-
for(llvm::Value* value: indices) {
349-
if(auto *C = dyn_cast<llvm::Constant>(value)) {
350-
continue;
351-
} else {
352-
allIndicesConstant = false;
353-
break;
354-
}
337+
for (PointerUnion<IntegerAttr, llvm::Value*> valueOrAttr : gepIndices) {
338+
if (llvm::Value* value = ::llvm::dyn_cast<llvm::Value*>(valueOrAttr))
339+
indices.push_back(value);
340+
else
341+
indices.push_back(
342+
builder.getInt32(valueOrAttr.get<IntegerAttr>().getInt()));
355343
}
356344
Type baseElementType = op.getElemType();
357345
llvm::Type *elementType = moduleTranslation.convertType(baseElementType);
358-
$res = builder.CreateGEP(elementType, $base, indices, "", $inbounds?true:allIndicesConstant);
346+
$res = builder.CreateGEP(elementType, $base, indices, "", $inbounds);
359347
}];
360348
let assemblyFormat = [{
361349
(`inbounds` $inbounds^)?

0 commit comments

Comments
 (0)