1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[SimplifyCFG] Teach FoldValueComparisonIntoPredecessors() to preserve DomTree, part 1

This commit is contained in:
Roman Lebedev 2020-12-31 20:13:30 +03:00
parent f63290233f
commit 110bf1321e
10 changed files with 33 additions and 17 deletions

View File

@ -1088,11 +1088,14 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
SmallSetVector<BasicBlock*, 4> FailBlocks;
if (!SafeToMergeTerminators(TI, PTI, &FailBlocks)) {
for (auto *Succ : FailBlocks) {
if (!SplitBlockPredecessors(Succ, TI->getParent(), ".fold.split"))
if (!SplitBlockPredecessors(Succ, TI->getParent(), ".fold.split",
DTU ? &DTU->getDomTree() : nullptr))
return false;
}
}
std::vector<DominatorTree::UpdateType> Updates;
// Figure out which 'cases' to copy from SI to PSI.
std::vector<ValueEqualityComparisonCase> BBCases;
BasicBlock *BBDefault = GetValueEqualityComparisonCases(TI, BBCases);
@ -1156,6 +1159,7 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
// Reconstruct the new switch statement we will be building.
if (PredDefault != BBDefault) {
PredDefault->removePredecessor(Pred);
Updates.push_back({DominatorTree::Delete, Pred, PredDefault});
PredDefault = BBDefault;
NewSuccessors.push_back(BBDefault);
}
@ -1232,8 +1236,10 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
// Okay, at this point, we know which new successor Pred will get. Make
// sure we update the number of entries in the PHI nodes for these
// successors.
for (BasicBlock *NewSuccessor : NewSuccessors)
for (BasicBlock *NewSuccessor : NewSuccessors) {
AddPredecessorToBlock(NewSuccessor, Pred, BB);
Updates.push_back({DominatorTree::Insert, Pred, NewSuccessor});
}
Builder.SetInsertPoint(PTI);
// Convert pointer to int before we switch.
@ -1272,10 +1278,20 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
InfLoopBlock = BasicBlock::Create(BB->getContext(), "infloop",
BB->getParent());
BranchInst::Create(InfLoopBlock, InfLoopBlock);
Updates.push_back(
{DominatorTree::Insert, InfLoopBlock, InfLoopBlock});
}
NewSI->setSuccessor(i, InfLoopBlock);
}
if (InfLoopBlock) {
Updates.push_back({DominatorTree::Delete, Pred, BB});
Updates.push_back({DominatorTree::Insert, Pred, InfLoopBlock});
}
if (DTU)
DTU->applyUpdatesPermissive(Updates);
Changed = true;
}
}

View File

@ -1,5 +1,5 @@
; RUN: opt < %s -gvn -simplifycfg -adce | llvm-dis
; RUN: opt < %s -gvn -simplifycfg -adce -verify-dom-info | llvm-dis
; RUN: opt < %s -gvn -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -adce | llvm-dis
; RUN: opt < %s -gvn -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -adce -verify-dom-info | llvm-dis
; This test makes sure that the DominatorTree properly handles
; deletion of edges that go to forward-unreachable regions.

View File

@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -jump-threading -simplifycfg -S < %s | FileCheck %s
; RUN: opt -jump-threading -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
declare void @ham()
define void @hoge() {

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -simplifycfg -disable-output
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -disable-output
; END.
define void @main() {

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -gvn -simplifycfg -disable-output
; RUN: opt < %s -gvn -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -disable-output
; PR867
target datalayout = "E-p:32:32"

View File

@ -1,9 +1,9 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=static < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=pic < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=ropi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
; RUN: opt -S -simplifycfg -switch-to-lookup -mtriple=arm -relocation-model=ropi-rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -switch-to-lookup -mtriple=arm -relocation-model=static < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -switch-to-lookup -mtriple=arm -relocation-model=pic < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -switch-to-lookup -mtriple=arm -relocation-model=ropi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -switch-to-lookup -mtriple=arm -relocation-model=rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -switch-to-lookup -mtriple=arm -relocation-model=ropi-rwpi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=static < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
; RUN: opt -S -passes='simplify-cfg<switch-to-lookup>' -mtriple=arm -relocation-model=pic < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -simplifycfg -S | \
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | \
; RUN: not grep "icmp eq"
; Check that simplifycfg deletes a dead 'seteq' instruction when it

View File

@ -1,6 +1,6 @@
; Test that simplifycfg can create switch instructions from constant pointers.
;
; RUN: opt < %s -simplifycfg -S | FileCheck %s
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
target datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-darwin10.0.0"

View File

@ -1,8 +1,8 @@
; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
; RUN: opt -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -o - < %s | FileCheck %s
; This test case was written to trigger an incorrect assert statement in
; -simplifycfg. Thus we don't actually want to check the output, just that
; -simplifycfg ran successfully. Thus we only check that the function still
; -simplifycfg -simplifycfg-require-and-preserve-domtree=1 ran successfully. Thus we only check that the function still
; exists, and that it still calls foo().
;
; NOTE: There are some obviously dead blocks and missing branch weight

View File

@ -1,4 +1,4 @@
; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
; RUN: opt -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -o - < %s | FileCheck %s
declare void @func2(i32)
declare void @func4(i32)