Index: llvm/include/llvm/Transforms/Utils/Local.h =================================================================== --- llvm/include/llvm/Transforms/Utils/Local.h +++ llvm/include/llvm/Transforms/Utils/Local.h @@ -257,7 +257,7 @@ /// branches to us and one of our successors, fold the setcc into the /// predecessor and use logical operations to pick the right destination. bool FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU = nullptr, - unsigned BonusInstThreshold = 1); + bool* Modified = nullptr, 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. Index: llvm/lib/Transforms/Utils/LoopSimplify.cpp =================================================================== --- llvm/lib/Transforms/Utils/LoopSimplify.cpp +++ llvm/lib/Transforms/Utils/LoopSimplify.cpp @@ -682,7 +682,7 @@ // The block has now been cleared of all instructions except for // a comparison and a conditional branch. SimplifyCFG may be able // to fold it now. - if (!FoldBranchToCommonDest(BI, MSSAU)) + if (!FoldBranchToCommonDest(BI, MSSAU, &Changed)) continue; // Success. The block is now dead, so remove it from the loop, Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2610,7 +2610,7 @@ /// and one of our successors, fold the block into the predecessor and use /// logical operations to pick the right destination. bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU, - unsigned BonusInstThreshold) { + bool *Modified, unsigned BonusInstThreshold) { BasicBlock *BB = BI->getParent(); const unsigned PredCount = pred_size(BB); @@ -2637,8 +2637,11 @@ break; } // Quit if we can't remove this instruction. - if (!tryCSEWithPredecessor(Curr, PB)) + if (!tryCSEWithPredecessor(Curr, PB)) { return false; + } + if (Modified) + *Modified = true; } } @@ -5944,13 +5947,14 @@ return true; } + bool Modified = false; // If this basic block is ONLY a compare and a branch, and if a predecessor // branches to us and our successor, fold the comparison into the // predecessor and use logical operations to update the incoming value // for PHI nodes in common successor. - if (FoldBranchToCommonDest(BI, nullptr, Options.BonusInstThreshold)) + if (FoldBranchToCommonDest(BI, nullptr, &Modified, Options.BonusInstThreshold)) return requestResimplify(); - return false; + return Modified; } static BasicBlock *allPredecessorsComeFromSameSource(BasicBlock *BB) { @@ -6008,10 +6012,11 @@ return requestResimplify(); } + bool Modified = false; // If this basic block is ONLY a compare and a branch, and if a predecessor // 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, nullptr, Options.BonusInstThreshold)) + if (FoldBranchToCommonDest(BI, nullptr, &Modified, Options.BonusInstThreshold)) return requestResimplify(); // We have a conditional branch to two blocks that are only reachable @@ -6063,7 +6068,7 @@ if (mergeConditionalStores(PBI, BI, DL, TTI)) return requestResimplify(); - return false; + return Modified; } /// Check if passing a value to an instruction will cause undefined behavior. Index: llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll =================================================================== --- llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll +++ llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll @@ -6,7 +6,6 @@ ; CHECK-LABEL: bb1: ; CHECK: and i1 false, false -; CHECK-LABEL: bb2: ; CHECK-NOT: and i1 false, false target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"