Skip to content

Commit bc8b6df

Browse files
committed
AMDGPU: Report special input intrinsics as free
1 parent 2eb6a6e commit bc8b6df

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,29 @@ static bool intrinsicHasPackedVectorBenefit(Intrinsic::ID ID) {
704704
InstructionCost
705705
GCNTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
706706
TTI::TargetCostKind CostKind) const {
707-
if (ICA.getID() == Intrinsic::fabs)
707+
switch (ICA.getID()) {
708+
case Intrinsic::fabs:
709+
// Free source modifier in the common case.
710+
return 0;
711+
case Intrinsic::amdgcn_workitem_id_x:
712+
case Intrinsic::amdgcn_workitem_id_y:
713+
case Intrinsic::amdgcn_workitem_id_z:
714+
// TODO: If hasPackedTID, or if the calling context is not an entry point
715+
// there may be a bit instruction.
716+
return 0;
717+
case Intrinsic::amdgcn_workgroup_id_x:
718+
case Intrinsic::amdgcn_workgroup_id_y:
719+
case Intrinsic::amdgcn_workgroup_id_z:
720+
case Intrinsic::amdgcn_lds_kernel_id:
721+
case Intrinsic::amdgcn_dispatch_ptr:
722+
case Intrinsic::amdgcn_dispatch_id:
723+
case Intrinsic::amdgcn_implicitarg_ptr:
724+
case Intrinsic::amdgcn_queue_ptr:
725+
// Read from an argument register.
708726
return 0;
727+
default:
728+
break;
729+
}
709730

710731
if (!intrinsicHasPackedVectorBenefit(ICA.getID()))
711732
return BaseT::getIntrinsicInstrCost(ICA, CostKind);

llvm/test/Analysis/CostModel/AMDGPU/special-argument-intrinsics.ll

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
define i32 @workitem_id_x() {
99
; ALL-LABEL: 'workitem_id_x'
10-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
10+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
1111
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
1212
;
1313
; SIZE-LABEL: 'workitem_id_x'
14-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
14+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
1515
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
1616
;
1717
%result = call i32 @llvm.amdgcn.workitem.id.x()
@@ -20,12 +20,12 @@ define i32 @workitem_id_x() {
2020

2121
define amdgpu_kernel void @kernel_workitem_id_x(ptr addrspace(1) %ptr) {
2222
; ALL-LABEL: 'kernel_workitem_id_x'
23-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
23+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
2424
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
2525
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
2626
;
2727
; SIZE-LABEL: 'kernel_workitem_id_x'
28-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
28+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.x()
2929
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
3030
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
3131
;
@@ -36,11 +36,11 @@ define amdgpu_kernel void @kernel_workitem_id_x(ptr addrspace(1) %ptr) {
3636

3737
define i32 @workitem_id_y() {
3838
; ALL-LABEL: 'workitem_id_y'
39-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
39+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
4040
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
4141
;
4242
; SIZE-LABEL: 'workitem_id_y'
43-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
43+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
4444
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
4545
;
4646
%result = call i32 @llvm.amdgcn.workitem.id.y()
@@ -49,12 +49,12 @@ define i32 @workitem_id_y() {
4949

5050
define amdgpu_kernel void @kernel_workitem_id_y(ptr addrspace(1) %ptr) {
5151
; ALL-LABEL: 'kernel_workitem_id_y'
52-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
52+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
5353
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
5454
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
5555
;
5656
; SIZE-LABEL: 'kernel_workitem_id_y'
57-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
57+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
5858
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
5959
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
6060
;
@@ -65,11 +65,11 @@ define amdgpu_kernel void @kernel_workitem_id_y(ptr addrspace(1) %ptr) {
6565

6666
define i32 @workitem_id_z() {
6767
; ALL-LABEL: 'workitem_id_z'
68-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
68+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
6969
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
7070
;
7171
; SIZE-LABEL: 'workitem_id_z'
72-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
72+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.y()
7373
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
7474
;
7575
%result = call i32 @llvm.amdgcn.workitem.id.y()
@@ -78,12 +78,12 @@ define i32 @workitem_id_z() {
7878

7979
define amdgpu_kernel void @kernel_workitem_id_z(ptr addrspace(1) %ptr) {
8080
; ALL-LABEL: 'kernel_workitem_id_z'
81-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
81+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
8282
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
8383
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
8484
;
8585
; SIZE-LABEL: 'kernel_workitem_id_z'
86-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
86+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workitem.id.z()
8787
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store i32 %result, ptr addrspace(1) %ptr, align 4
8888
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
8989
;
@@ -94,11 +94,11 @@ define amdgpu_kernel void @kernel_workitem_id_z(ptr addrspace(1) %ptr) {
9494

9595
define i32 @workgroup_id_x() {
9696
; ALL-LABEL: 'workgroup_id_x'
97-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
97+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
9898
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
9999
;
100100
; SIZE-LABEL: 'workgroup_id_x'
101-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
101+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.x()
102102
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
103103
;
104104
%result = call i32 @llvm.amdgcn.workgroup.id.x()
@@ -107,11 +107,11 @@ define i32 @workgroup_id_x() {
107107

108108
define i32 @workgroup_id_y() {
109109
; ALL-LABEL: 'workgroup_id_y'
110-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
110+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
111111
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
112112
;
113113
; SIZE-LABEL: 'workgroup_id_y'
114-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
114+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
115115
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
116116
;
117117
%result = call i32 @llvm.amdgcn.workgroup.id.y()
@@ -120,11 +120,11 @@ define i32 @workgroup_id_y() {
120120

121121
define i32 @workgroup_id_z() {
122122
; ALL-LABEL: 'workgroup_id_z'
123-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
123+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
124124
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
125125
;
126126
; SIZE-LABEL: 'workgroup_id_z'
127-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
127+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.workgroup.id.y()
128128
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
129129
;
130130
%result = call i32 @llvm.amdgcn.workgroup.id.y()
@@ -133,11 +133,11 @@ define i32 @workgroup_id_z() {
133133

134134
define i32 @lds_kernel_id() {
135135
; ALL-LABEL: 'lds_kernel_id'
136-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
136+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
137137
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 %result
138138
;
139139
; SIZE-LABEL: 'lds_kernel_id'
140-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
140+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i32 @llvm.amdgcn.lds.kernel.id()
141141
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 %result
142142
;
143143
%result = call i32 @llvm.amdgcn.lds.kernel.id()
@@ -146,11 +146,11 @@ define i32 @lds_kernel_id() {
146146

147147
define ptr addrspace(4) @dispatch_ptr() {
148148
; ALL-LABEL: 'dispatch_ptr'
149-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
149+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
150150
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret ptr addrspace(4) %result
151151
;
152152
; SIZE-LABEL: 'dispatch_ptr'
153-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
153+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
154154
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret ptr addrspace(4) %result
155155
;
156156
%result = call ptr addrspace(4) @llvm.amdgcn.dispatch.ptr()
@@ -159,11 +159,11 @@ define ptr addrspace(4) @dispatch_ptr() {
159159

160160
define i64 @dispatch_id_() {
161161
; ALL-LABEL: 'dispatch_id_'
162-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
162+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
163163
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i64 %result
164164
;
165165
; SIZE-LABEL: 'dispatch_id_'
166-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
166+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call i64 @llvm.amdgcn.dispatch.id()
167167
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %result
168168
;
169169
%result = call i64 @llvm.amdgcn.dispatch.id()
@@ -172,11 +172,11 @@ define i64 @dispatch_id_() {
172172

173173
define ptr addrspace(4) @implicitarg_ptr() {
174174
; ALL-LABEL: 'implicitarg_ptr'
175-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
175+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
176176
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret ptr addrspace(4) %result
177177
;
178178
; SIZE-LABEL: 'implicitarg_ptr'
179-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
179+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
180180
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret ptr addrspace(4) %result
181181
;
182182
%result = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
@@ -185,11 +185,11 @@ define ptr addrspace(4) @implicitarg_ptr() {
185185

186186
define ptr addrspace(4) @queue_ptr() {
187187
; ALL-LABEL: 'queue_ptr'
188-
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
188+
; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
189189
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret ptr addrspace(4) %result
190190
;
191191
; SIZE-LABEL: 'queue_ptr'
192-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
192+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()
193193
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret ptr addrspace(4) %result
194194
;
195195
%result = call ptr addrspace(4) @llvm.amdgcn.queue.ptr()

0 commit comments

Comments
 (0)