[PATCH] D151988: LoopVectorize: extend SelectCmp pattern for non-invariants
Shiva Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 02:58:04 PDT 2023
shiva0217 added inline comments.
================
Comment at: llvm/lib/Analysis/IVDescriptors.cpp:678
+ // If the loop is not invariant, we need to know the direction of the loop.
+ auto Bounds = SE ? Loop->getBounds(*SE) : std::nullopt;
+ if (!Loop->isLoopInvariant(NonPhi) &&
----------------
For the following case, the final value might not be able to pick by the min/max reduction.
int test(int a[32000]) {
int k = -1;
for (int i = 0; i < 32000; i++)
if (a[i] < 0)
k = a[i];
return k;
}
Extra checking of NonPhi might be needed. So the reduction can generate min/max.
auto *AR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(NonPhi));
if (AR) {
const SCEV *Step = AR->getStepRecurrence(*SE);
const SCEVConstant *ConstStep = dyn_cast<SCEVConstant>(Step);
if (!ConstStep && !SE->isLoopInvariant(Step, Loop))
return InstDesc(false, I);
} else
return InstDesc(false, I);
Would it need to check AR->hasNoUnsignedWrap?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151988/new/
https://reviews.llvm.org/D151988
More information about the llvm-commits
mailing list