Skip to content

Commit 99551af

Browse files
Load/Store instructions should use getMemoryOpCost
1 parent d508308 commit 99551af

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,11 +1692,40 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
16921692
// counterpart when the vector length argument is smaller than the maximum
16931693
// vector length.
16941694
if (VPIntrinsic::isVPIntrinsic(ICA.getID())) {
1695-
std::optional<Intrinsic::ID> FOp =
1695+
std::optional<unsigned> FOp =
16961696
VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
1697-
if (FOp)
1697+
if (FOp) {
1698+
if (ICA.getID() == Intrinsic::vp_load) {
1699+
Align Alignment = isa_and_nonnull<VPIntrinsic>(ICA.getInst())
1700+
? cast<VPIntrinsic>(ICA.getInst())
1701+
->getPointerAlignment()
1702+
.valueOrOne()
1703+
: Align(1);
1704+
unsigned AS = ICA.getArgs().size() >= 1 &&
1705+
isa<PointerType>(ICA.getArgs()[0]->getType())
1706+
? cast<PointerType>(ICA.getArgs()[0]->getType())
1707+
->getAddressSpace()
1708+
: 0;
1709+
return thisT()->getMemoryOpCost(*FOp, ICA.getReturnType(), Alignment,
1710+
AS, CostKind);
1711+
} else if (ICA.getID() == Intrinsic::vp_store) {
1712+
Align Alignment = isa_and_nonnull<VPIntrinsic>(ICA.getInst())
1713+
? cast<VPIntrinsic>(ICA.getInst())
1714+
->getPointerAlignment()
1715+
.valueOrOne()
1716+
: Align(1);
1717+
unsigned AS = ICA.getArgs().size() >= 2 &&
1718+
isa<PointerType>(ICA.getArgs()[1]->getType())
1719+
? cast<PointerType>(ICA.getArgs()[1]->getType())
1720+
->getAddressSpace()
1721+
: 0;
1722+
return thisT()->getMemoryOpCost(*FOp, Args[0]->getType(), Alignment,
1723+
AS, CostKind);
1724+
}
1725+
// TODO: Support other kinds of Intrinsics (i.e. reductions)
16981726
return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(),
16991727
CostKind);
1728+
}
17001729

17011730
std::optional<Intrinsic::ID> FID =
17021731
VPIntrinsic::getFunctionalIntrinsicIDForVP(ICA.getID());

llvm/test/Analysis/CostModel/RISCV/gep.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ define void @non_foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) {
270270
; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %4 = getelementptr i8, ptr %base, i32 42
271271
; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x4 = call <2 x i8> @llvm.masked.expandload.v2i8(ptr %4, <2 x i1> undef, <2 x i8> undef)
272272
; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %5 = getelementptr i8, ptr %base, i32 42
273-
; RVI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef)
273+
; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef)
274274
; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %6 = getelementptr i8, ptr %base, i32 42
275275
; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x6 = call <2 x i8> @llvm.experimental.vp.strided.load.v2i8.p0.i64(ptr %6, i64 undef, <2 x i1> undef, i32 undef)
276276
; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %7 = getelementptr i8, ptr %base, i32 42
@@ -340,7 +340,7 @@ define void @foldable_vector_uses(ptr %base, <2 x ptr> %base.vec) {
340340
; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %4 = getelementptr i8, ptr %base, i32 0
341341
; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x4 = call <2 x i8> @llvm.masked.expandload.v2i8(ptr %4, <2 x i1> undef, <2 x i8> undef)
342342
; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %5 = getelementptr i8, ptr %base, i32 0
343-
; RVI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef)
343+
; RVI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %x5 = call <2 x i8> @llvm.vp.load.v2i8.p0(ptr %5, <2 x i1> undef, i32 undef)
344344
; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %6 = getelementptr i8, ptr %base, i32 0
345345
; RVI-NEXT: Cost Model: Found an estimated cost of 5 for instruction: %x6 = call <2 x i8> @llvm.experimental.vp.strided.load.v2i8.p0.i64(ptr %6, i64 undef, <2 x i1> undef, i32 undef)
346346
; RVI-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %7 = getelementptr i8, ptr %base, i32 0

0 commit comments

Comments
 (0)