Skip to content

[FuncSpec] Handle ssa_copy intrinsic calls in InstCostVisitor #114247

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

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

hazzlim
Copy link
Contributor

@hazzlim hazzlim commented Oct 30, 2024

Look through ssa_copy intrinsic calls when computing codesize bonus for a specialization.

Also remove redundant logic to skip computing codesize bonus for ssa_copy intrinsics, now these are considered zero-cost by TTI (in PR #75294).

@llvmbot
Copy link
Member

llvmbot commented Oct 30, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-function-specialization

Author: Hari Limaye (hazzlim)

Changes

Look through ssa_copy intrinsic calls when computing codesize bonus for a specialization.

Also remove redundant logic to skip computing codesize bonus for ssa_copy intrinsics, now these are considered zero-cost by TTI (in PR#75294).


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/FunctionSpecialization.cpp (+8-4)
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 919d3143a13f7e..1efec22624dd4f 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -120,10 +120,6 @@ Cost InstCostVisitor::estimateBasicBlocks(
       continue;
 
     for (Instruction &I : *BB) {
-      // Disregard SSA copies.
-      if (auto *II = dyn_cast<IntrinsicInst>(&I))
-        if (II->getIntrinsicID() == Intrinsic::ssa_copy)
-          continue;
       // If it's a known constant we have already accounted for it.
       if (KnownConstants.contains(&I))
         continue;
@@ -402,6 +398,14 @@ Constant *InstCostVisitor::visitFreezeInst(FreezeInst &I) {
 }
 
 Constant *InstCostVisitor::visitCallBase(CallBase &I) {
+  assert(LastVisited != KnownConstants.end() && "Invalid iterator!");
+
+  // Look through calls to ssa_copy intrinsics.
+  if (auto *II = dyn_cast<IntrinsicInst>(&I);
+      II && II->getIntrinsicID() == Intrinsic::ssa_copy) {
+    return LastVisited->second;
+  }
+
   Function *F = I.getCalledFunction();
   if (!F || !canConstantFoldCallTo(&I, F))
     return nullptr;

Copy link
Collaborator

@labrinea labrinea left a comment

Choose a reason for hiding this comment

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

Great thanks! Unit/regression test?

Look through ssa_copy intrinsic calls when computing codesize bonus for
a specialization.

Also remove redundant logic to skip computing codesize bonus for
ssa_copy intrinsics, now these are considered zero-cost by TTI
(in PR#75294).
@hazzlim
Copy link
Contributor Author

hazzlim commented Oct 31, 2024

Great thanks! Unit/regression test?

Added a regression test, as a prior commit so it's more obvious how this change affects things :)

As additional context for this change, this improves the estimation of the CodeSize bonus for a specialization of the function digits_2 from the SPEC2k17 benchmark exchange2, increasing this from 43% to 68% (with -mcpu=neoverse-{n1|v2}).

@hazzlim hazzlim merged commit daa9af1 into llvm:main Nov 4, 2024
5 of 8 checks passed
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
…14247)

Look through ssa_copy intrinsic calls when computing codesize bonus for
a specialization.

Also remove redundant logic to skip computing codesize bonus for
ssa_copy intrinsics, now these are considered zero-cost by TTI (in PR
llvm#75294).
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.

3 participants