[clang] [CIR] Upstream TernaryOp (PR #137184)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 15:39:04 PDT 2025
================
@@ -1246,6 +1246,59 @@ def SelectOp : CIR_Op<"select", [Pure,
}];
}
+//===----------------------------------------------------------------------===//
+// TernaryOp
+//===----------------------------------------------------------------------===//
+
+def TernaryOp : CIR_Op<"ternary",
+ [DeclareOpInterfaceMethods<RegionBranchOpInterface>,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]> {
+ let summary = "The `cond ? a : b` C/C++ ternary operation";
+ let description = [{
+ The `cir.ternary` operation represents C/C++ ternary, much like a `select`
+ operation. The first argument is a `cir.bool` condition to evaluate, followed
+ by two regions to execute (true or false). This is different from `cir.if`
+ since each region is one block sized and the `cir.yield` closing the block
+ scope should have one argument.
+
+ Example:
+
+ ```mlir
+ // x = cond ? a : b;
----------------
andykaylor wrote:
```suggestion
// cond = a && b;
```
Along with corresponding changes below. (See https://godbolt.org/z/TjxY77xEW)
https://github.com/llvm/llvm-project/pull/137184
More information about the cfe-commits
mailing list