Skip to content

Commit 2b03d94

Browse files
authored
[CIR] Relax the requirement for ternary operation (#1168)
The requirement for the size of then-else part of cir.ternary operation seems to be too conservative. Like the example shows, it is possible the regions got expanded during the transformation.
1 parent 2968396 commit 2b03d94

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,8 @@ def TernaryOp : CIR_Op<"ternary",
805805
```
806806
}];
807807
let arguments = (ins CIR_BoolType:$cond);
808-
let regions = (region SizedRegion<1>:$trueRegion,
809-
SizedRegion<1>:$falseRegion);
808+
let regions = (region AnyRegion:$trueRegion,
809+
AnyRegion:$falseRegion);
810810
let results = (outs Optional<CIR_AnyType>:$result);
811811

812812
let skipDefaultBuilders = 1;

clang/test/CIR/CodeGen/ternary.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -fno-clangir-call-conv-lowering %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
3+
4+
#include <stdarg.h>
5+
6+
double f1(int cond, int n, ...) {
7+
va_list valist;
8+
va_start(valist, n);
9+
double res = cond ? va_arg(valist, double) : 0;
10+
va_end(valist);
11+
return res;
12+
}
13+
14+
// Fine enough to check it passes the verifying.
15+
// CIR: cir.ternary

0 commit comments

Comments
 (0)