Skip to content

Commit fc7b407

Browse files
sdesmalen-armmemfrob
authored andcommitted
[CostModel] Handle CTLZ and CCTZ in getTypeBasedIntrinsicInstrCost
Reviewed By: dmgreen Differential Revision: https://reviews.llvm.org/D95355
1 parent 57ce053 commit fc7b407

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,12 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
17471747
// library call but still not a cheap instruction.
17481748
SingleCallCost = TargetTransformInfo::TCC_Expensive;
17491749
break;
1750-
// FIXME: ctlz, cttz, ...
1750+
case Intrinsic::ctlz:
1751+
ISDs.push_back(ISD::CTLZ);
1752+
break;
1753+
case Intrinsic::cttz:
1754+
ISDs.push_back(ISD::CTTZ);
1755+
break;
17511756
case Intrinsic::bswap:
17521757
ISDs.push_back(ISD::BSWAP);
17531758
break;

llvm/test/Analysis/CostModel/ARM/intrinsic-cost-kinds.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ define void @fmaximum(float %a, float %b, <16 x float> %va, <16 x float> %vb) {
173173
define void @cttz(i32 %a, <16 x i32> %va) {
174174
; THRU-LABEL: 'cttz'
175175
; THRU-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s = call i32 @llvm.cttz.i32(i32 %a, i1 false)
176-
; THRU-NEXT: Cost Model: Found an estimated cost of 528 for instruction: %v = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %va, i1 false)
176+
; THRU-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %va, i1 false)
177177
; THRU-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
178178
;
179179
; LATE-LABEL: 'cttz'
@@ -183,12 +183,12 @@ define void @cttz(i32 %a, <16 x i32> %va) {
183183
;
184184
; SIZE-LABEL: 'cttz'
185185
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s = call i32 @llvm.cttz.i32(i32 %a, i1 false)
186-
; SIZE-NEXT: Cost Model: Found an estimated cost of 528 for instruction: %v = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %va, i1 false)
186+
; SIZE-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %va, i1 false)
187187
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
188188
;
189189
; SIZE_LATE-LABEL: 'cttz'
190190
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s = call i32 @llvm.cttz.i32(i32 %a, i1 false)
191-
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 528 for instruction: %v = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %va, i1 false)
191+
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v = call <16 x i32> @llvm.cttz.v16i32(<16 x i32> %va, i1 false)
192192
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
193193
;
194194
%s = call i32 @llvm.cttz.i32(i32 %a, i1 false)
@@ -199,7 +199,7 @@ define void @cttz(i32 %a, <16 x i32> %va) {
199199
define void @ctlz(i32 %a, <16 x i32> %va) {
200200
; THRU-LABEL: 'ctlz'
201201
; THRU-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s = call i32 @llvm.ctlz.i32(i32 %a, i1 true)
202-
; THRU-NEXT: Cost Model: Found an estimated cost of 528 for instruction: %v = call <16 x i32> @llvm.ctlz.v16i32(<16 x i32> %va, i1 true)
202+
; THRU-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v = call <16 x i32> @llvm.ctlz.v16i32(<16 x i32> %va, i1 true)
203203
; THRU-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
204204
;
205205
; LATE-LABEL: 'ctlz'
@@ -209,12 +209,12 @@ define void @ctlz(i32 %a, <16 x i32> %va) {
209209
;
210210
; SIZE-LABEL: 'ctlz'
211211
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s = call i32 @llvm.ctlz.i32(i32 %a, i1 true)
212-
; SIZE-NEXT: Cost Model: Found an estimated cost of 528 for instruction: %v = call <16 x i32> @llvm.ctlz.v16i32(<16 x i32> %va, i1 true)
212+
; SIZE-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v = call <16 x i32> @llvm.ctlz.v16i32(<16 x i32> %va, i1 true)
213213
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
214214
;
215215
; SIZE_LATE-LABEL: 'ctlz'
216216
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %s = call i32 @llvm.ctlz.i32(i32 %a, i1 true)
217-
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 528 for instruction: %v = call <16 x i32> @llvm.ctlz.v16i32(<16 x i32> %va, i1 true)
217+
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 8 for instruction: %v = call <16 x i32> @llvm.ctlz.v16i32(<16 x i32> %va, i1 true)
218218
; SIZE_LATE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
219219
;
220220
%s = call i32 @llvm.ctlz.i32(i32 %a, i1 true)

0 commit comments

Comments
 (0)