mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-28 03:25:23 +00:00
Make jump threading eliminate blocks that just contain phi nodes,
debug intrinsics, and an unconditional branch when possible. This reuses the TryToSimplifyUncondBranchFromEmptyBlock function split out of simplifycfg. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86722 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -115,6 +115,7 @@ bool JumpThreading::runOnFunction(Function &F) {
|
|||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
|
for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
|
||||||
BasicBlock *BB = I;
|
BasicBlock *BB = I;
|
||||||
|
// Thread all of the branches we can over this block.
|
||||||
while (ProcessBlock(BB))
|
while (ProcessBlock(BB))
|
||||||
Changed = true;
|
Changed = true;
|
||||||
|
|
||||||
@@ -129,6 +130,26 @@ bool JumpThreading::runOnFunction(Function &F) {
|
|||||||
LoopHeaders.erase(BB);
|
LoopHeaders.erase(BB);
|
||||||
DeleteDeadBlock(BB);
|
DeleteDeadBlock(BB);
|
||||||
Changed = true;
|
Changed = true;
|
||||||
|
} else if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
|
||||||
|
// Can't thread an unconditional jump, but if the block is "almost
|
||||||
|
// empty", we can replace uses of it with uses of the successor and make
|
||||||
|
// this dead.
|
||||||
|
if (BI->isUnconditional() &&
|
||||||
|
BB != &BB->getParent()->getEntryBlock()) {
|
||||||
|
BasicBlock::iterator BBI = BB->getFirstNonPHI();
|
||||||
|
// Ignore dbg intrinsics.
|
||||||
|
while (isa<DbgInfoIntrinsic>(BBI))
|
||||||
|
++BBI;
|
||||||
|
// If the terminator is the only non-phi instruction, try to nuke it.
|
||||||
|
if (BBI->isTerminator()) {
|
||||||
|
bool Erased = LoopHeaders.erase(BB);
|
||||||
|
|
||||||
|
if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
|
||||||
|
Changed = true;
|
||||||
|
else if (Erased)
|
||||||
|
LoopHeaders.insert(BB);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AnotherIteration = Changed;
|
AnotherIteration = Changed;
|
||||||
|
@@ -211,19 +211,29 @@ define i32 @test8b(i1 %cond, i1 %cond2) {
|
|||||||
T0:
|
T0:
|
||||||
%A = call i1 @test8a()
|
%A = call i1 @test8a()
|
||||||
br i1 %A, label %T1, label %F1
|
br i1 %A, label %T1, label %F1
|
||||||
|
|
||||||
|
; CHECK: T0:
|
||||||
|
; CHECK-NEXT: call
|
||||||
|
; CHECK-NEXT: br i1 %A, label %T1, label %Y
|
||||||
|
|
||||||
T1:
|
T1:
|
||||||
%B = call i1 @test8a()
|
%B = call i1 @test8a()
|
||||||
br i1 %B, label %T2, label %F1
|
br i1 %B, label %T2, label %F1
|
||||||
|
|
||||||
|
; CHECK: T1:
|
||||||
|
; CHECK-NEXT: call
|
||||||
|
; CHECK-NEXT: br i1 %B, label %T2, label %Y
|
||||||
T2:
|
T2:
|
||||||
%C = call i1 @test8a()
|
%C = call i1 @test8a()
|
||||||
br i1 %cond, label %T3, label %F1
|
br i1 %cond, label %T3, label %F1
|
||||||
|
|
||||||
|
; CHECK: T2:
|
||||||
|
; CHECK-NEXT: call
|
||||||
|
; CHECK-NEXT: br i1 %cond, label %T3, label %Y
|
||||||
T3:
|
T3:
|
||||||
ret i32 0
|
ret i32 0
|
||||||
|
|
||||||
F1:
|
F1:
|
||||||
; TODO: F1 uncond branch block should be removed, T2 should jump directly to Y.
|
|
||||||
; CHECK: F1:
|
|
||||||
; CHECK-NEXT br label %Y
|
|
||||||
%D = phi i32 [0, %T0], [0, %T1], [1, %T2]
|
%D = phi i32 [0, %T0], [0, %T1], [1, %T2]
|
||||||
%E = icmp eq i32 %D, 1
|
%E = icmp eq i32 %D, 1
|
||||||
%F = and i1 %E, %cond
|
%F = and i1 %E, %cond
|
||||||
|
Reference in New Issue
Block a user