Skip to content

[LV]: Add costs to VPInstruction #125008

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

Closed
wants to merge 1 commit into from
Closed

Conversation

hassnaaHamdi
Copy link
Member

@hassnaaHamdi hassnaaHamdi commented Jan 30, 2025

  • In some cases VPlanTransforms pass replaces some instructions by VPInstructions.
  • Right now VPInstruction returns 0 cost, and that causes inaccurate VPlan-based cost
    calculations which may cause choosing VF different than chosen one by legacy cost model.

- As VPlanTransforms replaces some instructions by VPInstructions, then VPInstruction should have costs.
- Use legacy model for now.
- Computed costs are for the original/replaced instructions to match with what legacy model computed.
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2025

@llvm/pr-subscribers-vectorizers

@llvm/pr-subscribers-llvm-transforms

Author: Hassnaa Hamdi (hassnaaHamdi)

Changes
  • As VPlanTransforms replaces some instructions by VPInstructions, then VPInstruction should have costs.
  • Use legacy model for now.
  • Computed costs are for the original/replaced instructions to match with what legacy model computed.

Full diff: https://github.com/llvm/llvm-project/pull/125008.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+3)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index a1ff684b2b8017..8813ea3c208b61 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1315,6 +1315,9 @@ class VPInstruction : public VPRecipeWithIRFlags,
   InstructionCost computeCost(ElementCount VF,
                               VPCostContext &Ctx) const override {
     // TODO: Compute accurate cost after retiring the legacy cost model.
+    // Use legacy cost model for now.
+    if (auto *I = dyn_cast_or_null<Instruction>(getUnderlyingValue()))
+      return Ctx.getLegacyCost(I, VF);
     return 0;
   }
 

@@ -1315,6 +1315,9 @@ class VPInstruction : public VPRecipeWithIRFlags,
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
// Use legacy cost model for now.
if (auto *I = dyn_cast_or_null<Instruction>(getUnderlyingValue()))
Copy link
Contributor

@david-arm david-arm Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hassnaaHamdi, I think you should be able to do this without falling back on the legacy cost model. I also plan to put a patch up fairly soon that starts filling this function in properly because it's needed for the early exit work. What instructions were you hitting when getting into this instruction?

Copy link
Member Author

@hassnaaHamdi hassnaaHamdi Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original instruction was 'or disjoint' and it got replaced by the VPlanTransforms to 'Add' instruction wrapped in VPInstruction.

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test case, some more details of what VPInstructions need costs now and how this is related to the change for interleaving?

@hassnaaHamdi
Copy link
Member Author

Closing this pull request as the work is done by another patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants