[PATCH] D157603: [RISCV] Truncate constants to EleSize when combine store of BUILD_VECTOR
Wang Pengcheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 10 04:48:45 PDT 2023
wangpc created this revision.
wangpc added reviewers: luke, craig.topper, reames.
Herald added subscribers: jobnoorman, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
wangpc requested review of this revision.
Herald added subscribers: llvm-commits, eopXD, MaskRay.
Herald added a project: LLVM.
The constants can be with larger bit width, so we need to truncate
it to EleSize or we will exceed the width of fixed-length vector.
Fixes #64588
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157603
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/pr64588.ll
Index: llvm/test/CodeGen/RISCV/rvv/pr64588.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/pr64588.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc < %s -mtriple riscv64 -mattr=+zve64x | FileCheck %s
+
+define void @bar(ptr %p, ptr %q) {
+; CHECK-LABEL: bar:
+; CHECK: # %bb.0:
+; CHECK-NEXT: sd zero, 0(a0)
+; CHECK-NEXT: sd zero, 8(a0)
+; CHECK-NEXT: ret
+ %v = insertelement <64 x i64> zeroinitializer, i64 0, i32 1
+ %trunc = trunc <64 x i64> %v to <64 x i1>
+ %p1 = getelementptr i8, ptr %p, i32 0
+ %p2 = getelementptr i8, ptr %p, i32 8
+ store <64 x i1> %trunc, ptr %p1
+ store <8 x i8> zeroinitializer, ptr %p2
+ ret void
+}
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -13475,11 +13475,12 @@
ISD::isBuildVectorOfConstantSDNodes(Val.getNode())) {
// Get the constant vector bits
APInt NewC(Val.getValueSizeInBits(), 0);
+ uint64_t EleSize = Val.getScalarValueSizeInBits();
for (unsigned i = 0; i < Val.getNumOperands(); i++) {
if (Val.getOperand(i).isUndef())
continue;
- NewC.insertBits(Val.getConstantOperandAPInt(i),
- i * Val.getScalarValueSizeInBits());
+ NewC.insertBits(Val.getConstantOperandAPInt(i).trunc(EleSize),
+ i * EleSize);
}
MVT NewVT = MVT::getIntegerVT(MemVT.getSizeInBits());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157603.548976.patch
Type: text/x-patch
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230810/aa13c7bc/attachment-0001.bin>
More information about the llvm-commits
mailing list