From 8c75adf95b330fce1ef7eced7a35b35e98237a10 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 11 Apr 2017 06:32:48 +0000 Subject: [InstCombine] Refinement of r299915. Only consider a ConstantVector for Neg if all the elements are Undef or ConstantInt. llvm-svn: 299917 --- .../lib/Transforms/InstCombine/InstructionCombining.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 3c6f07e7fdd..4782f477e84 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -726,9 +726,20 @@ Value *InstCombiner::dyn_castNegVal(Value *V) const { if (C->getType()->getElementType()->isIntegerTy()) return ConstantExpr::getNeg(C); - if (ConstantVector *C = dyn_cast(V)) - if (C->getType()->getElementType()->isIntegerTy()) - return ConstantExpr::getNeg(C); + if (ConstantVector *CV = dyn_cast(V)) { + for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) { + Constant *Elt = CV->getAggregateElement(i); + if (!Elt) + return nullptr; + + if (isa(Elt)) + continue; + + if (!isa(Elt)) + return nullptr; + } + return ConstantExpr::getNeg(CV); + } return nullptr; } -- cgit v1.2.3