This is an archive of the discontinued LLVM Phabricator instance.

[SVE] Make getNumElements assert if the vector is scalable
AbandonedPublic

Authored by ctetreau on Mar 2 2020, 1:40 PM.

Details

Summary
VectorType inherits getNumElements from SequentialType. For a fixed

length vector, this returns the number of vector lanes. Previously, for
scalable vectors, this has returned the n for <vscale x n x ty>.
VectorType has another function getElementCount that returns a pair of
(bool, uint64_t) where the bool is true if the vector is scalable, and
min is the same as the return value of getNumElements. This form is
preferred because it provides the caller a way of knowing if the vector
is scalable.

There exists a large amount of code that calls getNumElements and

iterates over the returned value. This code is correct for fixed length
vectors, but is always a bug for scalable vectors since the number of
vector lanes in a scalable vector is unknown at compile time. To
mitigate bugs that are caused by this situation, we are changing the
behavior of getNumElements to assert that if the SequentialType instance
is a vector, that the vector is not scalable. This should be a minimally
intrusive change since very little code has been written that uses
getNumElements correctly.

Diff Detail

Event Timeline

ctetreau created this revision.Mar 2 2020, 1:40 PM
Herald added a project: Restricted Project. · View Herald Transcript
ctetreau updated this revision to Diff 247722.Mar 2 2020, 1:43 PM

fix commit message formatting

https://reviews.llvm.org/B47829 says there are regression test failures; we can't merge until those are fixed.

I think this makes sense.

llvm/lib/IR/Type.cpp
584

Please make this inline.

ctetreau marked an inline comment as done.Mar 2 2020, 3:24 PM

I'm working through the test failures right now. It may be a little bit before I get a chance to update this one.

llvm/lib/IR/Type.cpp
584

I'll move it to the header

dancgr added a subscriber: dancgr.Mar 4 2020, 2:39 PM
ctetreau abandoned this revision.Apr 8 2020, 3:45 PM