Skip to content

Commit ad4e7d2

Browse files
committed
results of scope op forwarded
1 parent bae7bd9 commit ad4e7d2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ class CIRScopeOpFlattening : public mlir::OpRewritePattern<cir::ScopeOp> {
137137
auto *currentBlock = rewriter.getInsertionBlock();
138138
auto *remainingOpsBlock =
139139
rewriter.splitBlock(currentBlock, rewriter.getInsertionPoint());
140-
mlir::Block *continueBlock;
141-
if (scopeOp.getNumResults() == 0)
142-
continueBlock = remainingOpsBlock;
143-
else
144-
llvm_unreachable("NYI");
140+
mlir::Block *continueBlock = remainingOpsBlock;
141+
if (scopeOp.getNumResults() > 0)
142+
continueBlock->addArguments(scopeOp.getResultTypes(), loc);
145143

146144
// Inline body region.
147145
auto *beforeBody = &scopeOp.getRegion().front();

clang/test/CIR/CodeGen/fullexpr.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o - %s \
4+
// RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll
5+
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
36

47
int go(int const& val);
58

@@ -18,3 +21,19 @@ int go1() {
1821
// CHECK-NEXT: cir.yield %[[#RValTmp]] : !s32i
1922
// CHECK-NEXT: }
2023
// CHECK-NEXT: cir.store %[[#RVal]], %[[#XAddr]] : !s32i, !cir.ptr<!s32i>
24+
25+
// LLVM-LABEL: @_Z3go1v()
26+
// LLVM-NEXT: %[[#TmpAddr:]] = alloca i32, i64 1, align 4
27+
// LLVM: br label %[[before_body:[0-9]+]]
28+
// LLVM: [[before_body]]:
29+
// LLVM-NEXT: store i32 1, ptr %[[#TmpAddr]], align 4
30+
// LLVM-NEXT: %[[#RValTmp:]] = call i32 @_Z2goRKi(ptr %[[#TmpAddr]])
31+
// LLVM-NEXT: br label %[[continue_block:[0-9]+]]
32+
33+
// LLVM: [[continue_block]]:
34+
// LLVM-NEXT: [[PHI:%.*]] = phi i32 [ %[[#RValTmp]], %[[before_body]] ]
35+
// LLVM: store i32 [[PHI]], ptr [[TMP0:%.*]], align 4
36+
// LLVM: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
37+
// LLVM: store i32 [[TMP1]], ptr [[TMP2:%.*]], align 4
38+
// LLVM: [[TMP3:%.*]] = load i32, ptr [[TMP2]], align 4
39+
// LLVM: ret i32 [[TMP3]]

0 commit comments

Comments
 (0)