@@ -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:$noWrapFlags );
295295 let results = (outs LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$res);
296296 let skipDefaultBuilders = 1;
297297
@@ -303,8 +303,12 @@ 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+ The no-wrap flags can be used to specify the low-level pointer arithmetic
307307 overflow behavior that LLVM uses after lowering the operation to LLVM IR.
308+ Valid options include 'inbounds' (pointer arithmetic must be within object
309+ bounds), 'nusw' (no unsigned signed wrap), and 'nuw' (no unsigned wrap).
310+ Note that 'inbounds' implies 'nusw' which is ensured by the enum
311+ definition. The flags can be set individually or in combination.
308312
309313 Examples:
310314
@@ -323,10 +327,12 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
323327
324328 let builders = [
325329 OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$basePtr,
326- "ValueRange":$indices, CArg<"bool", "false">:$inbounds,
330+ "ValueRange":$indices,
331+ CArg<"GEPNoWrapFlags", "GEPNoWrapFlags::none">:$noWrapFlags,
327332 CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
328333 OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$basePtr,
329- "ArrayRef<GEPArg>":$indices, CArg<"bool", "false">:$inbounds,
334+ "ArrayRef<GEPArg>":$indices,
335+ CArg<"GEPNoWrapFlags", "GEPNoWrapFlags::none">:$noWrapFlags,
330336 CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
331337 ];
332338 let llvmBuilder = [{
@@ -343,10 +349,13 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
343349 }
344350 Type baseElementType = op.getElemType();
345351 llvm::Type *elementType = moduleTranslation.convertType(baseElementType);
346- $res = builder.CreateGEP(elementType, $base, indices, "", $inbounds);
352+ $res = builder.CreateGEP(elementType, $base, indices, "",
353+ llvm::GEPNoWrapFlags::fromRaw(
354+ static_cast<unsigned>(
355+ op.getNoWrapFlags())));
347356 }];
348357 let assemblyFormat = [{
349- (`inbounds` $inbounds ^)?
358+ ($noWrapFlags ^)?
350359 $base `[` custom<GEPIndices>($dynamicIndices, $rawConstantIndices) `]` attr-dict
351360 `:` functional-type(operands, results) `,` $elem_type
352361 }];
0 commit comments