[llvm] r344854 - [InstCombine] make code more flexible with lambda; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 20 09:58:27 PDT 2018


Author: spatel
Date: Sat Oct 20 09:58:27 2018
New Revision: 344854

URL: http://llvm.org/viewvc/llvm-project?rev=344854&view=rev
Log:
[InstCombine] make code more flexible with lambda; NFC

I couldn't tell from svn history when these checks were added,
but it pre-dates the split of instcombine into its own directory
at rL92459.

The motivation for changing the check is partly shown by the
code in PR34724:
https://bugs.llvm.org/show_bug.cgi?id=34724

There are also existing regression tests for SLPVectorizer with
sequences of extract+insert that are likely assumed to become
shuffles by the vectorizer cost models.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=344854&r1=344853&r2=344854&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Sat Oct 20 09:58:27 2018
@@ -898,9 +898,6 @@ Instruction *InstCombiner::visitInsertEl
       if (EI->getOperand(0) == VecOp && ExtractedIdx == InsertedIdx)
         return replaceInstUsesWith(IE, VecOp);
 
-      // If this insertelement isn't used by some other insertelement, turn it
-      // (and any insertelements it points to), into one big shuffle.
-
       // TODO: Looking at the user(s) to determine if this insert is a
       // fold-to-shuffle opportunity does not match the usual instcombine
       // constraints. We should decide if the transform is worthy based only
@@ -915,8 +912,17 @@ Instruction *InstCombiner::visitInsertEl
       // The rules for determining what is an acceptable target-independent
       // shuffle mask are fuzzy because they evolve based on the backend's
       // capabilities and real-world impact.
+      auto isShuffleRootCandidate = [](InsertElementInst &Insert) {
+        if (!Insert.hasOneUse())
+          return true;
+        auto *InsertUser = dyn_cast<InsertElementInst>(Insert.user_back());
+        if (!InsertUser)
+          return true;
+        return false;
+      };
 
-      if (!IE.hasOneUse() || !isa<InsertElementInst>(IE.user_back())) {
+      // Try to form a shuffle from a chain of extract-insert ops.
+      if (isShuffleRootCandidate(IE)) {
         SmallVector<Constant*, 16> Mask;
         ShuffleOps LR = collectShuffleElements(&IE, Mask, nullptr, *this);
 




More information about the llvm-commits mailing list