Skip to content

Commit fb1c55b

Browse files
committed
[CodeGen] Fix FoldConstantVectorArithmetic for scalable vectors
For now I have changed FoldConstantVectorArithmetic to return early if we encounter a scalable vector, since the subsequent code assumes you can perform lane-wise constant folds. However, in future work we should be able to extend this to look at splats of a constant value and fold those if possible. I have also added the same code to FoldConstantArithmetic, since that deals with vectors too. The warnings I fixed in this patch were being generated by this existing test: CodeGen/AArch64/sve-int-arith.ll Differential Revision: https://reviews.llvm.org/D79421
1 parent 8c24f33 commit fb1c55b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,8 +4915,14 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
49154915
if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(N2))
49164916
return FoldSymbolOffset(Opcode, VT, GA, N1);
49174917

4918-
// For vectors, extract each constant element and fold them individually.
4919-
// Either input may be an undef value.
4918+
// TODO: All the folds below are performed lane-by-lane and assume a fixed
4919+
// vector width, however we should be able to do constant folds involving
4920+
// splat vector nodes too.
4921+
if (VT.isScalableVector())
4922+
return SDValue();
4923+
4924+
// For fixed width vectors, extract each constant element and fold them
4925+
// individually. Either input may be an undef value.
49204926
auto *BV1 = dyn_cast<BuildVectorSDNode>(N1);
49214927
if (!BV1 && !N1->isUndef())
49224928
return SDValue();
@@ -4992,6 +4998,13 @@ SDValue SelectionDAG::FoldConstantVectorArithmetic(unsigned Opcode,
49924998
if (!VT.isVector())
49934999
return SDValue();
49945000

5001+
// TODO: All the folds below are performed lane-by-lane and assume a fixed
5002+
// vector width, however we should be able to do constant folds involving
5003+
// splat vector nodes too.
5004+
if (VT.isScalableVector())
5005+
return SDValue();
5006+
5007+
// From this point onwards all vectors are assumed to be fixed width.
49955008
unsigned NumElts = VT.getVectorNumElements();
49965009

49975010
auto IsScalarOrSameVectorSize = [&](const SDValue &Op) {

0 commit comments

Comments
 (0)