From b44d2c977ce2e5dbf9f227bd6ade5d85ae69a463 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 6 Apr 2026 09:58:04 -0700 Subject: [PATCH] [RISCV] Use a vector MemVT when converting store+extractelt into a vector store. (#190107) This is needed so that `allowsMemoryAccessForAlignment` checks for unaligned vector memory support instead of unaligned scalar memory support when called from `RISCVTargetLowering::expandUnalignedVPStore` While there remove incorrect setting of the truncating store flag on the vector instruction. And restrict the transform to simple stores since we don't have tests for volatile or atomic. Fixes #189037 --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 10 ++++++---- llvm/test/CodeGen/RISCV/rvv/pr189037.ll | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 llvm/test/CodeGen/RISCV/rvv/pr189037.ll diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index d00b734f6450..51d8c1ef2460 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -22378,16 +22378,18 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N, SDValue Src = Val.getOperand(0); MVT VecVT = Src.getSimpleValueType(); // VecVT should be scalable and memory VT should match the element type. - if (!Store->isIndexed() && VecVT.isScalableVector() && - MemVT == VecVT.getVectorElementType()) { + if (!Store->isIndexed() && Store->isSimple() && + VecVT.isScalableVector() && MemVT == VecVT.getVectorElementType()) { SDLoc DL(N); MVT MaskVT = getMaskTypeFor(VecVT); + // Create a vector memory VT so allowsMisalignedMemoryAccesses will + // work correctly. + MemVT = EVT::getVectorVT(*DAG.getContext(), MemVT, 1); return DAG.getStoreVP( Store->getChain(), DL, Src, Store->getBasePtr(), Store->getOffset(), DAG.getConstant(1, DL, MaskVT), DAG.getConstant(1, DL, Subtarget.getXLenVT()), MemVT, - Store->getMemOperand(), Store->getAddressingMode(), - Store->isTruncatingStore(), /*IsCompress*/ false); + Store->getMemOperand(), Store->getAddressingMode()); } } diff --git a/llvm/test/CodeGen/RISCV/rvv/pr189037.ll b/llvm/test/CodeGen/RISCV/rvv/pr189037.ll new file mode 100644 index 000000000000..b0165d2073f1 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/pr189037.ll @@ -0,0 +1,14 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 +; RUN: llc < %s -mtriple=riscv64 -mattr=+v,+unaligned-scalar-mem | FileCheck %s + +; We should produce a vse8 due to the align 1 +define void @test(ptr %out, <1 x i16> %v) { +; CHECK-LABEL: test: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetivli zero, 2, e8, mf4, ta, ma +; CHECK-NEXT: vse8.v v8, (a0) +; CHECK-NEXT: ret + %coerce.val.ii.i = extractelement <1 x i16> %v, i64 0 + store i16 %coerce.val.ii.i, ptr %out, align 1 + ret void +}