@@ -109,8 +109,11 @@ RISCVTTIImpl::getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
109
109
return Cost;
110
110
}
111
111
112
- InstructionCost RISCVTTIImpl::getIntImmCost (const APInt &Imm, Type *Ty,
113
- TTI::TargetCostKind CostKind) {
112
+ static InstructionCost getIntImmCostImpl (const DataLayout &DL,
113
+ const RISCVSubtarget *ST,
114
+ const APInt &Imm, Type *Ty,
115
+ TTI::TargetCostKind CostKind,
116
+ bool FreeZeroes) {
114
117
assert (Ty->isIntegerTy () &&
115
118
" getIntImmCost can only estimate cost of materialising integers" );
116
119
@@ -119,10 +122,13 @@ InstructionCost RISCVTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty,
119
122
return TTI::TCC_Free;
120
123
121
124
// Otherwise, we check how many instructions it will take to materialise.
122
- const DataLayout &DL = getDataLayout ();
123
- return RISCVMatInt::getIntMatCost (Imm, DL.getTypeSizeInBits (Ty), *getST (),
124
- /* CompressionCost=*/ false ,
125
- /* FreeZeroes=*/ true );
125
+ return RISCVMatInt::getIntMatCost (Imm, DL.getTypeSizeInBits (Ty), *ST,
126
+ /* CompressionCost=*/ false , FreeZeroes);
127
+ }
128
+
129
+ InstructionCost RISCVTTIImpl::getIntImmCost (const APInt &Imm, Type *Ty,
130
+ TTI::TargetCostKind CostKind) {
131
+ return getIntImmCostImpl (getDataLayout (), getST (), Imm, Ty, CostKind, false );
126
132
}
127
133
128
134
// Look for patterns of shift followed by AND that can be turned into a pair of
@@ -180,15 +186,17 @@ InstructionCost RISCVTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
180
186
// misaligned accesses are not legal (experience shows constant hoisting
181
187
// can sometimes be harmful in such cases).
182
188
if (Idx == 1 || !Inst)
183
- return getIntImmCost (Imm, Ty, CostKind);
189
+ return getIntImmCostImpl (getDataLayout (), getST (), Imm, Ty, CostKind,
190
+ /* FreeZeroes=*/ true );
184
191
185
192
StoreInst *ST = cast<StoreInst>(Inst);
186
193
if (!getTLI ()->allowsMemoryAccessForAlignment (
187
194
Ty->getContext (), DL, getTLI ()->getValueType (DL, Ty),
188
195
ST->getPointerAddressSpace (), ST->getAlign ()))
189
196
return TTI::TCC_Free;
190
197
191
- return getIntImmCost (Imm, Ty, CostKind);
198
+ return getIntImmCostImpl (getDataLayout (), getST (), Imm, Ty, CostKind,
199
+ /* FreeZeroes=*/ true );
192
200
}
193
201
case Instruction::Load:
194
202
// If the address is a constant, use the materialization cost.
0 commit comments