Skip to content

Commit 74e05dc

Browse files
committed
Make it so FreeZeroes is only used for loada instruction arguments, for now
1 parent a341494 commit 74e05dc

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ RISCVTTIImpl::getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
109109
return Cost;
110110
}
111111

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) {
114117
assert(Ty->isIntegerTy() &&
115118
"getIntImmCost can only estimate cost of materialising integers");
116119

@@ -119,10 +122,13 @@ InstructionCost RISCVTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty,
119122
return TTI::TCC_Free;
120123

121124
// 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);
126132
}
127133

128134
// 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,
180186
// misaligned accesses are not legal (experience shows constant hoisting
181187
// can sometimes be harmful in such cases).
182188
if (Idx == 1 || !Inst)
183-
return getIntImmCost(Imm, Ty, CostKind);
189+
return getIntImmCostImpl(getDataLayout(), getST(), Imm, Ty, CostKind,
190+
/*FreeZeroes=*/true);
184191

185192
StoreInst *ST = cast<StoreInst>(Inst);
186193
if (!getTLI()->allowsMemoryAccessForAlignment(
187194
Ty->getContext(), DL, getTLI()->getValueType(DL, Ty),
188195
ST->getPointerAddressSpace(), ST->getAlign()))
189196
return TTI::TCC_Free;
190197

191-
return getIntImmCost(Imm, Ty, CostKind);
198+
return getIntImmCostImpl(getDataLayout(), getST(), Imm, Ty, CostKind,
199+
/*FreeZeroes=*/true);
192200
}
193201
case Instruction::Load:
194202
// If the address is a constant, use the materialization cost.

llvm/test/CodeGen/RISCV/pr64935.ll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
define i1 @f() {
55
; CHECK-LABEL: f:
66
; CHECK: # %bb.0:
7-
; CHECK-NEXT: li a0, 1
7+
; CHECK-NEXT: lui a0, 524288
8+
; CHECK-NEXT: not a0, a0
9+
; CHECK-NEXT: sltiu a0, a0, 2
10+
; CHECK-NEXT: xori a0, a0, 1
811
; CHECK-NEXT: ret
912
%B25 = shl i64 4294967296, -9223372036854775808
1013
%B13 = sub i64 -1, -9223372036854775808

0 commit comments

Comments
 (0)