[llvm] ebd6b5d - [LICM] Minor optimization (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 24 08:06:08 PDT 2023
Author: Nikita Popov
Date: 2023-04-24T17:05:58+02:00
New Revision: ebd6b5dc6426c5a759d9ed588fe6b972319736ff
URL: https://github.com/llvm/llvm-project/commit/ebd6b5dc6426c5a759d9ed588fe6b972319736ff
DIFF: https://github.com/llvm/llvm-project/commit/ebd6b5dc6426c5a759d9ed588fe6b972319736ff.diff
LOG: [LICM] Minor optimization (NFC)
Simplify the match in hoistMinMax and only fetch the preheader
once.
Added:
Modified:
llvm/lib/Transforms/Scalar/LICM.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index b5298cfd258b..5a1945196a72 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -883,6 +883,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
LoopBlocksRPO Worklist(CurLoop);
Worklist.perform(LI);
bool Changed = false;
+ BasicBlock *Preheader = CurLoop->getLoopPreheader();
for (BasicBlock *BB : Worklist) {
// Only need to process the contents of this block if it is not part of a
// subloop (which would already have been processed).
@@ -916,8 +917,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
canSinkOrHoistInst(I, AA, DT, CurLoop, MSSAU, true, Flags, ORE) &&
isSafeToExecuteUnconditionally(
I, DT, TLI, CurLoop, SafetyInfo, ORE,
- CurLoop->getLoopPreheader()->getTerminator(), AC,
- AllowSpeculation)) {
+ Preheader->getTerminator(), AC, AllowSpeculation)) {
hoist(I, DT, CurLoop, CFH.getOrCreateHoistedBlock(BB), SafetyInfo,
MSSAU, SE, ORE);
HoistedInstructions.push_back(&I);
@@ -2421,19 +2421,13 @@ bool pointerInvalidatedByBlock(BasicBlock &BB, MemorySSA &MSSA, MemoryUse &MU) {
static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
MemorySSAUpdater &MSSAU) {
bool Inverse = false;
- bool IsLogical = false;
using namespace PatternMatch;
Value *Cond1, *Cond2;
- if (match(&I, m_Or(m_Value(Cond1), m_Value(Cond2))))
- Inverse = true;
- else if (match(&I, m_LogicalOr(m_Value(Cond1), m_Value(Cond2)))) {
+ if (match(&I, m_LogicalOr(m_Value(Cond1), m_Value(Cond2)))) {
Inverse = true;
- IsLogical = true;
- } else if (match(&I, m_And(m_Value(Cond1), m_Value(Cond2)))) {
+ } else if (match(&I, m_LogicalAnd(m_Value(Cond1), m_Value(Cond2)))) {
// Do nothing
- } else if (match(&I, m_LogicalAnd(m_Value(Cond1), m_Value(Cond2))))
- IsLogical = true;
- else
+ } else
return false;
auto MatchICmpAgainstInvariant = [&](Value *C, ICmpInst::Predicate &P,
@@ -2477,7 +2471,7 @@ static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
// before (if it was a non-taken input of logical and/or instruction). If it
// was poison, we need to freeze it. Note that no new use for LHS and RHS1 are
// introduced, so they don't need this.
- if (IsLogical)
+ if (isa<SelectInst>(I))
RHS2 = Builder.CreateFreeze(RHS2, RHS2->getName() + ".fr");
Value *NewRHS = Builder.CreateBinaryIntrinsic(
id, RHS1, RHS2, nullptr, StringRef("invariant.") +
More information about the llvm-commits
mailing list