From: Sanjay Patel Date: Fri, 7 Jun 2019 16:09:54 +0000 (+0000) Subject: [Analysis] simplify code for getSplatValue(); NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15d807a56c14fb4f563002c9c4a92ce8d19f64b9;p=llvm [Analysis] simplify code for getSplatValue(); NFC AFAIK, this is only currently called by TTI, but it could be used from instcombine or CGP to help solve problems like: https://bugs.llvm.org/show_bug.cgi?id=37428 https://bugs.llvm.org/show_bug.cgi?id=42174 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362810 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/VectorUtils.cpp b/lib/Analysis/VectorUtils.cpp index f1a05ae5055..ea00f0a7dd3 100644 --- a/lib/Analysis/VectorUtils.cpp +++ b/lib/Analysis/VectorUtils.cpp @@ -304,30 +304,21 @@ Value *llvm::findScalarElement(Value *V, unsigned EltNo) { /// Get splat value if the input is a splat vector or return nullptr. /// This function is not fully general. It checks only 2 cases: -/// the input value is (1) a splat constants vector or (2) a sequence -/// of instructions that broadcast a single value into a vector. -/// +/// the input value is (1) a splat constant vector or (2) a sequence +/// of instructions that broadcasts a scalar at element 0. const llvm::Value *llvm::getSplatValue(const Value *V) { - - if (auto *C = dyn_cast(V)) - if (isa(V->getType())) + if (isa(V->getType())) + if (auto *C = dyn_cast(V)) return C->getSplatValue(); - auto *ShuffleInst = dyn_cast(V); - if (!ShuffleInst) - return nullptr; - // All-zero (or undef) shuffle mask elements. - for (int MaskElt : ShuffleInst->getShuffleMask()) - if (MaskElt != 0 && MaskElt != -1) - return nullptr; - // The first shuffle source is 'insertelement' with index 0. - auto *InsertEltInst = - dyn_cast(ShuffleInst->getOperand(0)); - if (!InsertEltInst || !isa(InsertEltInst->getOperand(2)) || - !cast(InsertEltInst->getOperand(2))->isZero()) - return nullptr; + // shuf (inselt ?, Splat, 0), ?, <0, undef, 0, ...> + Value *Splat; + if (match(V, m_ShuffleVector(m_InsertElement(m_Value(), m_Value(Splat), + m_ZeroInt()), + m_Value(), m_ZeroInt()))) + return Splat; - return InsertEltInst->getOperand(1); + return nullptr; } MapVector