File tree 2 files changed +28
-3
lines changed
lib/CIR/Dialect/Transforms
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -438,9 +438,13 @@ class CIRTernaryOpFlattening
438
438
auto *condBlock = rewriter.getInsertionBlock ();
439
439
auto opPosition = rewriter.getInsertionPoint ();
440
440
auto *remainingOpsBlock = rewriter.splitBlock (condBlock, opPosition);
441
- auto *continueBlock = rewriter.createBlock (
442
- remainingOpsBlock, op->getResultTypes (),
443
- SmallVector<mlir::Location>(/* result number always 1 */ 1 , loc));
441
+ SmallVector<mlir::Location, 2 > locs;
442
+ // Ternary result is optional, make sure to populate the location only
443
+ // when relevant.
444
+ if (op->getResultTypes ().size ())
445
+ locs.push_back (loc);
446
+ auto *continueBlock =
447
+ rewriter.createBlock (remainingOpsBlock, op->getResultTypes (), locs);
444
448
rewriter.create <mlir::cir::BrOp>(loc, remainingOpsBlock);
445
449
446
450
auto &trueRegion = op.getTrueRegion ();
Original file line number Diff line number Diff line change @@ -44,4 +44,25 @@ module {
44
44
// CHECK: cir.return %8 : !s32i
45
45
// CHECK: }
46
46
47
+ cir.func @foo2(%arg0: !cir.bool) {
48
+ cir.ternary(%arg0, true {
49
+ cir.yield
50
+ }, false {
51
+ cir.yield
52
+ }) : (!cir.bool) -> ()
53
+ cir.return
54
+ }
55
+
56
+ // CHECK: cir.func @foo2(%arg0: !cir.bool) {
57
+ // CHECK: cir.brcond %arg0 ^bb1, ^bb2
58
+ // CHECK: ^bb1: // pred: ^bb0
59
+ // CHECK: cir.br ^bb3
60
+ // CHECK: ^bb2: // pred: ^bb0
61
+ // CHECK: cir.br ^bb3
62
+ // CHECK: ^bb3: // 2 preds: ^bb1, ^bb2
63
+ // CHECK: cir.br ^bb4
64
+ // CHECK: ^bb4: // pred: ^bb3
65
+ // CHECK: cir.return
66
+ // CHECK: }
67
+
47
68
}
You can’t perform that action at this time.
0 commit comments