[PATCH] D103880: [SDAG] Fix pow2 assumption when splitting vectors

Carl Ritson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 8 02:56:00 PDT 2021


critson created this revision.
critson added reviewers: lebedev.ri, RKSimon, craig.topper, spatel.
Herald added subscribers: ecnelises, hiraditya.
critson requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When reducing vector builds to shuffles it possible that
the DAG combiner may try to extract invalid subvectors.

This happens as the existing code assumes vectors will be power
of 2 sizes, which is already untrue, but becomes more noticable
with v6 and v7 types.
Specifically the existing code assumes that half PowerOf2Ceil of
a given vector index will fit twice into a given vector.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103880

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -19362,7 +19362,9 @@
       unsigned SplitSize = NearestPow2 / 2;
       EVT SplitVT = EVT::getVectorVT(*DAG.getContext(),
                                      InVT.getVectorElementType(), SplitSize);
-      if (TLI.isTypeLegal(SplitVT)) {
+      if (TLI.isTypeLegal(SplitVT) &&
+          SplitSize + SplitVT.getVectorMinNumElements() <=
+              InVT.getVectorMinNumElements()) {
         SDValue VecIn2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, SplitVT, Vec,
                                      DAG.getVectorIdxConstant(SplitSize, DL));
         SDValue VecIn1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, SplitVT, Vec,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103880.350558.patch
Type: text/x-patch
Size: 853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210608/be585023/attachment.bin>


More information about the llvm-commits mailing list