[llvm] [RISCV][GISel] Don't custom legalize load/store of vector of pointers if ELEN < XLEN. (PR #101565)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 14:58:42 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/101565
We need to have elements than can hold a pointer sized element.
No test because it crashes in LowerLoad or LowerStore now which
needs to be addressed separately.
I also reordered things so all the vector load/store stuff is together.
>From ff934ae6fa47d85689b2ef2f2e19a88d1d9bafd2 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 1 Aug 2024 14:41:43 -0700
Subject: [PATCH 1/2] [RISCV][GISel] Group the vector load/store legalizer
actions together.
---
.../Target/RISCV/GISel/RISCVLegalizerInfo.cpp | 59 ++++++++++---------
1 file changed, 31 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 4e583d96335d9..ad36f822accef 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -285,7 +285,22 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
{s32, p0, s16, 16},
{s32, p0, s32, 32},
{p0, p0, sXLen, XLen}});
- if (ST.hasVInstructions())
+ auto &ExtLoadActions =
+ getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD})
+ .legalForTypesWithMemDesc({{s32, p0, s8, 8}, {s32, p0, s16, 16}});
+ if (XLen == 64) {
+ LoadStoreActions.legalForTypesWithMemDesc({{s64, p0, s8, 8},
+ {s64, p0, s16, 16},
+ {s64, p0, s32, 32},
+ {s64, p0, s64, 64}});
+ ExtLoadActions.legalForTypesWithMemDesc(
+ {{s64, p0, s8, 8}, {s64, p0, s16, 16}, {s64, p0, s32, 32}});
+ } else if (ST.hasStdExtD()) {
+ LoadStoreActions.legalForTypesWithMemDesc({{s64, p0, s64, 64}});
+ }
+
+ // Vector loads/stores.
+ if (ST.hasVInstructions()) {
LoadStoreActions.legalForTypesWithMemDesc({{nxv2s8, p0, nxv2s8, 8},
{nxv4s8, p0, nxv4s8, 8},
{nxv8s8, p0, nxv8s8, 8},
@@ -302,38 +317,26 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
{nxv8s32, p0, nxv8s32, 32},
{nxv16s32, p0, nxv16s32, 32}});
- auto &ExtLoadActions =
- getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD})
- .legalForTypesWithMemDesc({{s32, p0, s8, 8}, {s32, p0, s16, 16}});
- if (XLen == 64) {
- LoadStoreActions.legalForTypesWithMemDesc({{s64, p0, s8, 8},
- {s64, p0, s16, 16},
- {s64, p0, s32, 32},
- {s64, p0, s64, 64}});
- ExtLoadActions.legalForTypesWithMemDesc(
- {{s64, p0, s8, 8}, {s64, p0, s16, 16}, {s64, p0, s32, 32}});
- } else if (ST.hasStdExtD()) {
- LoadStoreActions.legalForTypesWithMemDesc({{s64, p0, s64, 64}});
- }
- if (ST.hasVInstructions() && ST.getELen() == 64)
- LoadStoreActions.legalForTypesWithMemDesc({{nxv1s8, p0, nxv1s8, 8},
- {nxv1s16, p0, nxv1s16, 16},
- {nxv1s32, p0, nxv1s32, 32}});
+ if (ST.getELen() == 64)
+ LoadStoreActions.legalForTypesWithMemDesc({{nxv1s8, p0, nxv1s8, 8},
+ {nxv1s16, p0, nxv1s16, 16},
+ {nxv1s32, p0, nxv1s32, 32}});
- if (ST.hasVInstructionsI64())
- LoadStoreActions.legalForTypesWithMemDesc({{nxv1s64, p0, nxv1s64, 64},
+ if (ST.hasVInstructionsI64())
+ LoadStoreActions.legalForTypesWithMemDesc({{nxv1s64, p0, nxv1s64, 64},
+ {nxv2s64, p0, nxv2s64, 64},
+ {nxv4s64, p0, nxv4s64, 64},
+ {nxv8s64, p0, nxv8s64, 64}});
- {nxv2s64, p0, nxv2s64, 64},
- {nxv4s64, p0, nxv4s64, 64},
- {nxv8s64, p0, nxv8s64, 64}});
+ // we will take the custom lowering logic if we have scalable vector types
+ // with non-standard alignments
+ LoadStoreActions.customIf(
+ LegalityPredicates::any(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
+ typeIsLegalPtrVec(0, PtrVecTys, ST)));
+ }
LoadStoreActions.widenScalarToNextPow2(0, /* MinSize = */ 8)
.lowerIfMemSizeNotByteSizePow2()
- // we will take the custom lowering logic if we have scalable vector types
- // with non-standard alignments
- .customIf(LegalityPredicate(
- LegalityPredicates::any(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
- typeIsLegalPtrVec(0, PtrVecTys, ST))))
.clampScalar(0, s32, sXLen)
.lower();
>From 42b3d2311576bac10c7d2a9001b9c1c2da8de681 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 1 Aug 2024 14:55:14 -0700
Subject: [PATCH 2/2] [RISCV][GISel] Don't custom legalize load/store of vector
of pointers if ELEN < XLEN.
We need to have elements than can hold a pointer sized element.
No test because it crashes in LowerLoad or LowerStore now which
needs to be addressed separately.
---
llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index ad36f822accef..74bfe8b838af7 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -330,9 +330,11 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
// we will take the custom lowering logic if we have scalable vector types
// with non-standard alignments
- LoadStoreActions.customIf(
- LegalityPredicates::any(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
- typeIsLegalPtrVec(0, PtrVecTys, ST)));
+ LoadStoreActions.customIf(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST));
+
+ // Pointers require that XLen sized elements are legal.
+ if (XLen <= ST.getELen())
+ LoadStoreActions.customIf(typeIsLegalPtrVec(0, PtrVecTys, ST));
}
LoadStoreActions.widenScalarToNextPow2(0, /* MinSize = */ 8)
More information about the llvm-commits
mailing list