mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Make FoldBranchToCommonDest poison-safe by default
This is a small patch to make FoldBranchToCommonDest poison-safe by default. After fc3f0c9c, only two syntactic changes are needed to fix unit tests. This does not cause any assembly difference in testsuite as well (-O3, X86-64 Manjaro). Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D99452
This commit is contained in:
parent
64dc4c67c5
commit
c9eefe2dea
@ -186,15 +186,10 @@ bool FlattenCFG(BasicBlock *BB, AAResults *AA = nullptr);
|
|||||||
/// If this basic block is ONLY a setcc and a branch, and if a predecessor
|
/// If this basic block is ONLY a setcc and a branch, and if a predecessor
|
||||||
/// branches to us and one of our successors, fold the setcc into the
|
/// branches to us and one of our successors, fold the setcc into the
|
||||||
/// predecessor and use logical operations to pick the right destination.
|
/// predecessor and use logical operations to pick the right destination.
|
||||||
/// If PoisonSafe is true, use select i1 rather than and/or i1 to successfully
|
|
||||||
/// block unexpected propagation of poison when merging the branches. This is
|
|
||||||
/// set to false by default when used by LoopSimplify for performance, but this
|
|
||||||
/// should be turned on by default.
|
|
||||||
bool FoldBranchToCommonDest(BranchInst *BI, llvm::DomTreeUpdater *DTU = nullptr,
|
bool FoldBranchToCommonDest(BranchInst *BI, llvm::DomTreeUpdater *DTU = nullptr,
|
||||||
MemorySSAUpdater *MSSAU = nullptr,
|
MemorySSAUpdater *MSSAU = nullptr,
|
||||||
const TargetTransformInfo *TTI = nullptr,
|
const TargetTransformInfo *TTI = nullptr,
|
||||||
unsigned BonusInstThreshold = 1,
|
unsigned BonusInstThreshold = 1);
|
||||||
bool PoisonSafe = false);
|
|
||||||
|
|
||||||
/// This function takes a virtual register computed by an Instruction and
|
/// This function takes a virtual register computed by an Instruction and
|
||||||
/// replaces it with a slot in the stack frame, allocated via alloca.
|
/// replaces it with a slot in the stack frame, allocated via alloca.
|
||||||
|
@ -2902,7 +2902,6 @@ shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
|
|||||||
static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
|
static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
|
||||||
DomTreeUpdater *DTU,
|
DomTreeUpdater *DTU,
|
||||||
MemorySSAUpdater *MSSAU,
|
MemorySSAUpdater *MSSAU,
|
||||||
bool PoisonSafe,
|
|
||||||
const TargetTransformInfo *TTI) {
|
const TargetTransformInfo *TTI) {
|
||||||
BasicBlock *BB = BI->getParent();
|
BasicBlock *BB = BI->getParent();
|
||||||
BasicBlock *PredBlock = PBI->getParent();
|
BasicBlock *PredBlock = PBI->getParent();
|
||||||
@ -3004,9 +3003,8 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
|
|||||||
// or/and the two conditions together.
|
// or/and the two conditions together.
|
||||||
Value *NewCond = nullptr;
|
Value *NewCond = nullptr;
|
||||||
Value *BICond = VMap[BI->getCondition()];
|
Value *BICond = VMap[BI->getCondition()];
|
||||||
bool UseBinOp = !PoisonSafe || impliesPoison(BICond, PBI->getCondition());
|
|
||||||
|
|
||||||
if (UseBinOp)
|
if (impliesPoison(BICond, PBI->getCondition()))
|
||||||
NewCond = Builder.CreateBinOp(Opc, PBI->getCondition(), BICond, "or.cond");
|
NewCond = Builder.CreateBinOp(Opc, PBI->getCondition(), BICond, "or.cond");
|
||||||
else
|
else
|
||||||
NewCond =
|
NewCond =
|
||||||
@ -3035,8 +3033,7 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
|
|||||||
bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
|
bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
|
||||||
MemorySSAUpdater *MSSAU,
|
MemorySSAUpdater *MSSAU,
|
||||||
const TargetTransformInfo *TTI,
|
const TargetTransformInfo *TTI,
|
||||||
unsigned BonusInstThreshold,
|
unsigned BonusInstThreshold) {
|
||||||
bool PoisonSafe) {
|
|
||||||
// If this block ends with an unconditional branch,
|
// If this block ends with an unconditional branch,
|
||||||
// let SpeculativelyExecuteBB() deal with it.
|
// let SpeculativelyExecuteBB() deal with it.
|
||||||
if (!BI->isConditional())
|
if (!BI->isConditional())
|
||||||
@ -3140,8 +3137,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
|
|||||||
// Ok, we have the budget. Perform the transformation.
|
// Ok, we have the budget. Perform the transformation.
|
||||||
for (BasicBlock *PredBlock : Preds) {
|
for (BasicBlock *PredBlock : Preds) {
|
||||||
auto *PBI = cast<BranchInst>(PredBlock->getTerminator());
|
auto *PBI = cast<BranchInst>(PredBlock->getTerminator());
|
||||||
return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, PoisonSafe,
|
return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, TTI);
|
||||||
TTI);
|
|
||||||
}
|
}
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
@ -6360,7 +6356,7 @@ bool SimplifyCFGOpt::simplifyUncondBranch(BranchInst *BI,
|
|||||||
// predecessor and use logical operations to update the incoming value
|
// predecessor and use logical operations to update the incoming value
|
||||||
// for PHI nodes in common successor.
|
// for PHI nodes in common successor.
|
||||||
if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
|
if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
|
||||||
Options.BonusInstThreshold, true))
|
Options.BonusInstThreshold))
|
||||||
return requestResimplify();
|
return requestResimplify();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -6424,7 +6420,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
|
|||||||
// branches to us and one of our successors, fold the comparison into the
|
// branches to us and one of our successors, fold the comparison into the
|
||||||
// predecessor and use logical operations to pick the right destination.
|
// predecessor and use logical operations to pick the right destination.
|
||||||
if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
|
if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
|
||||||
Options.BonusInstThreshold, true))
|
Options.BonusInstThreshold))
|
||||||
return requestResimplify();
|
return requestResimplify();
|
||||||
|
|
||||||
// We have a conditional branch to two blocks that are only reachable
|
// We have a conditional branch to two blocks that are only reachable
|
||||||
|
@ -98,7 +98,7 @@ define void @test_03(i64* %p1, i64* %p2, i1 %maybe_exit) {
|
|||||||
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %guarded ], [ 0, %loop.preheader ]
|
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %guarded ], [ 0, %loop.preheader ]
|
||||||
; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1
|
; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1
|
||||||
; CHECK-NEXT: %rc = icmp slt i64 %iv.next, %div_result
|
; CHECK-NEXT: %rc = icmp slt i64 %iv.next, %div_result
|
||||||
; CHECK-NEXT: %or.cond = and i1 %maybe_exit, true
|
; CHECK-NEXT: %or.cond = select i1 %maybe_exit, i1 true, i1 false
|
||||||
; CHECK-NEXT: br i1 %or.cond, label %guarded, label %exit.loopexit1
|
; CHECK-NEXT: br i1 %or.cond, label %guarded, label %exit.loopexit1
|
||||||
; CHECK: guarded:
|
; CHECK: guarded:
|
||||||
; CHECK-NEXT: %gep = getelementptr i64, i64* %p1, i64 %iv.next
|
; CHECK-NEXT: %gep = getelementptr i64, i64* %p1, i64 %iv.next
|
||||||
|
@ -7,7 +7,7 @@ target triple = "x86_64-unknown-unknown"
|
|||||||
; Check that loop-simplify merges two loop exits, but preserves LCSSA form.
|
; Check that loop-simplify merges two loop exits, but preserves LCSSA form.
|
||||||
; CHECK-LABEL: @foo
|
; CHECK-LABEL: @foo
|
||||||
; CHECK: for:
|
; CHECK: for:
|
||||||
; CHECK: %or.cond = and i1 %cmp1, %cmp2
|
; CHECK: %or.cond = select i1 %cmp1, i1 %cmp2, i1 false
|
||||||
; CHECK-NOT: for.cond:
|
; CHECK-NOT: for.cond:
|
||||||
; CHECK: for.end:
|
; CHECK: for.end:
|
||||||
; CHECK: %a.lcssa = phi i32 [ %a, %for ]
|
; CHECK: %a.lcssa = phi i32 [ %a, %for ]
|
||||||
|
Loading…
Reference in New Issue
Block a user