[PATCH] Reorder shuffle and binary operation.

Serge Pavlov sepavloff at gmail.com
Mon May 5 08:43:42 PDT 2014


Thank you for feedback!

================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:1125-1131
@@ +1124,9 @@
+      SmallVector<int, 16> RHSMask = RShuf->getShuffleMask();
+      bool MasksEqual = true;
+      for (unsigned I = 0; I < VWidth; ++I)
+        if (LHSMask[I] != RHSMask[I]) {
+          MasksEqual = false;
+          break;
+        }
+      if (MasksEqual) {
+        BinaryOperator *NewBO = CreateBinOpAsGiven(Inst, LShuf->getOperand(0),
----------------
Benjamin Kramer wrote:
> This could be
> 
>   std::equal(LHSMask.begin(), LHSMask.end(), RHSMask.begin())
Indeed. Replaced.

================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:1143-1148
@@ +1142,8 @@
+  // try moving the shuffle after the binary operation.
+  ShuffleVectorInst *Shuffle = nullptr;
+  Constant *C1 = nullptr;
+  if (isa<ShuffleVectorInst>(LHS)) Shuffle = cast<ShuffleVectorInst>(LHS);
+  if (isa<ShuffleVectorInst>(RHS)) Shuffle = cast<ShuffleVectorInst>(RHS);
+  if (isa<Constant>(LHS)) C1 = cast<Constant>(LHS);
+  if (isa<Constant>(RHS)) C1 = cast<Constant>(RHS);
+  if (Shuffle && C1 && isa<UndefValue>(Shuffle->getOperand(1)) &&
----------------
Benjamin Kramer wrote:
> If you have a binary operator with a shuffle and a constant, the constant will always be canonicalized to the RHS.
This transformation should also be applicable to non-commutative operations such as div, sub.

http://reviews.llvm.org/D3525






More information about the llvm-commits mailing list