@@ -226,7 +226,7 @@ def Arith_AddIOp : Arith_IntBinaryOpWithOverflowFlags<"addi", [Commutative]> {
226
226
these is required to be the same type. This type may be an integer scalar type,
227
227
a vector whose element type is integer, or a tensor of integers.
228
228
229
- This op supports `nuw`/`nsw` overflow flags which stands stand for
229
+ This op supports `nuw`/`nsw` overflow flags which stands for
230
230
"No Unsigned Wrap" and "No Signed Wrap", respectively. If the `nuw` and/or
231
231
`nsw` flags are present, and an unsigned/signed overflow occurs
232
232
(respectively), the result is poison.
@@ -321,7 +321,7 @@ def Arith_SubIOp : Arith_IntBinaryOpWithOverflowFlags<"subi"> {
321
321
these is required to be the same type. This type may be an integer scalar type,
322
322
a vector whose element type is integer, or a tensor of integers.
323
323
324
- This op supports `nuw`/`nsw` overflow flags which stands stand for
324
+ This op supports `nuw`/`nsw` overflow flags which stands for
325
325
"No Unsigned Wrap" and "No Signed Wrap", respectively. If the `nuw` and/or
326
326
`nsw` flags are present, and an unsigned/signed overflow occurs
327
327
(respectively), the result is poison.
@@ -367,7 +367,7 @@ def Arith_MulIOp : Arith_IntBinaryOpWithOverflowFlags<"muli",
367
367
these is required to be the same type. This type may be an integer scalar type,
368
368
a vector whose element type is integer, or a tensor of integers.
369
369
370
- This op supports `nuw`/`nsw` overflow flags which stands stand for
370
+ This op supports `nuw`/`nsw` overflow flags which stands for
371
371
"No Unsigned Wrap" and "No Signed Wrap", respectively. If the `nuw` and/or
372
372
`nsw` flags are present, and an unsigned/signed overflow occurs
373
373
(respectively), the result is poison.
@@ -800,7 +800,7 @@ def Arith_ShLIOp : Arith_IntBinaryOpWithOverflowFlags<"shli"> {
800
800
operand is greater or equal than the bitwidth of the first operand, then the
801
801
operation returns poison.
802
802
803
- This op supports `nuw`/`nsw` overflow flags which stands stand for
803
+ This op supports `nuw`/`nsw` overflow flags which stands for
804
804
"No Unsigned Wrap" and "No Signed Wrap", respectively. If the `nuw` and/or
805
805
`nsw` flags are present, and an unsigned/signed overflow occurs
806
806
(respectively), the result is poison.
@@ -1271,25 +1271,49 @@ def Arith_ScalingExtFOp
1271
1271
// TruncIOp
1272
1272
//===----------------------------------------------------------------------===//
1273
1273
1274
- def Arith_TruncIOp : Arith_IToICastOp<"trunci"> {
1274
+ def Arith_TruncIOp : Op<Arith_Dialect, "trunci",
1275
+ [Pure, SameOperandsAndResultShape, SameInputOutputTensorDims,
1276
+ DeclareOpInterfaceMethods<CastOpInterface>,
1277
+ DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>,
1278
+ DeclareOpInterfaceMethods<ArithIntegerOverflowFlagsInterface>]> {
1275
1279
let summary = "integer truncation operation";
1276
1280
let description = [{
1277
1281
The integer truncation operation takes an integer input of
1278
1282
width M and an integer destination type of width N. The destination
1279
1283
bit-width must be smaller than the input bit-width (N < M).
1280
1284
The top-most (N - M) bits of the input are discarded.
1281
1285
1286
+ This op supports `nuw`/`nsw` overflow flags which stands for "No Unsigned
1287
+ Wrap" and "No Signed Wrap", respectively. If the nuw keyword is present,
1288
+ and any of the truncated bits are non-zero, the result is a poison value.
1289
+ If the nsw keyword is present, and any of the truncated bits are not the
1290
+ same as the top bit of the truncation result, the result is a poison value.
1291
+
1282
1292
Example:
1283
1293
1284
1294
```mlir
1295
+ // Scalar truncation.
1285
1296
%1 = arith.constant 21 : i5 // %1 is 0b10101
1286
1297
%2 = arith.trunci %1 : i5 to i4 // %2 is 0b0101
1287
1298
%3 = arith.trunci %1 : i5 to i3 // %3 is 0b101
1288
1299
1289
- %5 = arith.trunci %0 : vector<2 x i32> to vector<2 x i16>
1300
+ // Vector truncation.
1301
+ %4 = arith.trunci %0 : vector<2 x i32> to vector<2 x i16>
1302
+
1303
+ // Scalar truncation with overflow flags.
1304
+ %5 = arith.trunci %a overflow<nsw, nuw> : i32 to i16
1290
1305
```
1291
1306
}];
1292
1307
1308
+ let arguments = (ins
1309
+ SignlessFixedWidthIntegerLike:$in,
1310
+ DefaultValuedAttr<Arith_IntegerOverflowAttr,
1311
+ "::mlir::arith::IntegerOverflowFlags::none">:$overflowFlags);
1312
+ let results = (outs SignlessFixedWidthIntegerLike:$out);
1313
+ let assemblyFormat = [{
1314
+ $in (`overflow` `` $overflowFlags^)? attr-dict
1315
+ `:` type($in) `to` type($out)
1316
+ }];
1293
1317
let hasFolder = 1;
1294
1318
let hasCanonicalizer = 1;
1295
1319
let hasVerifier = 1;
0 commit comments