[llvm] [RISCV] Treat insert_subvector into undef with index==0 as legal. (PR #109745)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 20:00:56 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/109745
Regardless of fixed and scalable type. We can always use subreg ops.
We don't need to do any container conversion.
>From 4b5ae32a7f93d14e540079bdce232ad1cef427ce Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 23 Sep 2024 19:52:57 -0700
Subject: [PATCH] [RISCV] Treat insert_subvector into undef with index==0 as
legal.
Regardless of fixed and scalable type. We can always use subreg ops.
We don't need to do any container conversion.
---
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 2aa89aca4c808d..15e4e4e65de773 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -10152,13 +10152,15 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
unsigned OrigIdx = Op.getConstantOperandVal(2);
const RISCVRegisterInfo *TRI = Subtarget.getRegisterInfo();
+ if (OrigIdx == 0 && Vec.isUndef())
+ return Op;
+
// We don't have the ability to slide mask vectors up indexed by their i1
// elements; the smallest we can do is i8. Often we are able to bitcast to
// equivalent i8 vectors. Note that when inserting a fixed-length vector
// into a scalable one, we might not necessarily have enough scalable
// elements to safely divide by 8: nxv1i1 = insert nxv1i1, v4i1 is valid.
- if (SubVecVT.getVectorElementType() == MVT::i1 &&
- (OrigIdx != 0 || !Vec.isUndef())) {
+ if (SubVecVT.getVectorElementType() == MVT::i1) {
if (VecVT.getVectorMinNumElements() >= 8 &&
SubVecVT.getVectorMinNumElements() >= 8) {
assert(OrigIdx % 8 == 0 && "Invalid index");
@@ -10196,8 +10198,6 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
// vector group up the full amount.
const auto VLen = Subtarget.getRealVLen();
if (SubVecVT.isFixedLengthVector() && !VLen) {
- if (OrigIdx == 0 && Vec.isUndef() && !VecVT.isFixedLengthVector())
- return Op;
MVT ContainerVT = VecVT;
if (VecVT.isFixedLengthVector()) {
ContainerVT = getContainerForFixedLengthVector(VecVT);
@@ -10208,11 +10208,6 @@ SDValue RISCVTargetLowering::lowerINSERT_SUBVECTOR(SDValue Op,
DAG.getUNDEF(ContainerVT), SubVec,
DAG.getVectorIdxConstant(0, DL));
- if (OrigIdx == 0 && Vec.isUndef() && VecVT.isFixedLengthVector()) {
- SubVec = convertFromScalableVector(VecVT, SubVec, DAG, Subtarget);
- return DAG.getBitcast(Op.getValueType(), SubVec);
- }
-
SDValue Mask =
getDefaultVLOps(VecVT, ContainerVT, DL, DAG, Subtarget).first;
// Set the vector length to only the number of elements we care about. Note
More information about the llvm-commits
mailing list