diff options
author | Max Kazantsev <mkazantsev@azul.com> | 2021-03-01 12:07:46 +0700 |
---|---|---|
committer | Max Kazantsev <mkazantsev@azul.com> | 2021-03-01 12:11:54 +0700 |
commit | 2892fcc204f30ff16d9adb382a67d7125598813d (patch) | |
tree | 59e0a5202c10c36a20559bae2bb45046da5a19fb /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | dc93b1127c5e0621e672745d26bce5a11f68d943 (diff) | |
download | llvm-2892fcc204f30ff16d9adb382a67d7125598813d.zip llvm-2892fcc204f30ff16d9adb382a67d7125598813d.tar.gz llvm-2892fcc204f30ff16d9adb382a67d7125598813d.tar.bz2 |
[NFC] Factor out IV detector function for further reuse
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index ed83fad..b62c332 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -1276,23 +1276,30 @@ static bool OptimizeNoopCopyExpression(CastInst *CI, const TargetLowering &TLI, return SinkCast(CI); } +static bool isIVIncrement(const BinaryOperator *BO, const LoopInfo *LI) { + auto *PN = dyn_cast<PHINode>(BO->getOperand(0)); + if (!PN) + return false; + const Loop *L = LI->getLoopFor(BO->getParent()); + if (!L || L->getHeader() != PN->getParent() || !L->getLoopLatch()) + return false; + const BasicBlock *Latch = L->getLoopLatch(); + if (PN->getIncomingValueForBlock(Latch) != BO) + return false; + if (!L->isLoopInvariant(BO->getOperand(1))) + // Avoid complexities w/loop varying steps. + return false; + return true; +} + bool CodeGenPrepare::replaceMathCmpWithIntrinsic(BinaryOperator *BO, Value *Arg0, Value *Arg1, CmpInst *Cmp, Intrinsic::ID IID) { - auto isIVIncrement = [this, &Cmp](BinaryOperator *BO) { - auto *PN = dyn_cast<PHINode>(BO->getOperand(0)); - if (!PN) + auto IsReplacableIVIncrement = [this, &Cmp](BinaryOperator *BO) { + if (!isIVIncrement(BO, LI)) return false; const Loop *L = LI->getLoopFor(BO->getParent()); - if (!L || L->getHeader() != PN->getParent() || !L->getLoopLatch()) - return false; - const BasicBlock *Latch = L->getLoopLatch(); - if (PN->getIncomingValueForBlock(Latch) != BO) - return false; - if (!L->isLoopInvariant(BO->getOperand(1))) - // Avoid complexities w/loop varying steps. - return false; // IV increment may have other users than the IV. We do not want to make // dominance queries to analyze the legality of moving it towards the cmp, // so just check that there is no other users. @@ -1305,9 +1312,9 @@ bool CodeGenPrepare::replaceMathCmpWithIntrinsic(BinaryOperator *BO, // cheap check because no CFG changes & dom tree recomputation happens // during the transform. Function *F = BO->getParent()->getParent(); - return getDT(*F).dominates(Cmp->getParent(), Latch); + return getDT(*F).dominates(Cmp->getParent(), L->getLoopLatch()); }; - if (BO->getParent() != Cmp->getParent() && !isIVIncrement(BO)) { + if (BO->getParent() != Cmp->getParent() && !IsReplacableIVIncrement(BO)) { // We used to use a dominator tree here to allow multi-block optimization. // But that was problematic because: // 1. It could cause a perf regression by hoisting the math op into the |