This is an archive of the discontinued LLVM Phabricator instance.

[ValueTypes] Add support for scalable EVTs
ClosedPublic

Authored by c-rhodes on Mar 5 2020, 4:13 AM.

Details

Summary

Changes:

  • Remove a bunch of asserts checking for unsupported scalable types and add some more now that they are supported.
  • Propagate the scalable flag where necessary.
  • Add another EVT::getExtendedVectorVT method that takes an ElementCount parameter.
  • Add EVT::isExtendedScalableVector and EVT::getExtendedVectorElementCount - latter is currently unused.

Diff Detail

Event Timeline

c-rhodes created this revision.Mar 5 2020, 4:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2020, 4:13 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
c-rhodes updated this revision to Diff 248450.Mar 5 2020, 5:27 AM

Fix warnings reported by Harbor.

Please post patches with full context (-U10000)

llvm/include/llvm/CodeGen/ValueTypes.h
265

Not sure changing getVectorNumElements like this makes sense.

c-rhodes updated this revision to Diff 248662.Mar 6 2020, 1:39 AM

Added context.

c-rhodes updated this revision to Diff 248677.Mar 6 2020, 2:36 AM

Remove check for isScalableVector in getVectorNumElements.

Please post patches with full context (-U10000)

I've updated the patch, sorry about that.

llvm/include/llvm/CodeGen/ValueTypes.h
265

I've removed this change, there was just one place in SelectionDAGBuilder I had to fix up to call getVectorElementCount. I had a chat with Graham and he suggested it would be good to check if it's a fixed-length vector here, maybe by having something similar to the MVT isFixedLengthVector on the EVT which could call MVT::isFixedLengthVector if it's a SimplyTy or check it's not a scalable vector otherwise.

efriedma added inline comments.Mar 11 2020, 7:34 PM
llvm/include/llvm/CodeGen/ValueTypes.h
265

Yes, we want to catch incorrect use of getNumElements in both IR and in SelectionDAG.

c-rhodes added inline comments.Mar 12 2020, 4:49 AM
llvm/include/llvm/CodeGen/ValueTypes.h
265

Is this something we can implement going forward or should this be handled before landing this patch?

efriedma added inline comments.Mar 12 2020, 1:42 PM
llvm/include/llvm/CodeGen/ValueTypes.h
265

If it's easy, might as well handle it here, if there's some non-obvious complication, I'd be fine with putting it off.

c-rhodes added inline comments.Mar 17 2020, 5:15 AM
llvm/include/llvm/CodeGen/ValueTypes.h
265

I've tested the following patch downstream:

diff --git a/llvm/include/llvm/CodeGen/ValueTypes.h b/llvm/include/llvm/CodeGen/ValueTypes.h
index 72e0cc8..c2db003 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.h
+++ b/llvm/include/llvm/CodeGen/ValueTypes.h
@@ -152,6 +152,10 @@ namespace llvm {
       return isSimple() ? V.isScalableVector() : isExtendedScalableVector();
     }

+    bool isFixedLengthVector() const {
+      return isSimple() ? V.isFixedLengthVector() : isExtendedFixedLengthVector();
+    }
+
     /// Return true if this is a 16-bit vector type.
     bool is16BitVector() const {
       return isSimple() ? V.is16BitVector() : isExtended16BitVector();
@@ -262,7 +266,7 @@ namespace llvm {

     /// Given a vector type, return the number of elements it contains.
     unsigned getVectorNumElements() const {
-      assert(isVector() && "Invalid vector type!");
+      assert(isFixedLengthVector() && "Invalid vector type!");
       if (isSimple())
         return V.getVectorNumElements();
       return getExtendedVectorNumElements();
@@ -432,6 +436,7 @@ namespace llvm {
     bool isExtended1024BitVector() const LLVM_READONLY;
     bool isExtended2048BitVector() const LLVM_READONLY;
     bool isExtendedScalableVector() const LLVM_READONLY;
+    bool isExtendedFixedLengthVector() const LLVM_READONLY;
     EVT getExtendedVectorElementType() const;
     unsigned getExtendedVectorNumElements() const LLVM_READONLY;
     ElementCount getExtendedVectorElementCount() const LLVM_READONLY;
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index dcb3a88..a2a35e2 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -106,6 +106,10 @@ bool EVT::isExtendedScalableVector() const {
   return isExtendedVector() && cast<VectorType>(LLVMTy)->isScalable();
 }

+bool EVT::isExtendedFixedLengthVector() const {
+  return isExtendedVector() && !cast<VectorType>(LLVMTy)->isScalable();
+}
+
 EVT EVT::getExtendedVectorElementType() const {
   assert(isExtended() && "Type is not extended!");
   return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());

After running check-all there are a lot of failures. Ideally we want to get rid of getVectorNumElements but a quick grep shows there's >450 uses of it in lib/CodeGen and lib/Target/AArch64 alone. All of these probably aren't EVT::getVectorNumElements but having looked through some of the errors downstream there's cases like those in SelectionDAGBuilder::visitShuffleVector that need fixing up.

I think this assert is similar to the implicit cast of TypeSize -> uint64_t which Sander addressed with a warning in D75297. Being restrictive here is also going to trigger a lot of asserts, perhaps we can also emit a warning here?

efriedma added inline comments.Mar 17 2020, 10:15 AM
llvm/include/llvm/CodeGen/ValueTypes.h
265

That makes sense, but let's do it as a separate patch.

c-rhodes marked an inline comment as done.Mar 18 2020, 11:59 AM
c-rhodes added inline comments.
llvm/include/llvm/CodeGen/ValueTypes.h
265

I've created a separate patch D76376.

efriedma accepted this revision.Mar 18 2020, 12:33 PM

LGTM with one minor comment

llvm/include/llvm/CodeGen/ValueTypes.h
263

isVector() || isScalableVector() is the same thing as isVector(), I think?

This revision is now accepted and ready to land.Mar 18 2020, 12:33 PM
c-rhodes marked an inline comment as not done.Mar 19 2020, 2:26 AM

Thanks for reviewing Eli!

llvm/include/llvm/CodeGen/ValueTypes.h
263

Yeah isVector() looks sufficient, I'll fix before merging.

c-rhodes marked an inline comment as done.Mar 19 2020, 4:14 AM
This revision was automatically updated to reflect the committed changes.