[clang] [CIR] Add pass to fold empty branches (PR #239417)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 15:13:10 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir
Author: Andy Kaylor (andykaylor)
<details>
<summary>Changes</summary>
This adds a CIR pass to fold empty branches just before lowering to the LLVM dialect. The CFG flattening pass, in particular, creates a lot of empty branches. This changes cleans that up, which brings our output closer to classic codegen. Running the CIR canonicalize pass would have the same effect, but it also eliminates unused values, which seemed too aggressive.
Assisted-by: Cursor / claude-opus-5.5
---
Patch is 94.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/239417.diff
44 Files Affected:
- (modified) clang/include/clang/CIR/Dialect/Passes.h (+1)
- (modified) clang/include/clang/CIR/Dialect/Passes.td (+16)
- (added) clang/lib/CIR/Dialect/Transforms/CIRFoldEmptyBranches.cpp (+89)
- (modified) clang/lib/CIR/Dialect/Transforms/CMakeLists.txt (+1)
- (modified) clang/lib/CIR/Lowering/CIRPasses.cpp (+1)
- (modified) clang/test/CIR/CodeGen/abstract-cond.c (-2)
- (modified) clang/test/CIR/CodeGen/basic.c (+1-3)
- (modified) clang/test/CIR/CodeGen/binassign.c (-1)
- (modified) clang/test/CIR/CodeGen/cleanup-automatic-eh.cpp (-2)
- (modified) clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper-eh.cpp (+3-7)
- (modified) clang/test/CIR/CodeGen/cleanup-conditional.cpp (-5)
- (modified) clang/test/CIR/CodeGen/cleanup-scope-goto-out.cpp (+3-13)
- (modified) clang/test/CIR/CodeGen/cleanup-scope-goto-within.cpp (+2-8)
- (modified) clang/test/CIR/CodeGen/delete.cpp (-10)
- (modified) clang/test/CIR/CodeGen/dtors.cpp (-8)
- (modified) clang/test/CIR/CodeGen/ehspec-noexcept.cpp (+5-15)
- (modified) clang/test/CIR/CodeGen/ehspec.cpp (+2-4)
- (modified) clang/test/CIR/CodeGen/goto.cpp (+10-20)
- (modified) clang/test/CIR/CodeGen/if.cpp (+2-14)
- (modified) clang/test/CIR/CodeGen/instantiate-init.cpp (-4)
- (modified) clang/test/CIR/CodeGen/label.c (+3-11)
- (modified) clang/test/CIR/CodeGen/loop-cond-var-cleanup.cpp (+6-23)
- (modified) clang/test/CIR/CodeGen/loop.cpp (+3-37)
- (modified) clang/test/CIR/CodeGen/paren-init-list-eh.cpp (+3-2)
- (modified) clang/test/CIR/CodeGen/partial-array-cleanup.cpp (+2-7)
- (modified) clang/test/CIR/CodeGen/statement-exprs.c (-2)
- (modified) clang/test/CIR/CodeGen/switch-cleanup.cpp (+1-4)
- (modified) clang/test/CIR/CodeGen/switch-pre-case-stmts.cpp (+3-17)
- (modified) clang/test/CIR/CodeGen/switch.cpp (-84)
- (modified) clang/test/CIR/CodeGen/ternary-throw.cpp (+8-16)
- (modified) clang/test/CIR/CodeGen/ternary.cpp (+1-3)
- (modified) clang/test/CIR/CodeGen/three-way-cmp.cpp (-3)
- (modified) clang/test/CIR/CodeGen/throws.cpp (+1-3)
- (modified) clang/test/CIR/CodeGen/try-catch.cpp (+33-141)
- (modified) clang/test/CIR/CodeGen/virtual-fn-calls-eh.cpp (-2)
- (modified) clang/test/CIR/CodeGen/vla.c (-6)
- (modified) clang/test/CIR/CodeGenBuiltins/builtin-bcopy.cpp (+2-2)
- (modified) clang/test/CIR/CodeGenOpenMP/omp-llvmir.c (-3)
- (modified) clang/test/CIR/CodeGenSYCL/address-space-deduction.cpp (-2)
- (modified) clang/test/CIR/Lowering/func-simple.cpp (-4)
- (modified) clang/test/CIR/Lowering/goto.cir (+1-5)
- (modified) clang/test/CIR/Lowering/switch.cir (+2-10)
- (added) clang/test/CIR/Transforms/fold-empty-branches.cir (+168)
- (modified) clang/tools/cir-opt/cir-opt.cpp (+3)
``````````diff
diff --git a/clang/include/clang/CIR/Dialect/Passes.h b/clang/include/clang/CIR/Dialect/Passes.h
index 117822486cc3a2..7c09a42bed949f 100644
--- a/clang/include/clang/CIR/Dialect/Passes.h
+++ b/clang/include/clang/CIR/Dialect/Passes.h
@@ -26,6 +26,7 @@ enum class CallConvTarget { None, Test, X86_64, AMDGPU };
namespace mlir {
std::unique_ptr<Pass> createCIRCanonicalizePass();
+std::unique_ptr<Pass> createCIRFoldEmptyBranchesPass();
std::unique_ptr<Pass> createCIRFlattenCFGPass();
std::unique_ptr<Pass> createCIRSimplifyPass();
std::unique_ptr<Pass> createCIREHABILoweringPass();
diff --git a/clang/include/clang/CIR/Dialect/Passes.td b/clang/include/clang/CIR/Dialect/Passes.td
index a5335ab3606dd6..787a9d8f29b899 100644
--- a/clang/include/clang/CIR/Dialect/Passes.td
+++ b/clang/include/clang/CIR/Dialect/Passes.td
@@ -29,6 +29,22 @@ def CIRCanonicalize : Pass<"cir-canonicalize"> {
let dependentDialects = ["cir::CIRDialect"];
}
+def CIRFoldEmptyBranches : Pass<"cir-fold-empty-branches"> {
+ let summary = "Removes blocks that contain only an unconditional branch";
+ let description = [{
+ Removes every non-entry block that has no arguments, contains only a
+ `cir.br`, and is the only predecessor of the `cir.br` destination. Each
+ predecessor of such a block branches directly to the `cir.br`
+ destination, passing the operands the `cir.br` passed.
+
+ A `cir.br` with a `loop_id` is never removed, so loop metadata is
+ preserved. No operations other than `cir.br` are erased.
+ }];
+
+ let constructor = "mlir::createCIRFoldEmptyBranchesPass()";
+ let dependentDialects = ["cir::CIRDialect"];
+}
+
def CIRSimplify : Pass<"cir-simplify"> {
let summary = "Performs CIR simplification and code optimization";
let description = [{
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRFoldEmptyBranches.cpp b/clang/lib/CIR/Dialect/Transforms/CIRFoldEmptyBranches.cpp
new file mode 100644
index 00000000000000..4b5136a95d0147
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/CIRFoldEmptyBranches.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a pass that removes blocks containing only an
+// unconditional branch to a block that has no other predecessor, redirecting
+// their predecessors to the branch target.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PassDetail.h"
+#include "mlir/IR/Block.h"
+#include "mlir/IR/Region.h"
+#include "mlir/Interfaces/ControlFlowInterfaces.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace mlir;
+using namespace cir;
+
+namespace mlir {
+#define GEN_PASS_DEF_CIRFOLDEMPTYBRANCHES
+#include "clang/CIR/Dialect/Passes.h.inc"
+} // namespace mlir
+
+namespace {
+
+struct CIRFoldEmptyBranchesPass
+ : public impl::CIRFoldEmptyBranchesBase<CIRFoldEmptyBranchesPass> {
+ using CIRFoldEmptyBranchesBase::CIRFoldEmptyBranchesBase;
+
+ void runOnOperation() override;
+};
+
+/// Erase `block` if it is a non-entry block with no arguments whose only
+/// operation is a `cir.br` to another block, and `block` is the only
+/// predecessor of that block. A `cir.br` with a loop id is a loop back edge
+/// that carries the loop's metadata, so it is kept. Every predecessor
+/// terminator must implement BranchOpInterface so the `cir.br` operands can be
+/// forwarded.
+static bool foldEmptyBranch(Block &block) {
+ if (block.isEntryBlock() || block.getNumArguments() != 0 ||
+ !llvm::hasSingleElement(block))
+ return false;
+
+ auto br = dyn_cast<cir::BrOp>(block.front());
+ if (!br || br.getDest() == &block || br.getLoopIdAttr())
+ return false;
+
+ Block *dest = br.getDest();
+ if (dest->getSinglePredecessor() != &block)
+ return false;
+
+ for (Block *pred : block.getPredecessors())
+ if (!isa<BranchOpInterface>(pred->getTerminator()))
+ return false;
+
+ SmallVector<Value> operands(br.getDestOperands());
+ for (BlockOperand &use : llvm::make_early_inc_range(block.getUses())) {
+ auto branch = cast<BranchOpInterface>(use.getOwner());
+ unsigned index = use.getOperandNumber();
+ branch.getSuccessorOperands(index).append(operands);
+ branch->setSuccessor(dest, index);
+ }
+ block.erase();
+ return true;
+}
+
+void CIRFoldEmptyBranchesPass::runOnOperation() {
+ getOperation()->walk([](Region *region) {
+ bool changed;
+ do {
+ changed = false;
+ for (Block &block : llvm::make_early_inc_range(*region))
+ changed |= foldEmptyBranch(block);
+ } while (changed);
+ });
+}
+
+} // namespace
+
+std::unique_ptr<Pass> mlir::createCIRFoldEmptyBranchesPass() {
+ return std::make_unique<CIRFoldEmptyBranchesPass>();
+}
diff --git a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
index 5f19c41bd1c37d..c379da7d64794c 100644
--- a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
@@ -3,6 +3,7 @@ add_subdirectory(TargetLowering)
add_clang_library(MLIRCIRTransforms
CallConvLoweringPass.cpp
CIRCanonicalize.cpp
+ CIRFoldEmptyBranches.cpp
CIRSimplify.cpp
CIRTransformUtils.cpp
CXXABILowering.cpp
diff --git a/clang/lib/CIR/Lowering/CIRPasses.cpp b/clang/lib/CIR/Lowering/CIRPasses.cpp
index 24276411df6f9b..2b1cef44dd6c2d 100644
--- a/clang/lib/CIR/Lowering/CIRPasses.cpp
+++ b/clang/lib/CIR/Lowering/CIRPasses.cpp
@@ -162,6 +162,7 @@ void populateCIRPreLoweringPasses(OpPassManager &pm) {
pm.addPass(createCIRFlattenCFGPass());
pm.addPass(createCIREHABILoweringPass());
pm.addPass(createGotoSolverPass());
+ pm.addPass(createCIRFoldEmptyBranchesPass());
}
} // namespace mlir
diff --git a/clang/test/CIR/CodeGen/abstract-cond.c b/clang/test/CIR/CodeGen/abstract-cond.c
index 98fa2ac8dc0f4e..d9c41072d35a0b 100644
--- a/clang/test/CIR/CodeGen/abstract-cond.c
+++ b/clang/test/CIR/CodeGen/abstract-cond.c
@@ -84,8 +84,6 @@ int test_stmt_expr(int flag, struct s6 a1, struct s6 a2) {
// LLVM: %[[COND:.*]] = icmp ne i32 %[[LOAD_FLAG]], 0
// LLVM: br i1 %[[COND]], label %[[TRUE:.*]], label %[[FALSE:.*]]
// LLVM: [[TRUE]]:
-// LLVM: br label %[[STMT_BODY:.*]]
-// LLVM: [[STMT_BODY]]:
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[T:.*]], ptr align 4 {{.*}}, i64 4, i1 false)
// LLVM: call void @foo()
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[TMP:.*]], ptr align 4 %[[T]], i64 4, i1 false)
diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c
index ef246cb867208d..e1c30578523304 100644
--- a/clang/test/CIR/CodeGen/basic.c
+++ b/clang/test/CIR/CodeGen/basic.c
@@ -152,9 +152,7 @@ void f5(void) {
// LLVM: [[SCOPE]]:
// LLVM: br label %[[LOOP:.*]]
// LLVM: [[LOOP]]:
-// LLVM: br i1 true, label %[[LOOP_STEP:.*]], label %[[LOOP_EXIT:.*]]
-// LLVM: [[LOOP_STEP]]:
-// LLVM: br label %[[LOOP_BODY:.*]]
+// LLVM: br i1 true, label %[[LOOP_BODY:.*]], label %[[LOOP_EXIT:.*]]
// LLVM: [[LOOP_BODY]]:
// LLVM: br label %[[LOOP]]
// LLVM: [[LOOP_EXIT]]:
diff --git a/clang/test/CIR/CodeGen/binassign.c b/clang/test/CIR/CodeGen/binassign.c
index 13ef5b7db0555e..525980923619e4 100644
--- a/clang/test/CIR/CodeGen/binassign.c
+++ b/clang/test/CIR/CodeGen/binassign.c
@@ -169,7 +169,6 @@ int ignore_result_assign() {
// LLVM: %{{.*}} = load i32, ptr %[[RETVAL_PTR]]
// LLVM: ret i32
// LLVM: [[ELSE]]:
-// LLVM: br label
// LLVM: store i32 0, ptr %[[RETVAL_PTR]]
// LLVM: %{{.*}} = load i32, ptr %[[RETVAL_PTR]]
// LLVM: ret i32
diff --git a/clang/test/CIR/CodeGen/cleanup-automatic-eh.cpp b/clang/test/CIR/CodeGen/cleanup-automatic-eh.cpp
index 360d4f1253f23d..dd49c915cae6e3 100644
--- a/clang/test/CIR/CodeGen/cleanup-automatic-eh.cpp
+++ b/clang/test/CIR/CodeGen/cleanup-automatic-eh.cpp
@@ -37,8 +37,6 @@ void test_cleanup_with_automatic_storage_duration() {
// LLVM: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
// LLVM: [[CONT]]:
// LLVM: call void @_ZN5StrukD1Ev(
-// LLVM: br label %[[EXIT_NORMAL_CLEANUP:.*]]
-// LLVM: [[EXIT_NORMAL_CLEANUP]]:
// LLVM: br label %[[EXIT:.*]]
// LLVM: [[LPAD]]:
// LLVM: landingpad { ptr, i32 }
diff --git a/clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper-eh.cpp b/clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper-eh.cpp
index 70dd8076a1c7eb..b353ff2370a325 100644
--- a/clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper-eh.cpp
+++ b/clang/test/CIR/CodeGen/cleanup-conditional-with-wrapper-eh.cpp
@@ -101,14 +101,10 @@ Wrapper makeWrapper() {
// LLVM: [[CONSTRUCT_DONE]]:
// LLVM: %[[CLEANUP_FLAG:.*]] = load i8, ptr %[[CLEANUP_COND]]
// LLVM: %[[SHOULD_CLEANUP:.*]] = trunc i8 %[[CLEANUP_FLAG]] to i1
-// LLVM: br i1 %[[SHOULD_CLEANUP]], label %[[NORMAL_CLEANUP:.*]], label %[[CLEANUP_DONE:.*]]
+// LLVM: br i1 %[[SHOULD_CLEANUP]], label %[[NORMAL_CLEANUP:.*]], label %[[DONE:.*]]
// LLVM: [[NORMAL_CLEANUP]]:
// LLVM: call void @_ZNSt10unique_ptrI4BaseED1Ev(ptr {{.*}} %[[AGG_TMP0]])
-// LLVM: br label %[[CLEANUP_DONE]]
-// LLVM: [[CLEANUP_DONE]]:
-// LLVM: br label %[[EXIT_CLEANUP_SCOPE:.*]]
-// LLVM: [[EXIT_CLEANUP_SCOPE]]:
-// LLVM: br label %[[DONE:.*]]
+// LLVM: br label %[[DONE]]
// LLVM: [[INVOKE_CLEANUP]]:
// LLVM: landingpad { ptr, i32 }
// LLVM: cleanup
@@ -253,7 +249,6 @@ void APFixedPoint::add(int x) const {
// LLVM: br i1 %[[TF_B]], label %[[CLEANUP_T:.*]], label %[[AFTER_T:.*]]
// LLVM: [[CLEANUP_T]]:
// LLVM: call void @_ZN5APIntD1Ev(ptr {{.*}} %[[AGG_TMP]])
-// LLVM: [[AFTER_T]]:
// LLVM: [[LPAD]]:
// LLVM: landingpad { ptr, i32 }
// LLVM: cleanup
@@ -268,6 +263,7 @@ void APFixedPoint::add(int x) const {
// LLVM: br i1 %[[TF_EH_B]], label %[[EH_CLEANUP_T:.*]], label %[[EH_AFTER_T:.*]]
// LLVM: [[EH_CLEANUP_T]]:
// LLVM: call void @_ZN5APIntD1Ev(ptr {{.*}} %[[AGG_TMP]])
+// LLVM: [[AFTER_T]]:
// LLVM: [[EH_AFTER_T]]:
// LLVM: call void @_ZN5APIntD1Ev(ptr {{.*}} %[[THISVAL]])
// LLVM: resume
diff --git a/clang/test/CIR/CodeGen/cleanup-conditional.cpp b/clang/test/CIR/CodeGen/cleanup-conditional.cpp
index b9df861d17e4f3..65bd49a2fdbb78 100644
--- a/clang/test/CIR/CodeGen/cleanup-conditional.cpp
+++ b/clang/test/CIR/CodeGen/cleanup-conditional.cpp
@@ -74,8 +74,6 @@ void test_ternary_temporary(bool c, int x) {
// LLVMCIR: call void @_ZN1SD1Ev(ptr {{.*}} %[[TMP]])
// LLVMCIR: br label %[[SKIP_DTOR]]
// LLVMCIR: [[SKIP_DTOR]]:
-// LLVMCIR: br label %[[EXIT:.*]]
-// LLVMCIR: [[EXIT]]:
// LLVMCIR: %[[RESULT:.*]] = load i32, ptr %[[RESULT_TMP]]
// LLVMCIR: store i32 %[[RESULT]], ptr %{{.*}}
@@ -200,7 +198,6 @@ void test_ternary_both_branches(bool c) {
// LLVMCIR: call void @_ZN1AD1Ev({{.*}} %[[TMPA]])
// LLVMCIR: br label %[[SKIP_DTOR_A]]
// LLVMCIR: [[SKIP_DTOR_A]]:
-// LLVMCIR: br label %{{.*}}
// OGCG-LABEL: define dso_local void @_Z26test_ternary_both_branchesb(
// OGCG: [[ENTRY:.*]]:
@@ -321,8 +318,6 @@ int test_return_ternary(bool c) {
// LLVMCIR: call void @_ZN1AD1Ev({{.*}} %[[TMPA]])
// LLVMCIR: br label %[[SKIP_DTOR_A]]
// LLVMCIR: [[SKIP_DTOR_A]]:
-// LLVMCIR: br label %[[EXIT:.*]]
-// LLVMCIR: [[EXIT]]:
// LLVMCIR: %[[RET:.*]] = load i32, ptr %[[RETVAL]]
// LLVMCIR: ret i32 %[[RET]]
diff --git a/clang/test/CIR/CodeGen/cleanup-scope-goto-out.cpp b/clang/test/CIR/CodeGen/cleanup-scope-goto-out.cpp
index 76ac8e4d38c607..bd7053fcccc5f7 100644
--- a/clang/test/CIR/CodeGen/cleanup-scope-goto-out.cpp
+++ b/clang/test/CIR/CodeGen/cleanup-scope-goto-out.cpp
@@ -42,8 +42,6 @@ end:;
// LLVM: %[[A_ADDR:.*]] = alloca %struct.StructWithDestructor
// LLVM: br i1 %{{.*}}, label %[[IF_THEN:.*]], label %[[IF_END:.*]]
// LLVM: [[IF_THEN]]:
-// LLVM: br label %[[BODY:.*]]
-// LLVM: [[BODY]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[A_ADDR]])
// LLVM: br label %[[CLEANUP:.*]]
// LLVM: [[CLEANUP]]:
@@ -108,8 +106,6 @@ end:;
// LLVM: store i32 1, ptr %{{.*}}
// LLVM: br label %[[CLEANUP:.*]]
// LLVM: [[NORMAL_PATH]]:
-// LLVM: br label %[[FALL:.*]]
-// LLVM: [[FALL]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[A_ADDR]])
// LLVM: store i32 0, ptr %{{.*}}
// LLVM: br label %[[CLEANUP]]
@@ -194,8 +190,6 @@ void test_goto_inner_to_outer(bool cond) {
// LLVM: store i32 1, ptr %{{.*}}
// LLVM: br label %[[INNER_CLEANUP:.*]]
// LLVM: [[NORMAL_PATH]]:
-// LLVM: br label %[[USE_INNER:.*]]
-// LLVM: [[USE_INNER]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[INNER_ADDR:.*]])
// LLVM: store i32 0, ptr %{{.*}}
// LLVM: br label %[[INNER_CLEANUP]]
@@ -205,10 +199,10 @@ void test_goto_inner_to_outer(bool cond) {
// LLVM: i32 0, label %[[FALL_DEST:.*]]
// LLVM: i32 1, label %[[GOTO_DEST:.*]]
// LLVM: ]
-// LLVM: [[FALL_DEST]]:
-// LLVM: br label %{{.*}}
// LLVM: [[GOTO_DEST]]:
// LLVM: br label %[[USE_OUTER:.*]]
+// LLVM: [[FALL_DEST]]:
+// LLVM: br label %{{.*}}
// LLVM: [[USE_OUTER]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[OUTER_ADDR:.*]])
// LLVM: br label %[[OUTER_DTOR_BB:.*]]
@@ -293,19 +287,15 @@ end:;
// LLVM: store i32 1, ptr %{{.*}}
// LLVM: br label %[[INNER_CLEANUP:.*]]
// LLVM: [[NORMAL_PATH]]:
-// LLVM: br label %[[USE_INNER:.*]]
-// LLVM: [[USE_INNER]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[INNER_ADDR]])
// LLVM: store i32 0, ptr %{{.*}}
// LLVM: br label %[[INNER_CLEANUP]]
// LLVM: [[INNER_CLEANUP]]:
// LLVM: call void @_ZN20StructWithDestructorD1Ev(ptr {{.*}} %[[INNER_ADDR]])
// LLVM: switch i32 %{{.*}}, label %[[INNER_DEFAULT:.*]] [
-// LLVM: i32 0, label %[[INNER_FALL:.*]]
+// LLVM: i32 0, label %[[USE_OUTER:.*]]
// LLVM: i32 1, label %[[INNER_GOTO:.*]]
// LLVM: ]
-// LLVM: [[INNER_FALL]]:
-// LLVM: br label %[[USE_OUTER:.*]]
// LLVM: [[INNER_GOTO]]:
// LLVM: store i32 1, ptr %{{.*}}
// LLVM: br label %[[OUTER_CLEANUP:.*]]
diff --git a/clang/test/CIR/CodeGen/cleanup-scope-goto-within.cpp b/clang/test/CIR/CodeGen/cleanup-scope-goto-within.cpp
index 2d6a3223883b92..6a9c384c3786fc 100644
--- a/clang/test/CIR/CodeGen/cleanup-scope-goto-within.cpp
+++ b/clang/test/CIR/CodeGen/cleanup-scope-goto-within.cpp
@@ -49,8 +49,6 @@ void test_goto_within_cleanup(bool cond) {
// LLVM: [[GOTO_BB]]:
// LLVM: br label %[[LABEL_BB:[0-9]+]]
// LLVM: [[FALLTHROUGH]]:
-// LLVM: br label %[[USE_BB:.*]]
-// LLVM: [[USE_BB]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[A_ADDR]])
// LLVM: br label %[[LABEL_BB]]
// LLVM: [[LABEL_BB]]:
@@ -121,21 +119,17 @@ void test_goto_jump_into_nested_op(bool cond1, bool cond2) {
// LLVM: [[GOTO_BB]]:
// LLVM: br label %[[SKIP_BB:[0-9]+]]
// LLVM: [[FALLTHROUGH]]:
-// LLVM: br label %[[USE_BB:.*]]
-// LLVM: [[USE_BB]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[A_ADDR]])
// LLVM: br label %[[COND2_BB:.*]]
// LLVM: [[COND2_BB]]:
// LLVM: %[[COND2_BYTE:.*]] = load i8, ptr %[[COND2_ADDR]]
// LLVM: %[[COND2_BIT:.*]] = trunc i8 %[[COND2_BYTE]] to i1
-// LLVM: br i1 %[[COND2_BIT]], label %[[GOTO_BB2:.*]], label %[[MERGE:.*]]
+// LLVM: br i1 %[[COND2_BIT]], label %[[GOTO_BB2:.*]], label %[[CLEANUP:.*]]
// LLVM: [[GOTO_BB2]]:
// LLVM: br label %[[SKIP_BB]]
// LLVM: [[SKIP_BB]]:
// LLVM: call void @_Z3useR20StructWithDestructor(ptr {{.*}} %[[A_ADDR]])
-// LLVM: br label %[[MERGE]]
-// LLVM: [[MERGE]]:
-// LLVM: br label %[[CLEANUP:.*]]
+// LLVM: br label %[[CLEANUP]]
// LLVM: [[CLEANUP]]:
// LLVM: call void @_ZN20StructWithDestructorD1Ev(ptr {{.*}} %[[A_ADDR]])
// LLVM-NOT: call void @_ZN20StructWithDestructorD1Ev
diff --git a/clang/test/CIR/CodeGen/delete.cpp b/clang/test/CIR/CodeGen/delete.cpp
index b78a869d66bc74..f4c9e2833591c2 100644
--- a/clang/test/CIR/CodeGen/delete.cpp
+++ b/clang/test/CIR/CodeGen/delete.cpp
@@ -35,13 +35,7 @@ void test_sized_delete(SizedDelete *x) {
// LLVM: %[[NOT_NULL:.*]] = icmp ne ptr %[[X]], null
// LLVM: br i1 %[[NOT_NULL]], label %[[DELETE_NOTNULL:.*]], label %[[DELETE_END:.*]]
// LLVM: [[DELETE_NOTNULL]]:
-// LLVM: br label %[[ENTER_CLEANUP_SCOPE:.*]]
-// LLVM: [[ENTER_CLEANUP_SCOPE]]:
-// LLVM: br label %[[NORMAL_CLEANUP:.*]]
-// LLVM: [[NORMAL_CLEANUP]]:
// LLVM: call void @_ZN11SizedDeletedlEPvm(ptr noundef %[[X]], i64 noundef 4)
-// LLVM: br label %[[EXIT_CLEANUP:.*]]
-// LLVM: [[EXIT_CLEANUP]]:
// LLVM: br label %[[EXIT_CLEANUP_SCOPE:.*]]
// LLVM: [[EXIT_CLEANUP_SCOPE]]:
// LLVM: br label %[[DELETE_END]]
@@ -95,14 +89,10 @@ Container::~Container() { delete contents; }
// LLVM: %[[NOT_NULL:.*]] = icmp ne ptr %[[CONTENTS_PTR]], null
// LLVM: br i1 %[[NOT_NULL]], label %[[DELETE_NOTNULL:.*]], label %[[DELETE_END:.*]]
// LLVM: [[DELETE_NOTNULL]]:
-// LLVM: br label %[[ENTER_CLEANUP_SCOPE:.*]]
-// LLVM: [[ENTER_CLEANUP_SCOPE]]:
// LLVM: call void @_ZN8ContentsD2Ev(ptr noundef nonnull align 1 dereferenceable(1) %[[CONTENTS_PTR]])
// LLVM: br label %[[NORMAL_CLEANUP:.*]]
// LLVM: [[NORMAL_CLEANUP]]:
// LLVM: call void @_ZdlPvm(ptr noundef %[[CONTENTS_PTR]], i64 noundef 1)
-// LLVM: br label %[[EXIT_CLEANUP:.*]]
-// LLVM: [[EXIT_CLEANUP]]:
// LLVM: br label %[[EXIT_CLEANUP_SCOPE:.*]]
// LLVM: [[EXIT_CLEANUP_SCOPE]]:
// LLVM: br label %[[DELETE_END]]
diff --git a/clang/test/CIR/CodeGen/dtors.cpp b/clang/test/CIR/CodeGen/dtors.cpp
index 7402be349cbd36..d34dd5a56764a3 100644
--- a/clang/test/CIR/CodeGen/dtors.cpp
+++ b/clang/test/CIR/CodeGen/dtors.cpp
@@ -379,15 +379,9 @@ int test_temp_in_condition(G &obj) {
// LLVM: br label %[[CLEAN_SCOPE_TWO_CLEANUP:.*]]
// LLVM: [[CLEAN_SCOPE_TWO_CLEANUP]]:
// LLVM: call void @_ZN1GD1Ev(ptr {{.*}} %[[REF_TMP1]])
-// LLVM: br label %[[EXIT_CLEAN_SCOPE_TWO:.*]]
-// LLVM: [[EXIT_CLEAN_SCOPE_TWO]]:
-// LLVM: br label %[[CLEAN_SCOPE_ONE_CONTINUE:.*]]
-// LLVM: [[CLEAN_SCOPE_ONE_CONTINUE]]:
// LLVM: br label %[[CLEAN_SCOPE_ONE_CLEANUP:.*]]
// LLVM: [[CLEAN_SCOPE_ONE_CLEANUP]]:
// LLVM: call void @_ZN1GD1Ev(ptr {{.*}} %[[REF_TMP0]])
-// LLVM: br label %[[EXIT_CLEAN_SCOPE_ONE:.*]]
-// LLVM: [[EXIT_CLEAN_SCOPE_ONE]]:
// LLVM: br label %[[SCOPE_CONTINUE:.*]]
// LLVM: [[SCOPE_CONTINUE]]:
// LLVM: %[[LOAD_RESULT:.*]] = load i8, ptr %[[TMP_RESULT]]
@@ -398,8 +392,6 @@ int test_temp_in_condition(G &obj) {
// LLVM: %[[RETVAL:.*]] = load i32, ptr %[[RET_ADDR]]
// LLVM: ret i32 %[[RETVAL]]
// LLVM: [[FALSE_BLOCK]]:
-// LLVM: br label %[[EXIT_SCOPE:.*]]
-// LLVM: [[EXIT_SCOPE]]:
// LLVM: store i32 0, ptr %[[RET_ADDR]]
// LLVM: %[[RETVAL:.*]] = load i32, ptr %[[RET_ADDR]]
// LLVM: ret i32 %[[RETVAL]]
diff --git a/clang/test/CIR/CodeGen/ehspec-noexcept.cpp b/clang/test/CIR/CodeGen/ehspec-noexcept.cpp
index 8bbd67d2dbd50f..ea9b2e5da85510 100644
--- a/clang/test/CIR/CodeGen/ehspec-noexcept.cpp
+++ b/clang/test/CIR/CodeGen/ehspec-noexcept.cpp
@@ -160,32 +160,22 @@ void outer() noexcept {
// LLVM: br label %[[TRY_CONT]]
// The pipelines lay the join and the terminate handler out in opposite orders,
-// and the CIR pipeline reaches each of them through a chain of empty
-// forwarding blocks, so these checks follow the branches. Interleaving the two
-// chains is what the layout requires, not what the control flow does.
+// and the CIR pipeline reaches the terminate handler through a chain of
+// forwar...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/239417
More information about the cfe-commits
mailing list