This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix FoldConstantVectorArithmetic for scalable vectors
ClosedPublic

Authored by david-arm on May 5 2020, 7:55 AM.

Details

Summary

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

Diff Detail

Event Timeline

david-arm created this revision.May 5 2020, 7:55 AM
RKSimon added a subscriber: RKSimon.May 5 2020, 8:12 AM

You might want to add something similar to FoldConstantArithmetic as FoldConstantVectorArithmetic will be soon folded into it.

david-arm updated this revision to Diff 262300.May 6 2020, 12:15 AM
david-arm edited the summary of this revision. (Show Details)May 6 2020, 1:11 AM

The code path I have changed is defended by this existing test:

CodeGen/AArch64/sve-int-arith.ll

Hi @david-arm ,

NIT1: in what way does the test defend the change? The test is successful with and without your changes, so I think this comment in the commit message is misleading I know you have added this to remove the warnings generated when using getVectorNumElements on scalable vectors, so my personal preference is that there is nothing to defend here, it is just a sensible change to do to avoid entering code that makes invalid assumption on the underlying VTs. I think you can remove the paragraph I quoted from the commit message.

Grazie!

Francesco

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4918

NIT2: In the spirit of NIT1, I think you should add the TODO only on the part that requires implementing constant folding for splat into scalable vectors, as follows:

// Custom code for scalable vectors, as all the folds below assume a fixed width vector.
// TODO: bail off for now, however we should be able to do constant folds involving splats to scalable vectors too.

This way, once the TODO is done and removed, we will not loose the information on why the scalable vectors require custom code.

5001–5003

Ditto.

david-arm marked an inline comment as done.May 12 2020, 6:48 AM

Re NIT1: all I mean is that these tests exercise these code paths. Previously we were fortunate enough that it just "worked", but now I've added to *ensure* that it is guaranteed to work. So in that sense the tests are testing that we don't do something silly in the places I've changed.

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4918

Hi Francesco, I'm sorry but I don't quite follow here. All the code below this is not custom code for scalable vectors. Even if we later fixed the code below to work for both fixed and scalable, it still won't be specific to scalable.

fpetrogalli accepted this revision.May 13 2020, 7:13 AM

LGTM, please consider adding those two comments I mentioned in my last review before submitting.

Francesco

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4918

I wanted to make sure that there was a clear cut between the code for scalable vectors and the code for fixed width vector. So maybe it makes sense to leave the comment as it is, and just modify line 4952 to say:

// For fixed width vectors, extract each constant element and fold them individually.
5008

Same here, add a comment saying that from now on the vectors are assumed to be fixed width.

This revision is now accepted and ready to land.May 13 2020, 7:13 AM
david-arm edited the summary of this revision. (Show Details)
david-arm marked 2 inline comments as done.
fpetrogalli accepted this revision.May 15 2020, 5:36 AM
This revision was automatically updated to reflect the committed changes.