This is an archive of the discontinued LLVM Phabricator instance.

[SVE] In LoopIdiomRecognize::isLegalStore bail out for scalable vectors
ClosedPublic

Authored by david-arm on Sep 10 2020, 12:55 AM.

Details

Summary

The function LoopIdiomRecognize::isLegalStore looks for stores in loops
that could be transformed into memset or memcpy. However, the algorithm
currently requires that we know how big the store is at runtime, i.e.
that the store size will not overflow an unsigned integer. For scalable
vectors we cannot guarantee this so I have changed the code to bail out
for now. In addition, even if we add a way to query the maximum value of
vscale in future we will still need to update the algorithm to cope with
non-constant strides. The additional cost associated with calculating
the memset and memcpy arguments will need to be taken into account as
well.

This patch also fixes up an implicit TypeSize -> uint64_t cast,
thereby removing a warning. I've added tests here showing a fixed
width vector loop being transformed into memcpy, and a scalable
vector loop remaining unchanged:

Transforms/LoopIdiom/memcpy-vectors.ll

Diff Detail

Event Timeline

david-arm created this revision.Sep 10 2020, 12:55 AM
david-arm requested review of this revision.Sep 10 2020, 12:55 AM
efriedma added inline comments.Sep 10 2020, 7:00 PM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
475

Do you have any idea why we're checking whether the store overflows an unsigned?

david-arm added inline comments.Sep 10 2020, 11:29 PM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
475

Hi @efriedma, honestly I don't know why we check for overflow here, although I assumed it was probably because they wanted to multiply the store size by something else at some point, so want to ensure it fits in a 64-bit value. That's a pure guess though! I can look into this further if you want, but there is still the issue of non-constant strides and extra maths to deal with.

efriedma accepted this revision.Sep 11 2020, 3:59 PM

LGTM

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
475

In that case, please simplify the comment to just say the code needs changes to deal with a non-constant stride.

This revision is now accepted and ready to land.Sep 11 2020, 3:59 PM