diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-08-16 12:52:17 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-08-16 12:52:17 +0000 |
commit | 039f556f44e366e70d174be1026080bdb6c23995 (patch) | |
tree | 85d988b5887f8ec9a763fe1c7bd246155c7b28a4 /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 61cd68700927f4811e0803a135104e9c96b0d679 (diff) | |
download | bcm5719-llvm-039f556f44e366e70d174be1026080bdb6c23995.tar.gz bcm5719-llvm-039f556f44e366e70d174be1026080bdb6c23995.zip |
[InstCombine] move vector compare before same-shuffled ops
This is a step towards fixing PR37463:
https://bugs.llvm.org/show_bug.cgi?id=37463
llvm-svn: 339875
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 725e1c87e6c..a90a46dab42 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -4598,6 +4598,26 @@ static Instruction *canonicalizeICmpBool(ICmpInst &I, } } +static Instruction *foldVectorCmp(CmpInst &Cmp, + InstCombiner::BuilderTy &Builder) { + // If both arguments of the cmp are shuffles that use the same mask and + // shuffle within a single vector, move the shuffle after the cmp. + Value *LHS = Cmp.getOperand(0), *RHS = Cmp.getOperand(1); + Value *V1, *V2; + Constant *M; + if (match(LHS, m_ShuffleVector(m_Value(V1), m_Undef(), m_Constant(M))) && + match(RHS, m_ShuffleVector(m_Value(V2), m_Undef(), m_Specific(M))) && + V1->getType() == V2->getType() && + (LHS->hasOneUse() || RHS->hasOneUse())) { + // cmp (shuffle V1, M), (shuffle V2, M) --> shuffle (cmp V1, V2), M + CmpInst::Predicate P = Cmp.getPredicate(); + Value *NewCmp = isa<ICmpInst>(Cmp) ? Builder.CreateICmp(P, V1, V2) + : Builder.CreateFCmp(P, V1, V2); + return new ShuffleVectorInst(NewCmp, UndefValue::get(NewCmp->getType()), M); + } + return nullptr; +} + Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { bool Changed = false; Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); @@ -4867,6 +4887,10 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { return foldICmpAddOpConst(X, Cst, I.getSwappedPredicate()); } + if (I.getType()->isVectorTy()) + if (Instruction *Res = foldVectorCmp(I, Builder)) + return Res; + return Changed ? &I : nullptr; } @@ -5301,5 +5325,9 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { if (LHSExt->getSrcTy() == RHSExt->getSrcTy()) return new FCmpInst(Pred, LHSExt->getOperand(0), RHSExt->getOperand(0)); + if (I.getType()->isVectorTy()) + if (Instruction *Res = foldVectorCmp(I, Builder)) + return Res; + return Changed ? &I : nullptr; } |