From: Sanjay Patel Date: Mon, 6 Mar 2017 23:25:28 +0000 (+0000) Subject: [InstCombine] use dyn_cast instead of isa+cast; NFCI X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1609c3ca8631d58bf3eeef6b6d0403f37f9fd798;p=llvm [InstCombine] use dyn_cast instead of isa+cast; NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297092 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index fb875e6da40..a0b93668128 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1321,22 +1321,19 @@ Value *InstCombiner::SimplifyVectorOp(BinaryOperator &Inst) { assert(cast(LHS->getType())->getNumElements() == VWidth); assert(cast(RHS->getType())->getNumElements() == VWidth); - // If both arguments of binary operation are shuffles, which use the same - // mask and shuffle within a single vector, it is worthwhile to move the - // shuffle after binary operation: + // If both arguments of the binary operation are shuffles that use the same + // mask and shuffle within a single vector, move the shuffle after the binop: // Op(shuffle(v1, m), shuffle(v2, m)) -> shuffle(Op(v1, v2), m) - if (isa(LHS) && isa(RHS)) { - ShuffleVectorInst *LShuf = cast(LHS); - ShuffleVectorInst *RShuf = cast(RHS); - if (isa(LShuf->getOperand(1)) && - isa(RShuf->getOperand(1)) && - LShuf->getOperand(0)->getType() == RShuf->getOperand(0)->getType() && - LShuf->getMask() == RShuf->getMask()) { - Value *NewBO = CreateBinOpAsGiven(Inst, LShuf->getOperand(0), - RShuf->getOperand(0), Builder); - return Builder->CreateShuffleVector(NewBO, - UndefValue::get(NewBO->getType()), LShuf->getMask()); - } + auto *LShuf = dyn_cast(LHS); + auto *RShuf = dyn_cast(RHS); + if (LShuf && RShuf && LShuf->getMask() == RShuf->getMask() && + isa(LShuf->getOperand(1)) && + isa(RShuf->getOperand(1)) && + LShuf->getOperand(0)->getType() == RShuf->getOperand(0)->getType()) { + Value *NewBO = CreateBinOpAsGiven(Inst, LShuf->getOperand(0), + RShuf->getOperand(0), Builder); + return Builder->CreateShuffleVector( + NewBO, UndefValue::get(NewBO->getType()), LShuf->getMask()); } // If one argument is a shuffle within one vector, the other is a constant,