-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[CostModel] Mark ssa_copy as free #75294
Conversation
@llvm/pr-subscribers-llvm-analysis Author: David Green (davemgreen) ChangesThese are intrinsics are only used ephemerally and be should be given a zero cost. Full diff: https://github.com/llvm/llvm-project/pull/75294.diff 2 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index e05ce2890a08c8..33db350a12102a 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -1510,6 +1510,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
Intrinsic::ID IID = ICA.getID();
if (Function::isTargetIntrinsic(IID))
return TargetTransformInfo::TCC_Basic;
+ if (IID == Intrinsic::ssa_copy)
+ return TargetTransformInfo::TCC_Free;
if (ICA.isTypeBasedOnly())
return getTypeBasedIntrinsicInstrCost(ICA, CostKind);
diff --git a/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll b/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll
index 9a9193b36de029..d58f3348e41fed 100644
--- a/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll
+++ b/llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll
@@ -341,27 +341,27 @@ define void @memcpy(ptr %a, ptr %b, i32 %c) {
define void @ssa_copy() {
; CHECK: %{{.*}} = llvm.intr.ssa.copy %{{.*}} : f32
; THRU-LABEL: 'ssa_copy'
-; THRU-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
-; THRU-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
-; THRU-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
+; THRU-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
+; THRU-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
+; THRU-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
; THRU-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
;
; LATE-LABEL: 'ssa_copy'
-; LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
-; LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
-; LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
+; LATE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
+; LATE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
+; LATE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
; LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
; SIZE-LABEL: 'ssa_copy'
-; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
-; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
-; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
+; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
+; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
+; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
; SIZE_LATE-LABEL: 'ssa_copy'
-; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
-; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
-; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
+; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %i = call i32 @llvm.ssa.copy.i32(i32 undef)
+; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %f = call float @llvm.ssa.copy.f32(float undef)
+; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %p = call ptr @llvm.ssa.copy.p0(ptr undef)
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
%i = call i32 @llvm.ssa.copy.i32(i32 undef)
|
I am curious if you encountered cases where those intrinsics are still around after the middle-end optimization pipeline. I think all users of those intrinsics should clean them up, but there might be some places that got missed. |
No the costing is done during a pass that adds and removes them. This could be handled specially in that pass, but it is more general fix to give a zero cost to everywhere. |
@@ -1510,6 +1510,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> { | |||
Intrinsic::ID IID = ICA.getID(); | |||
if (Function::isTargetIntrinsic(IID)) | |||
return TargetTransformInfo::TCC_Basic; | |||
if (IID == Intrinsic::ssa_copy) | |||
return TargetTransformInfo::TCC_Free; |
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.
This should be in TargetTransformInfoImpl.h.
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.
Ah I see. That is better, thanks.
These are intrinsics are only used ephemerally and be should be given a zero cost.
99621ee
to
fad4c27
Compare
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
These are intrinsics are only used ephemerally and be should be given a zero cost.