[llvm] LoopVectorize: fix phi cost when it is scalar after vectorization (PR #74456)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 07:39:06 PST 2024
================
@@ -6885,7 +6885,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF,
auto *Phi = cast<PHINode>(I);
// First-order recurrences are replaced by vector shuffles inside the loop.
- if (VF.isVector() && Legal->isFixedOrderRecurrence(Phi)) {
+ // However, if the Phi is a scalar after vectorization, don't get shuffle
+ // cost.
+ if (VF.isVector() && Legal->isFixedOrderRecurrence(Phi) &&
+ !isScalarAfterVectorization(Phi, VF)) {
----------------
fhahn wrote:
IIUC we now don't crash because the phi in the test is considered scalar after vectorization; but this doesn't match the code we generate in the test case, where we have a vector phi for the recurrence and the corresponding shuffle AFAICT.
We only support codegen for vector recurrences, so it would probably be better to avoid marking the phi as scalar after vectorization.
https://github.com/llvm/llvm-project/pull/74456
More information about the llvm-commits
mailing list