Skip to content

Commit c1650db

Browse files
committed
Add round trip test and documentation
1 parent a96e075 commit c1650db

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,12 @@ def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
695695
It requires one input operand and has one result, both types
696696
should be the same.
697697

698+
If the `nsw` (no signed wrap) attribute is present, the result is poison if
699+
signed overflow occurs.
700+
698701
```mlir
699702
%7 = cir.unary(inc, %1) : i32 -> i32
700-
%8 = cir.unary(dec, %2) : i32 -> i32
703+
%8 = cir.unary(dec, %2) nsw : i32 -> i32
701704
```
702705
}];
703706

@@ -868,9 +871,21 @@ def BinOp : CIR_Op<"binop", [Pure,
868871
It requires two input operands and has one result, all types
869872
should be the same.
870873

874+
If the `nsw` (no signed wrap) or `nuw` (no unsigned wrap) attributes are
875+
present, the result is poison if signed or unsigned overflow occurs
876+
(respectively).
877+
878+
If the `sat` (saturated) attribute is present, the result is clamped to
879+
the maximum value representatable by the type if it would otherwise
880+
exceed that value and is clamped to the minimum representable value if
881+
it would otherwise be below that value.
882+
871883
```mlir
872-
%7 = cir.binop(add, %1, %2) : !s32i
873-
%7 = cir.binop(mul, %1, %2) : !u8i
884+
%5 = cir.binop(add, %1, %2) : !s32i
885+
%6 = cir.binop(mul, %1, %2) : !u8i
886+
%7 = cir.binop(add, %1, %2) nsw : !s32i
887+
%8 = cir.binop(add, %3, %4) nuw : !u32i
888+
%9 = cir.binop(add, %1, %2) sat : !s32i
874889
```
875890
}];
876891

clang/test/CIR/IR/unary.cir

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: cir-opt %s | FileCheck %s
2+
3+
!s32i = !cir.int<s, 32>
4+
!s64i = !cir.int<s, 64>
5+
!u32i = !cir.int<u, 32>
6+
!u64i = !cir.int<u, 64>
7+
8+
module {
9+
cir.func @test_unary_unsigned() {
10+
%0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["a"] {alignment = 4 : i64}
11+
%1 = cir.load %0 : !cir.ptr<!u32i>, !u32i
12+
%2 = cir.unary(plus, %1) : !u32i, !u32i
13+
%3 = cir.unary(minus, %1) : !u32i, !u32i
14+
%4 = cir.unary(not, %1) : !u32i, !u32i
15+
%5 = cir.unary(inc, %1) : !u32i, !u32i
16+
%6 = cir.unary(dec, %1) : !u32i, !u32i
17+
cir.return
18+
}
19+
// CHECK: cir.func @test_unary_unsigned() {
20+
// CHECK: %0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["a"] {alignment = 4 : i64}
21+
// CHECK: %1 = cir.load %0 : !cir.ptr<!u32i>, !u32i
22+
// CHECK: %2 = cir.unary(plus, %1) : !u32i, !u32i
23+
// CHECK: %3 = cir.unary(minus, %1) : !u32i, !u32i
24+
// CHECK: %4 = cir.unary(not, %1) : !u32i, !u32i
25+
// CHECK: %5 = cir.unary(inc, %1) : !u32i, !u32i
26+
// CHECK: %6 = cir.unary(dec, %1) : !u32i, !u32i
27+
// CHECK: cir.return
28+
// CHECK: }
29+
30+
cir.func @test_unary_signed() {
31+
%0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["a"] {alignment = 4 : i64}
32+
%1 = cir.load %0 : !cir.ptr<!s32i>, !s32i
33+
%2 = cir.unary(plus, %1) : !s32i, !s32i
34+
%3 = cir.unary(minus, %1) nsw : !s32i, !s32i
35+
%4 = cir.unary(not, %1) : !s32i, !s32i
36+
%5 = cir.unary(inc, %1) nsw : !s32i, !s32i
37+
%6 = cir.unary(dec, %1) nsw : !s32i, !s32i
38+
cir.return
39+
}
40+
// CHECK: cir.func @test_unary_signed() {
41+
// CHECK: %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["a"] {alignment = 4 : i64}
42+
// CHECK: %1 = cir.load %0 : !cir.ptr<!s32i>, !s32i
43+
// CHECK: %2 = cir.unary(plus, %1) : !s32i, !s32i
44+
// CHECK: %3 = cir.unary(minus, %1) nsw : !s32i, !s32i
45+
// CHECK: %4 = cir.unary(not, %1) : !s32i, !s32i
46+
// CHECK: %5 = cir.unary(inc, %1) nsw : !s32i, !s32i
47+
// CHECK: %6 = cir.unary(dec, %1) nsw : !s32i, !s32i
48+
// CHECK: cir.return
49+
// CHECK: }
50+
}

0 commit comments

Comments
 (0)