aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-04-24 17:05:06 +0200
committerNikita Popov <npopov@redhat.com>2023-04-24 17:05:58 +0200
commitebd6b5dc6426c5a759d9ed588fe6b972319736ff (patch)
tree21edd70c937a06879f450c7b268a05dee8cd4727
parentf0630a37b616ec81bf65f5e36e0586a396bfb6d6 (diff)
downloadllvm-ebd6b5dc6426c5a759d9ed588fe6b972319736ff.zip
llvm-ebd6b5dc6426c5a759d9ed588fe6b972319736ff.tar.gz
llvm-ebd6b5dc6426c5a759d9ed588fe6b972319736ff.tar.bz2
[LICM] Minor optimization (NFC)
Simplify the match in hoistMinMax and only fetch the preheader once.
-rw-r--r--llvm/lib/Transforms/Scalar/LICM.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index b5298cf..5a19451 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.") +