[llvm] 08860f5 - [Local] Allow creating callbr with duplicate successors
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 05:34:51 PDT 2022
Author: Nikita Popov
Date: 2022-07-19T14:28:22+02:00
New Revision: 08860f525a2363ccd697ebb3ff59769e37b1be21
URL: https://github.com/llvm/llvm-project/commit/08860f525a2363ccd697ebb3ff59769e37b1be21
DIFF: https://github.com/llvm/llvm-project/commit/08860f525a2363ccd697ebb3ff59769e37b1be21.diff
LOG: [Local] Allow creating callbr with duplicate successors
Since D129288, callbr is allowed to have duplicate successors. This
patch removes a limitation which prevents optimizations from actually
producing such callbrs.
Differential Revision: https://reviews.llvm.org/D129997
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
llvm/test/Transforms/SimplifyCFG/jump-threading.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index b203259db1c68..fbae54735e70f 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1089,18 +1089,6 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
}
}
- // We cannot fold the block if it's a branch to an already present callbr
- // successor because that creates duplicate successors.
- for (BasicBlock *PredBB : predecessors(BB)) {
- if (auto *CBI = dyn_cast<CallBrInst>(PredBB->getTerminator())) {
- if (Succ == CBI->getDefaultDest())
- return false;
- for (unsigned i = 0, e = CBI->getNumIndirectDests(); i != e; ++i)
- if (Succ == CBI->getIndirectDest(i))
- return false;
- }
- }
-
LLVM_DEBUG(dbgs() << "Killing Trivial BB: \n" << *BB);
SmallVector<DominatorTree::UpdateType, 32> Updates;
diff --git a/llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll b/llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
index 5105c34513a9b..e47fafd949733 100644
--- a/llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
+++ b/llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
@@ -74,7 +74,6 @@ define hidden i32 @test2() local_unnamed_addr {
; CHECK-LABEL: <$x.10>:
; CHECK-NEXT: b {{.*}} <test3+0x18>
; CHECK-LABEL: <$x.12>:
-; CHECK-NEXT: mov w0, wzr
; CHECK-NEXT: ldr x30, [sp], #16
; CHECK-NEXT: ret
define internal i1 @test3() {
diff --git a/llvm/test/Transforms/JumpThreading/callbr-edge-split.ll b/llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
index 7d1cb4ca05feb..d96f5cff63dc4 100644
--- a/llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
+++ b/llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
@@ -13,9 +13,7 @@ define i32 @c() {
; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_ELSE:%.*]], label [[IF_END:%.*]]
; CHECK: if.else:
; CHECK-NEXT: callbr void asm sideeffect "", "!i"()
-; CHECK-NEXT: to label [[NORMAL:%.*]] [label %if.then2]
-; CHECK: normal:
-; CHECK-NEXT: br label [[IF_THEN2:%.*]]
+; CHECK-NEXT: to label [[IF_THEN2:%.*]] [label %if.then2]
; CHECK: if.end:
; CHECK-NEXT: [[CALL:%.*]] = call i32 @b()
; CHECK-NEXT: [[PHITMP:%.*]] = icmp ne i32 [[CALL]], 0
diff --git a/llvm/test/Transforms/JumpThreading/pr46857-callbr.ll b/llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
index a5ccde0d540bc..f1d062925161e 100644
--- a/llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
+++ b/llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
@@ -1,17 +1,13 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -jump-threading -S | FileCheck %s
-; CHECK-ALL-LABEL: @func(
-
define i1 @func(i1 %arg, i32 %arg1, i1 %arg2) {
; CHECK-LABEL: @func(
; CHECK-NEXT: bb:
; CHECK-NEXT: br i1 [[ARG:%.*]], label [[BB7:%.*]], label [[BB4:%.*]]
; CHECK: bb4:
; CHECK-NEXT: callbr void asm sideeffect "", "!i"()
-; CHECK-NEXT: to label [[BB5:%.*]] [label %bb7.thr_comm]
-; CHECK: bb5:
-; CHECK-NEXT: br label [[BB7_THR_COMM:%.*]]
+; CHECK-NEXT: to label [[BB7_THR_COMM:%.*]] [label %bb7.thr_comm]
; CHECK: bb7.thr_comm:
; CHECK-NEXT: [[I91:%.*]] = xor i1 [[ARG2:%.*]], [[ARG]]
; CHECK-NEXT: br i1 [[I91]], label [[BB11:%.*]], label [[BB11]]
diff --git a/llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll b/llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
index 368bc5e9331f7..008aa5c44d951 100644
--- a/llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
+++ b/llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
@@ -17,16 +17,13 @@ bb:
ret void
}
-; TODO: Can fold to a duplicate callbr destination.
define void @callbr_can_fold_to_duplicate_dest1() {
; CHECK-LABEL: @callbr_can_fold_to_duplicate_dest1(
; CHECK-NEXT: entry:
; CHECK-NEXT: callbr void asm sideeffect "", "!i"()
-; CHECK-NEXT: to label [[BB2:%.*]] [label %common.ret]
+; CHECK-NEXT: to label [[COMMON_RET:%.*]] [label %common.ret]
; CHECK: common.ret:
; CHECK-NEXT: ret void
-; CHECK: bb2:
-; CHECK-NEXT: br label [[COMMON_RET:%.*]]
;
entry:
callbr void asm sideeffect "", "!i"()
@@ -39,18 +36,13 @@ bb2:
ret void
}
-; TODO: Can fold to a duplicate callbr destination.
define void @callbr_can_fold_to_duplicate_dest2() {
; CHECK-LABEL: @callbr_can_fold_to_duplicate_dest2(
; CHECK-NEXT: entry:
; CHECK-NEXT: callbr void asm sideeffect "", "!i,!i"()
-; CHECK-NEXT: to label [[COMMON_RET:%.*]] [label [[BB2:%.*]], label %bb3]
+; CHECK-NEXT: to label [[COMMON_RET:%.*]] [label [[COMMON_RET]], label %common.ret]
; CHECK: common.ret:
; CHECK-NEXT: ret void
-; CHECK: bb2:
-; CHECK-NEXT: br label [[COMMON_RET]]
-; CHECK: bb3:
-; CHECK-NEXT: br label [[COMMON_RET]]
;
entry:
callbr void asm sideeffect "", "!i,!i"()
diff --git a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
index e7d7662fd3ccc..96befcce7054d 100644
--- a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
+++ b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
@@ -425,9 +425,7 @@ define void @callbr() {
; CHECK-LABEL: @callbr(
; CHECK-NEXT: entry:
; CHECK-NEXT: callbr void asm sideeffect "", "!i,~{dirflag},~{fpsr},~{flags}"()
-; CHECK-NEXT: to label [[IF_END:%.*]] [label %target]
-; CHECK: target:
-; CHECK-NEXT: br label [[IF_END]]
+; CHECK-NEXT: to label [[IF_END:%.*]] [label %if.end]
; CHECK: if.end:
; CHECK-NEXT: ret void
;
More information about the llvm-commits
mailing list