[llvm] [VPlan] Port invalid cost remarks to VPlan. (PR #99322)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 04:55:31 PDT 2024
================
@@ -4376,38 +4387,64 @@ static void emitInvalidCostRemarks(SmallVector<InstructionVFPair> InvalidCosts,
std::make_tuple(RHS.isScalable(), RHS.getKnownMinValue());
});
- // For a list of ordered instruction-vf pairs:
- // [(load, vf1), (load, vf2), (store, vf1)]
- // Group the instructions together to emit separate remarks for:
- // load (vf1, vf2)
- // store (vf1)
- auto Tail = ArrayRef<InstructionVFPair>(InvalidCosts);
- auto Subset = ArrayRef<InstructionVFPair>();
+ // For a list of ordered recipe-VF pairs:
+ // [(load, VF1), (load, VF2), (store, VF1)]
+ // group the recipes together to emit separate remarks for:
+ // load (VF1, VF2)
+ // store (VF1)
+ auto Tail = ArrayRef<RecipeVFPair>(InvalidCosts);
+ auto Subset = ArrayRef<RecipeVFPair>();
do {
if (Subset.empty())
Subset = Tail.take_front(1);
- Instruction *I = Subset.front().first;
-
- // If the next instruction is different, or if there are no other pairs,
+ VPRecipeBase *R = Subset.front().first;
+
+ unsigned Opcode =
+ TypeSwitch<const VPRecipeBase *, unsigned>(R)
+ .Case<VPHeaderPHIRecipe>(
+ [](const auto *R) { return Instruction::PHI; })
+ .Case<VPWidenSelectRecipe>(
+ [](const auto *R) { return Instruction::Select; })
+ .Case<VPWidenStoreRecipe>(
+ [](const auto *R) { return Instruction::Store; })
+ .Case<VPWidenLoadRecipe>(
+ [](const auto *R) { return Instruction::Load; })
+ .Case<VPWidenCallRecipe>(
+ [](const auto *R) { return Instruction::Call; })
+ .Case<VPInstruction, VPWidenRecipe, VPReplicateRecipe,
+ VPWidenCastRecipe>(
+ [](const auto *R) { return R->getOpcode(); })
+ .Case<VPInterleaveRecipe>([](const VPInterleaveRecipe *R) {
+ return R->getStoredValues().empty() ? Instruction::Load
+ : Instruction::Store;
+ });
+
+ // If the next recipe is different, or if there are no other pairs,
// emit a remark for the collated subset. e.g.
- // [(load, vf1), (load, vf2))]
+ // [(load, VF1), (load, VF2))]
// to emit:
- // remark: invalid costs for 'load' at VF=(vf, vf2)
- if (Subset == Tail || Tail[Subset.size()].first != I) {
+ // remark: invalid costs for 'load' at VF=(VF1, VF2)
+ if (Subset == Tail || Tail[Subset.size()].first != R) {
std::string OutString;
raw_string_ostream OS(OutString);
assert(!Subset.empty() && "Unexpected empty range");
- OS << "Instruction with invalid costs prevented vectorization at VF=(";
+ OS << "Recipe with invalid costs prevented vectorization at VF=(";
for (const auto &Pair : Subset)
OS << (Pair.second == Subset.front().second ? "" : ", ") << Pair.second;
OS << "):";
- if (auto *CI = dyn_cast<CallInst>(I))
- OS << " call to " << CI->getCalledFunction()->getName();
- else
- OS << " " << I->getOpcodeName();
+ if (Opcode == Instruction::Call) {
+ auto *WidenCall = dyn_cast<VPWidenCallRecipe>(R);
+ Function *CalledFn =
+ WidenCall ? WidenCall->getCalledScalarFunction()
+ : cast<Function>(R->getOperand(R->getNumOperands() - 1)
+ ->getLiveInIRValue());
----------------
ayalz wrote:
Worth at-least a comment or assert, noting that if not WidenCall then R is replicating a CallInst, both having the called function as their last operand. Better have ReplicateRecipe (or a derivative thereof) provide the called function explicitly (or print its name), to avoid bypassing CallInst's getCalledFunction(), also noting that recipes may use their last operand for an optional mask.
https://github.com/llvm/llvm-project/pull/99322
More information about the llvm-commits
mailing list