-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[VPlan] Implement VPWidenCallRecipe::computeCost (NFCI). #106047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Florian Hahn (fhahn) ChangesImplement cost computation for VPWidenCallRecipe. In some cases, targets use argument info to compute intrinsic costs. If all operands of the call are VPValues with an underlying IR value, use the IR values as arguments. Full diff: https://github.com/llvm/llvm-project/pull/106047.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 36a1aa08654d5b..ea88fe6720d96f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1565,6 +1565,10 @@ class VPWidenCallRecipe : public VPSingleDefRecipe {
/// Produce a widened version of the call instruction.
void execute(VPTransformState &State) override;
+ /// Return the cost of this VPWidenCallRecipe.
+ InstructionCost computeCost(ElementCount VF,
+ VPCostContext &Ctx) const override;
+
Function *getCalledScalarFunction() const {
return cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue());
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index fe1325f4163004..8bc0c6621fbde2 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -924,6 +924,46 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
}
}
+InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF,
+ VPCostContext &Ctx) const {
+ TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+ if (Variant) {
+ return Ctx.TTI.getCallInstrCost(nullptr, Variant->getReturnType(),
+ Variant->getFunctionType()->params(),
+ CostKind);
+ }
+
+ FastMathFlags FMF;
+ // TODO: Manage flags via VPRecipeWithIRFlags.
+ if (auto *FPMO = dyn_cast_or_null<FPMathOperator>(getUnderlyingValue()))
+ FMF = FPMO->getFastMathFlags();
+
+ // Some backends analyze intrinsic arguments to determine cost. If all
+ // operands are VPValues with an underlying IR value, use the original IR
+ // values for cost computations.
+ SmallVector<const Value *> Arguments;
+ for (VPValue *Op : operands()) {
+ auto *V = Op->getUnderlyingValue();
+ if (!V) {
+ Arguments.clear();
+ break;
+ }
+ Arguments.push_back(V);
+ }
+
+ Type *RetTy =
+ ToVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF);
+ SmallVector<Type *> ParamTys;
+ for (unsigned I = 0; I != getNumOperands(); ++I)
+ ParamTys.push_back(
+ ToVectorTy(Ctx.Types.inferScalarType(getOperand(I)), VF));
+
+ IntrinsicCostAttributes CostAttrs(VectorIntrinsicID, RetTy, Arguments,
+ ParamTys, FMF);
+ return Ctx.TTI.getIntrinsicInstrCost(
+ CostAttrs, TargetTransformInfo::TCK_RecipThroughput);
+}
+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void VPWidenCallRecipe::print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
IntrinsicCostAttributes CostAttrs(VectorIntrinsicID, RetTy, Arguments, | ||
ParamTys, FMF); | ||
return Ctx.TTI.getIntrinsicInstrCost( | ||
CostAttrs, TargetTransformInfo::TCK_RecipThroughput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can just use CostKind
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done thanks!
Implement cost computation for VPWidenCallRecipe. In some cases, targets use argument info to compute intrinsic costs. If all operands of the call are VPValues with an underlying IR value, use the IR values as arguments.
3fc1eee
to
3730ebf
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/4/builds/1815 Here is the relevant piece of the build log for the reference
|
Looks like this causes buildbot failures. In my case, stage1-clang crashes while compiling ADTTests on the aarch64 host.
|
@chapuni could you share the full crashing compiler invocation? Bootstrapping on ARM64 macOS works fine for me. |
This is also the cause of test suite failures on AArch64 Linux: https://lab.llvm.org/buildbot/#/builders/41/builds/1722 It's just that build configuration issues are hiding them under a pile of unintentional NOEXE results. We'll find what is actually failing. |
@DavidSpickett thanks, I think it looks like an assertion is triggered when building a Fortran workload from the llvm-test-suite with Flang. Is there any chance to extract the IR reproducer from Flang? |
Looks like the failing test is typebound_operator_9.f03 |
I also ran into assert failures with this, on a multitude of architectures. (I would have caught it already yesterday, but my nightly build yesterday was broken due to other reasons, so yesterday's build went untested otherwise.) It's reproducible with the following snippets: float *a;
int b;
double fabs();
__attribute__((cold)) int c() {
for (; b; b++)
a[b] = 1. - fabs(b);
}
And: int *a;
__attribute__((cold)) int b(int c) {
long d, f;
double e;
for (int g = 0; g < c; g++) {
e = g * 3.14159265358979323846;
f = e;
if (f > 0)
d = 0;
else
d = f;
a[g] = d;
}
}
|
@mstorsjo thanks, should be fixed by dd94537 @antmox @DavidSpickett AFAICT now the bots with Flang crashes should be back to green? |
@fhahn yes indeed, bots are back to green, thanks |
this is causing crashes on
|
Implement cost computation for VPWidenCallRecipe. In some cases, targets use argument info to compute intrinsic costs. If all operands of the call are VPValues with an underlying IR value, use the IR values as arguments. PR: llvm#106731 Change-Id: I9eea7ea07341d8662d5cb0798dcb7151f0fb04e2
Implement cost computation for VPWidenCallRecipe. In some cases, targets use argument info to compute intrinsic costs. If all operands of the call are VPValues with an underlying IR value, use the IR values as arguments.