[PATCH] D157603: [RISCV] Truncate constants to EltSize when combine store of BUILD_VECTOR

Michael Maitland via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 10:47:22 PDT 2023

michaelmaitland added inline comments.

Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:13486
-        NewC.insertBits(Val.getConstantOperandAPInt(i),
-                        i * Val.getScalarValueSizeInBits());
+        NewC.insertBits(Val.getConstantOperandAPInt(i).trunc(EltSize),
+                        i * EltSize);
craig.topper wrote:
> michaelmaitland wrote:
> > What happens if we're truncating a constant that is larger than EltSize?
> BUILD_VECTOR nodes have a vector result and scalar operands. The scalar operands go through type legalization before the BUILD_VECTOR is lowered. Any scalar operand that is smaller than XLen will be type legalized to XLen by any extending. The semantics of BUILD_VECTOR is that the extra bits of the input aren't supposed to be used. They just exist to make all the types legal. It is safe to drop the extra bits here.
> On RV32, it is possible for type legalization to see a vXi64 BUILD_VECTOR with i64 scalar operands that need to be legalized to i32. In that case type legalization will create a v2Xi32 BUILD_VECTOR with twice as many elements and i32 scalar operands followed by a bitcast to vXi64.
> It is never possible for a BUILD_VECTOR to have a scalar operand that is smaller than the element size of the result type.
Why not change the i64 operand to BUILD_VECTOR to i32 before we get here if thats the case?

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list