@@ -291,7 +291,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
291291 Variadic<LLVM_ScalarOrVectorOf<AnySignlessInteger>>:$dynamicIndices,
292292 DenseI32ArrayAttr:$rawConstantIndices,
293293 TypeAttr:$elem_type,
294- UnitAttr:$inbounds );
294+ GEPNoWrapFlagsProp:$gepNoWrapFlags );
295295 let results = (outs LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$res);
296296 let skipDefaultBuilders = 1;
297297
@@ -303,8 +303,10 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
303303 as indices. In the case of indexing within a structure, it is required to
304304 either use constant indices directly, or supply a constant SSA value.
305305
306- An optional 'inbounds' attribute specifies the low-level pointer arithmetic
306+ Optional attributes can be used to specify the low-level pointer arithmetic
307307 overflow behavior that LLVM uses after lowering the operation to LLVM IR.
308+ The acceptable attributes could be one of or the combination of 'inbounds',
309+ 'nusw' or 'nuw'.
308310
309311 Examples:
310312
@@ -323,10 +325,12 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
323325
324326 let builders = [
325327 OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$basePtr,
326- "ValueRange":$indices, CArg<"bool", "false">:$inbounds,
328+ "ValueRange":$indices,
329+ CArg<"GEPNoWrapFlags", "GEPNoWrapFlags::none">:$gepNoWrapFlags,
327330 CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
328331 OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$basePtr,
329- "ArrayRef<GEPArg>":$indices, CArg<"bool", "false">:$inbounds,
332+ "ArrayRef<GEPArg>":$indices,
333+ CArg<"GEPNoWrapFlags", "GEPNoWrapFlags::none">:$gepNoWrapFlags,
330334 CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
331335 ];
332336 let llvmBuilder = [{
@@ -343,10 +347,13 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
343347 }
344348 Type baseElementType = op.getElemType();
345349 llvm::Type *elementType = moduleTranslation.convertType(baseElementType);
346- $res = builder.CreateGEP(elementType, $base, indices, "", $inbounds);
350+ $res = builder.CreateGEP(elementType, $base, indices, "",
351+ llvm::GEPNoWrapFlags::fromRaw(
352+ static_cast<unsigned>(
353+ op.getGepNoWrapFlags())));
347354 }];
348355 let assemblyFormat = [{
349- (`inbounds` $inbounds ^)?
356+ ($gepNoWrapFlags ^)?
350357 $base `[` custom<GEPIndices>($dynamicIndices, $rawConstantIndices) `]` attr-dict
351358 `:` functional-type(operands, results) `,` $elem_type
352359 }];
0 commit comments