[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
This commit is contained in:
Nikita Popov 2022-07-18 12:08:00 +02:00
parent 4539b44148
commit 08860f525a
6 changed files with 5 additions and 34 deletions

View File

@ -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;

View File

@ -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() {

View File

@ -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

View File

@ -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]]

View File

@ -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"()

View File

@ -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
;