[llvm] 1cf6b93 - Revert "[Local] Allow creating callbr with duplicate successors"
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 15:03:38 PDT 2022
Author: Nick Desaulniers
Date: 2022-07-19T15:03:27-07:00
New Revision: 1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785
URL: https://github.com/llvm/llvm-project/commit/1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785
DIFF: https://github.com/llvm/llvm-project/commit/1cf6b93df168fea81e3ca7c6c3c9fcaaf82c7785.diff
LOG: Revert "[Local] Allow creating callbr with duplicate successors"
This reverts commit 08860f525a2363ccd697ebb3ff59769e37b1be21.
Crashes during PPC64LE linux kernel builds as reported by @nathanchance.
https://reviews.llvm.org/D129997#3663632
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 fbae54735e70f..b203259db1c68 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1089,6 +1089,18 @@ 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 e47fafd949733..5105c34513a9b 100644
--- a/llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
+++ b/llvm/test/CodeGen/AArch64/callbr-asm-obj-file.ll
@@ -74,6 +74,7 @@ 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 d96f5cff63dc4..7d1cb4ca05feb 100644
--- a/llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
+++ b/llvm/test/Transforms/JumpThreading/callbr-edge-split.ll
@@ -13,7 +13,9 @@ 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 [[IF_THEN2:%.*]] [label %if.then2]
+; CHECK-NEXT: to label [[NORMAL:%.*]] [label %if.then2]
+; CHECK: normal:
+; CHECK-NEXT: br 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 f1d062925161e..a5ccde0d540bc 100644
--- a/llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
+++ b/llvm/test/Transforms/JumpThreading/pr46857-callbr.ll
@@ -1,13 +1,17 @@
; 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 [[BB7_THR_COMM:%.*]] [label %bb7.thr_comm]
+; CHECK-NEXT: to label [[BB5:%.*]] [label %bb7.thr_comm]
+; CHECK: bb5:
+; CHECK-NEXT: br 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 008aa5c44d951..368bc5e9331f7 100644
--- a/llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
+++ b/llvm/test/Transforms/SimplifyCFG/callbr-destinations.ll
@@ -17,13 +17,16 @@ 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 [[COMMON_RET:%.*]] [label %common.ret]
+; CHECK-NEXT: to label [[BB2:%.*]] [label %common.ret]
; CHECK: common.ret:
; CHECK-NEXT: ret void
+; CHECK: bb2:
+; CHECK-NEXT: br label [[COMMON_RET:%.*]]
;
entry:
callbr void asm sideeffect "", "!i"()
@@ -36,13 +39,18 @@ 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 [[COMMON_RET]], label %common.ret]
+; CHECK-NEXT: to label [[COMMON_RET:%.*]] [label [[BB2:%.*]], label %bb3]
; 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 96befcce7054d..e7d7662fd3ccc 100644
--- a/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
+++ b/llvm/test/Transforms/SimplifyCFG/jump-threading.ll
@@ -425,7 +425,9 @@ 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 %if.end]
+; CHECK-NEXT: to label [[IF_END:%.*]] [label %target]
+; CHECK: target:
+; CHECK-NEXT: br label [[IF_END]]
; CHECK: if.end:
; CHECK-NEXT: ret void
;
More information about the llvm-commits
mailing list