/// 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
/// 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,
MemorySSAUpdater *MSSAU = nullptr,
const TargetTransformInfo *TTI = nullptr,
- unsigned BonusInstThreshold = 1,
- bool PoisonSafe = false);
+ unsigned BonusInstThreshold = 1);
/// This function takes a virtual register computed by an Instruction and
/// replaces it with a slot in the stack frame, allocated via alloca.
static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
DomTreeUpdater *DTU,
MemorySSAUpdater *MSSAU,
- bool PoisonSafe,
const TargetTransformInfo *TTI) {
BasicBlock *BB = BI->getParent();
BasicBlock *PredBlock = PBI->getParent();
// or/and the two conditions together.
Value *NewCond = nullptr;
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");
else
NewCond =
bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
MemorySSAUpdater *MSSAU,
const TargetTransformInfo *TTI,
- unsigned BonusInstThreshold,
- bool PoisonSafe) {
+ unsigned BonusInstThreshold) {
// If this block ends with an unconditional branch,
// let SpeculativelyExecuteBB() deal with it.
if (!BI->isConditional())
// Ok, we have the budget. Perform the transformation.
for (BasicBlock *PredBlock : Preds) {
auto *PBI = cast<BranchInst>(PredBlock->getTerminator());
- return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, PoisonSafe,
- TTI);
+ return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, TTI);
}
return Changed;
}
// predecessor and use logical operations to update the incoming value
// for PHI nodes in common successor.
if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
- Options.BonusInstThreshold, true))
+ Options.BonusInstThreshold))
return requestResimplify();
return false;
}
// branches to us and one of our successors, fold the comparison into the
// predecessor and use logical operations to pick the right destination.
if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
- Options.BonusInstThreshold, true))
+ Options.BonusInstThreshold))
return requestResimplify();
// We have a conditional branch to two blocks that are only reachable
; CHECK-NEXT: %iv = phi i64 [ %iv.next, %guarded ], [ 0, %loop.preheader ]
; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1
; 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: guarded:
; CHECK-NEXT: %gep = getelementptr i64, i64* %p1, i64 %iv.next