[PATCH] Reorder shuffle and binary operation.
Benjamin Kramer
benny.kra at gmail.com
Fri May 2 09:50:19 PDT 2014
================
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),
----------------
This could be
std::equal(LHSMask.begin(), LHSMask.end(), RHSMask.begin())
================
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)) &&
----------------
If you have a binary operator with a shuffle and a constant, the constant will always be canonicalized to the RHS.
http://reviews.llvm.org/D3525
More information about the llvm-commits
mailing list