summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-03-31 15:01:30 +0000
committerSanjay Patel <spatel@rotateright.com>2019-03-31 15:01:30 +0000
commitb276dd195a2dc3c908578493ce347988365aec69 (patch)
tree44d05b05c96320968c58757a27138fa0856b7009 /llvm/lib/Transforms
parent9f4a4d39749ec48c9c14d2a7a7dcd025a2a7516a (diff)
downloadbcm5719-llvm-b276dd195a2dc3c908578493ce347988365aec69.tar.gz
bcm5719-llvm-b276dd195a2dc3c908578493ce347988365aec69.zip
[InstCombine] canonicalize select shuffles by commuting
In PR41304: https://bugs.llvm.org/show_bug.cgi?id=41304 ...we have a case where we want to fold a binop of select-shuffle (blended) values. Rather than try to match commuted variants of the pattern, we can canonicalize the shuffles and check for mask equality with commuted operands. We don't produce arbitrary shuffle masks in instcombine, but select-shuffles are a special case that the backend is required to handle because we already canonicalize vector select to this shuffle form. So there should be no codegen difference from this change. It's possible that this improves CSE in IR though. Differential Revision: https://reviews.llvm.org/D60016 llvm-svn: 357366
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index cb5c22c69be..49c29fe651b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -1343,6 +1343,15 @@ static Instruction *foldSelectShuffle(ShuffleVectorInst &Shuf,
if (!Shuf.isSelect())
return nullptr;
+ // Canonicalize to choose from operand 0 first.
+ unsigned NumElts = Shuf.getType()->getVectorNumElements();
+ if (Shuf.getMaskValue(0) >= (int)NumElts) {
+ assert(!isa<UndefValue>(Shuf.getOperand(1)) &&
+ "Not expecting undef shuffle operand with select mask");
+ Shuf.commute();
+ return &Shuf;
+ }
+
if (Instruction *I = foldSelectShuffleWith1Binop(Shuf))
return I;
OpenPOWER on IntegriCloud