[llvm] 9daccb7 - Correctly update Changed status for SimplifyCFG
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 07:54:28 PDT 2020
Author: serge-sans-paille
Date: 2020-06-10T16:54:15+02:00
New Revision: 9daccb7a477b8cf2448dab35ae2779a4b36c2b63
URL: https://github.com/llvm/llvm-project/commit/9daccb7a477b8cf2448dab35ae2779a4b36c2b63
DIFF: https://github.com/llvm/llvm-project/commit/9daccb7a477b8cf2448dab35ae2779a4b36c2b63.diff
LOG: Correctly update Changed status for SimplifyCFG
Interestingly, this leads to better output in one of the test case.
Differential Revision: https://reviews.llvm.org/D81237
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 9afc18efce69..23b76bd18a55 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2615,6 +2615,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
const unsigned PredCount = pred_size(BB);
+ bool Changed = false;
+
Instruction *Cond = nullptr;
if (BI->isConditional())
Cond = dyn_cast<Instruction>(BI->getCondition());
@@ -2639,16 +2641,17 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
// Quit if we can't remove this instruction.
if (!tryCSEWithPredecessor(Curr, PB))
return false;
+ Changed = true;
}
}
if (!Cond)
- return false;
+ return Changed;
}
if (!Cond || (!isa<CmpInst>(Cond) && !isa<BinaryOperator>(Cond)) ||
Cond->getParent() != BB || !Cond->hasOneUse())
- return false;
+ return Changed;
// Make sure the instruction after the condition is the cond branch.
BasicBlock::iterator CondIt = ++Cond->getIterator();
@@ -2658,7 +2661,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
++CondIt;
if (&*CondIt != BI)
- return false;
+ return Changed;
// Only allow this transformation if computing the condition doesn't involve
// too many instructions and these involved instructions can be executed
@@ -2672,11 +2675,11 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
if (isa<DbgInfoIntrinsic>(I))
continue;
if (!I->hasOneUse() || !isSafeToSpeculativelyExecute(&*I))
- return false;
+ return Changed;
// I has only one use and can be executed unconditionally.
Instruction *User = dyn_cast<Instruction>(I->user_back());
if (User == nullptr || User->getParent() != BB)
- return false;
+ return Changed;
// I is used in the same BB. Since BI uses Cond and doesn't have more slots
// to use any other instruction, User must be an instruction between next(I)
// and Cond.
@@ -2686,23 +2689,23 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
NumBonusInsts += PredCount;
// Early exits once we reach the limit.
if (NumBonusInsts > BonusInstThreshold)
- return false;
+ return Changed;
}
// Cond is known to be a compare or binary operator. Check to make sure that
// neither operand is a potentially-trapping constant expression.
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Cond->getOperand(0)))
if (CE->canTrap())
- return false;
+ return Changed;
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Cond->getOperand(1)))
if (CE->canTrap())
- return false;
+ return Changed;
// Finally, don't infinitely unroll conditional loops.
BasicBlock *TrueDest = BI->getSuccessor(0);
BasicBlock *FalseDest = (BI->isConditional()) ? BI->getSuccessor(1) : nullptr;
if (TrueDest == BB || FalseDest == BB)
- return false;
+ return Changed;
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
BasicBlock *PredBlock = *PI;
@@ -2742,6 +2745,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
}
LLVM_DEBUG(dbgs() << "FOLDING BRANCH TO COMMON DEST:\n" << *PBI << *BB);
+ Changed = true;
+
IRBuilder<> Builder(PBI);
// If we need to invert the condition in the pred block to match, do so now.
@@ -2913,9 +2918,9 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
}
}
- return true;
+ return Changed;
}
- return false;
+ return Changed;
}
// If there is only one store in BB1 and BB2, return it, otherwise return
diff --git a/llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll b/llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll
index 7b26b6f95de3..242b1230e5fd 100644
--- a/llvm/test/Transforms/SimplifyCFG/fold-branch-debuginvariant.ll
+++ b/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"
More information about the llvm-commits
mailing list