@@ -291,7 +291,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
291
291
Variadic<LLVM_ScalarOrVectorOf<AnySignlessInteger>>:$dynamicIndices,
292
292
DenseI32ArrayAttr:$rawConstantIndices,
293
293
TypeAttr:$elem_type,
294
- UnitAttr:$inbounds );
294
+ GEPNoWrapFlagsProp:$noWrapFlags );
295
295
let results = (outs LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$res);
296
296
let skipDefaultBuilders = 1;
297
297
@@ -303,8 +303,12 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
303
303
as indices. In the case of indexing within a structure, it is required to
304
304
either use constant indices directly, or supply a constant SSA value.
305
305
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
307
307
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.
308
312
309
313
Examples:
310
314
@@ -323,10 +327,12 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
323
327
324
328
let builders = [
325
329
OpBuilder<(ins "Type":$resultType, "Type":$elementType, "Value":$basePtr,
326
- "ValueRange":$indices, CArg<"bool", "false">:$inbounds,
330
+ "ValueRange":$indices,
331
+ CArg<"GEPNoWrapFlags", "GEPNoWrapFlags::none">:$noWrapFlags,
327
332
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
328
333
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,
330
336
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>,
331
337
];
332
338
let llvmBuilder = [{
@@ -343,10 +349,13 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
343
349
}
344
350
Type baseElementType = op.getElemType();
345
351
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())));
347
356
}];
348
357
let assemblyFormat = [{
349
- (`inbounds` $inbounds ^)?
358
+ ($noWrapFlags ^)?
350
359
$base `[` custom<GEPIndices>($dynamicIndices, $rawConstantIndices) `]` attr-dict
351
360
`:` functional-type(operands, results) `,` $elem_type
352
361
}];
0 commit comments