[PATCH] D80919: [CodeGen] Fix warnings in getCopyFromPartsVector

David Sherwood via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 05:51:15 PDT 2020


david-arm created this revision.
david-arm added a reviewer: sdesmalen.
Herald added subscribers: llvm-commits, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: LLVM.

Replace some of the calls to getVectorNumElements() with
getVectorElementCount(). These warnings were being hit by
this test:

  llvm/test/CodeGen/AArch64/sve-gep.ll

As part of this patch I have introduced another comparison
operator in ElementCount, namely to check if one count
is > than another. However, when doing mathematical
operations we do not always know the answer at compile
time and therefore we have two functions:

bool isGT(const ElementCount &RHS, bool &Known);
bool knownGT(const ElementCount &RHS);

The first function returns true if the answer is known at
compile time to be >, otherwise it returns false. The Known
boolean is set true if the answer is known at compile time.

The second function also does the comparison, but asserts
that the answer is known at compile time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80919

Files:
  llvm/include/llvm/Support/TypeSize.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -437,8 +437,10 @@
     // parts vector has more elements than the value vector, then we have a
     // vector widening case (e.g. <2 x float> -> <4 x float>).  Extract the
     // elements we want.
+    ElementCount PartEC = PartEVT.getVectorElementCount();
+    ElementCount ValueEC = ValueVT.getVectorElementCount();
     if (PartEVT.getVectorElementType() == ValueVT.getVectorElementType()) {
-      assert(PartEVT.getVectorNumElements() > ValueVT.getVectorNumElements() &&
+      assert(PartEC.knownGT(ValueEC) &&
              "Cannot narrow, it would be a lossy transformation");
       return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ValueVT, Val,
                          DAG.getVectorIdxConstant(0, DL));
@@ -448,8 +450,7 @@
     if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits())
       return DAG.getNode(ISD::BITCAST, DL, ValueVT, Val);
 
-    assert(PartEVT.getVectorNumElements() == ValueVT.getVectorNumElements() &&
-      "Cannot handle this kind of promotion");
+    assert(PartEC == ValueEC && "Cannot handle this kind of promotion");
     // Promoted vector extract
     return DAG.getAnyExtOrTrunc(Val, DL, ValueVT);
 
Index: llvm/include/llvm/Support/TypeSize.h
===================================================================
--- llvm/include/llvm/Support/TypeSize.h
+++ llvm/include/llvm/Support/TypeSize.h
@@ -49,6 +49,33 @@
   bool operator!=(const ElementCount& RHS) const {
     return !(*this == RHS);
   }
+
+  // Returns true if the answer is known at compile time to be >, else we
+  // return false. Known is only set to false if we cannot prove we know the
+  // answer at compile time.
+  bool isGT(const ElementCount &RHS, bool &Known) {
+    bool Result;
+    if ((Scalable || !RHS.Scalable) && Min > RHS.Min)
+      Known = Result = true;
+    else if ((!Scalable || RHS.Scalable) && Min <= RHS.Min) {
+      Known = true;
+      Result = false;
+    } else
+      Known = Result = false;
+    return Result;
+  }
+
+  bool knownGT(const ElementCount &RHS) {
+    bool Known;
+    bool Result = isGT(RHS, Known);
+    assertKnown(Known);
+    return Result;
+  }
+
+private:
+  void assertKnown(bool Known) {
+    assert(Known && "Cannot compare element counts at runtime");
+  }
 };
 
 // This class is used to represent the size of types. If the type is of fixed


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80919.267591.patch
Type: text/x-patch
Size: 2558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200601/844088d8/attachment.bin>


More information about the llvm-commits mailing list