@@ -296,7 +296,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
296
296
let skipDefaultBuilders = 1;
297
297
298
298
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
300
300
perform pointer arithmetic.
301
301
302
302
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,
334
334
indices.reserve($rawConstantIndices.size());
335
335
GEPIndicesAdaptor<decltype($dynamicIndices)>
336
336
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()));
355
343
}
356
344
Type baseElementType = op.getElemType();
357
345
llvm::Type *elementType = moduleTranslation.convertType(baseElementType);
358
- $res = builder.CreateGEP(elementType, $base, indices, "", $inbounds?true:allIndicesConstant );
346
+ $res = builder.CreateGEP(elementType, $base, indices, "", $inbounds);
359
347
}];
360
348
let assemblyFormat = [{
361
349
(`inbounds` $inbounds^)?
0 commit comments