[PATCH] D47215: DAG: Fix extract_subvector combine for a single element

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 12:11:06 PDT 2018


arsenm created this revision.
arsenm added a reviewer: craig.topper.
Herald added subscribers: tpr, wdng.

This would fail before because 1x vectors aren't legal,
so instead just use the scalar type.

      

Avoids regressions in a future AMDGPU commit to add
v4i16/v4f16 as legal types.

      

Test update is just the one test that this triggers
on in tree now. It wasn't checking anything before.
The result is completely  changed since the selects
are eliminated. Not sure if it's considered better
or not.


https://reviews.llvm.org/D47215

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15844,13 +15844,17 @@
       // Only do this if we won't split any elements.
       if (ExtractSize % EltSize == 0) {
         unsigned NumElems = ExtractSize / EltSize;
-        EVT ExtractVT = EVT::getVectorVT(*DAG.getContext(),
-                                         InVT.getVectorElementType(), NumElems);
+        EVT EltVT = InVT.getVectorElementType();
+        EVT ExtractVT = NumElems == 1 ? EltVT :
+          EVT::getVectorVT(*DAG.getContext(), EltVT, NumElems);
         if ((Level < AfterLegalizeDAG ||
-             TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) &&
+             (NumElems == 1 ||
+              TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT))) &&
             (!LegalTypes || TLI.isTypeLegal(ExtractVT))) {
           unsigned IdxVal = (Idx->getZExtValue() * NVT.getScalarSizeInBits()) /
                             EltSize;
+          if (NumElems == 1)
+            return DAG.getBitcast(NVT, V->getOperand(IdxVal));
 
           // Extract the pieces from the original build_vector.
           SDValue BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47215.148068.patch
Type: text/x-patch
Size: 1311 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/4034f65f/attachment.bin>


More information about the llvm-commits mailing list