Skip to content

AMDGPU: Report special input intrinsics as free #141948

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,29 @@ static bool intrinsicHasPackedVectorBenefit(Intrinsic::ID ID) {
InstructionCost
GCNTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
TTI::TargetCostKind CostKind) const {
if (ICA.getID() == Intrinsic::fabs)
switch (ICA.getID()) {
case Intrinsic::fabs:
// Free source modifier in the common case.
return 0;
case Intrinsic::amdgcn_workitem_id_x:
case Intrinsic::amdgcn_workitem_id_y:
case Intrinsic::amdgcn_workitem_id_z:
// TODO: If hasPackedTID, or if the calling context is not an entry point
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe report 1 for packed tid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason the calling instruction isn't set in the context where this gets called from, so I can't figure out if it's a kernel or not so I left this for later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly also can't check if the other work items are disabled

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok for now.

// there may be a bit instruction.
return 0;
case Intrinsic::amdgcn_workgroup_id_x:
case Intrinsic::amdgcn_workgroup_id_y:
case Intrinsic::amdgcn_workgroup_id_z:
case Intrinsic::amdgcn_lds_kernel_id:
case Intrinsic::amdgcn_dispatch_ptr:
case Intrinsic::amdgcn_dispatch_id:
case Intrinsic::amdgcn_implicitarg_ptr:
case Intrinsic::amdgcn_queue_ptr:
// Read from an argument register.
return 0;
default:
break;
}

if (!intrinsicHasPackedVectorBenefit(ICA.getID()))
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
Expand Down
56 changes: 28 additions & 28 deletions llvm/test/Analysis/CostModel/AMDGPU/special-argument-intrinsics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

define i32 @workitem_id_x() {
; ALL-LABEL: 'workitem_id_x'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'workitem_id_x'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.workitem.id.x()
Expand All @@ -20,12 +20,12 @@ define i32 @workitem_id_x() {

define amdgpu_kernel void @kernel_workitem_id_x(ptr addrspace(1) %ptr) {
; ALL-LABEL: 'kernel_workitem_id_x'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; SIZE-LABEL: 'kernel_workitem_id_x'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
Expand All @@ -36,11 +36,11 @@ define amdgpu_kernel void @kernel_workitem_id_x(ptr addrspace(1) %ptr) {

define i32 @workitem_id_y() {
; ALL-LABEL: 'workitem_id_y'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'workitem_id_y'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.workitem.id.y()
Expand All @@ -49,12 +49,12 @@ define i32 @workitem_id_y() {

define amdgpu_kernel void @kernel_workitem_id_y(ptr addrspace(1) %ptr) {
; ALL-LABEL: 'kernel_workitem_id_y'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; SIZE-LABEL: 'kernel_workitem_id_y'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
Expand All @@ -65,11 +65,11 @@ define amdgpu_kernel void @kernel_workitem_id_y(ptr addrspace(1) %ptr) {

define i32 @workitem_id_z() {
; ALL-LABEL: 'workitem_id_z'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'workitem_id_z'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.workitem.id.y()
Expand All @@ -78,12 +78,12 @@ define i32 @workitem_id_z() {

define amdgpu_kernel void @kernel_workitem_id_z(ptr addrspace(1) %ptr) {
; ALL-LABEL: 'kernel_workitem_id_z'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; SIZE-LABEL: 'kernel_workitem_id_z'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
Expand All @@ -94,11 +94,11 @@ define amdgpu_kernel void @kernel_workitem_id_z(ptr addrspace(1) %ptr) {

define i32 @workgroup_id_x() {
; ALL-LABEL: 'workgroup_id_x'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'workgroup_id_x'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.workgroup.id.x()
Expand All @@ -107,11 +107,11 @@ define i32 @workgroup_id_x() {

define i32 @workgroup_id_y() {
; ALL-LABEL: 'workgroup_id_y'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'workgroup_id_y'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.workgroup.id.y()
Expand All @@ -120,11 +120,11 @@ define i32 @workgroup_id_y() {

define i32 @workgroup_id_z() {
; ALL-LABEL: 'workgroup_id_z'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'workgroup_id_z'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.workgroup.id.y()
Expand All @@ -133,11 +133,11 @@ define i32 @workgroup_id_z() {

define i32 @lds_kernel_id() {
; ALL-LABEL: 'lds_kernel_id'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
;
; SIZE-LABEL: 'lds_kernel_id'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
;
%result = call i32 @llvm.amdgcn.lds.kernel.id()
Expand All @@ -146,11 +146,11 @@ define i32 @lds_kernel_id() {

define ptr addrspace(4) @dispatch_ptr() {
; ALL-LABEL: 'dispatch_ptr'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret ptr addrspace(4) %result
;
; SIZE-LABEL: 'dispatch_ptr'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret ptr addrspace(4) %result
;
%result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
Expand All @@ -159,11 +159,11 @@ define ptr addrspace(4) @dispatch_ptr() {

define i64 @dispatch_id_() {
; ALL-LABEL: 'dispatch_id_'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i64 %result
;
; SIZE-LABEL: 'dispatch_id_'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %result
;
%result = call i64 @llvm.amdgcn.dispatch.id()
Expand All @@ -172,11 +172,11 @@ define i64 @dispatch_id_() {

define ptr addrspace(4) @implicitarg_ptr() {
; ALL-LABEL: 'implicitarg_ptr'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret ptr addrspace(4) %result
;
; SIZE-LABEL: 'implicitarg_ptr'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret ptr addrspace(4) %result
;
%result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
Expand All @@ -185,11 +185,11 @@ define ptr addrspace(4) @implicitarg_ptr() {

define ptr addrspace(4) @queue_ptr() {
; ALL-LABEL: 'queue_ptr'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret ptr addrspace(4) %result
;
; SIZE-LABEL: 'queue_ptr'
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret ptr addrspace(4) %result
;
%result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
Expand Down
Loading