diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2008-12-18 06:31:11 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2008-12-18 06:31:11 +0000 |
commit | 2a8f6597a3814e82e7b202e557541410c9282c33 (patch) | |
tree | 6ab8d7898b866eb46cb52b52a9d3196597762514 /lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | 31535f1f04853974ec53dfc61d90e8dc4a09b456 (diff) |
Make all the vector elements positive in an srem of constant vector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61195 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 4914c110cb..8d54e0c983 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3089,6 +3089,29 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) { } } + // If it's a constant vector, flip any negative values positive. + if (isa<VectorType>(I.getType())) { + if (ConstantVector *RHSV = dyn_cast<ConstantVector>(Op1)) { + unsigned VWidth = RHSV->getNumOperands(); + std::vector<Constant *> Elts(VWidth); + + for (unsigned i = 0; i != VWidth; ++i) { + if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i))) { + if (RHS->getValue().isNegative()) + Elts[i] = cast<ConstantInt>(ConstantExpr::getNeg(RHS)); + else + Elts[i] = RHS; + } + } + + Constant *NewRHSV = ConstantVector::get(Elts); + if (NewRHSV != RHSV) { + I.setOperand(1, NewRHSV); + return &I; + } + } + } + return 0; } |