[llvm] [SimplifyCFG] Simplify nested branches (PR #97067)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 30 09:04:22 PDT 2024


================
@@ -0,0 +1,306 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
+
+define void @fold_nested_branch(i1 %cond1, i1 %cond2) {
+; CHECK-LABEL: define void @fold_nested_branch(
+; CHECK-SAME: i1 [[COND1:%.*]], i1 [[COND2:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = xor i1 [[COND1]], [[COND2]]
+; CHECK-NEXT:    br i1 [[TMP0]], label %[[BB4:.*]], label %[[BB3:.*]]
+; CHECK:       [[COMMON_RET:.*]]:
+; CHECK-NEXT:    ret void
+; CHECK:       [[BB3]]:
+; CHECK-NEXT:    call void @sideeffect1()
+; CHECK-NEXT:    br label %[[COMMON_RET]]
+; CHECK:       [[BB4]]:
+; CHECK-NEXT:    call void @sideeffect2()
+; CHECK-NEXT:    br label %[[COMMON_RET]]
+;
+entry:
+  br i1 %cond1, label %bb1, label %bb2
+
+bb1:
+  br i1 %cond2, label %bb3, label %bb4
+
+bb2:
+  br i1 %cond2, label %bb4, label %bb3
+
+bb3:
+  call void @sideeffect1()
+  ret void
+
+bb4:
+  call void @sideeffect2()
+  ret void
+}
----------------
nikic wrote:

Can you please add a test where bb1/bb2 also have an additional predecessor (but without forming a loop)?

https://github.com/llvm/llvm-project/pull/97067


More information about the llvm-commits mailing list