summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-12-18 06:31:11 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-12-18 06:31:11 +0000
commit0f0e63fe7313f8f3647bd6be66c94fa75fc77759 (patch)
tree210a5a90bc382ae88810f4e6bc5673964f9bf23a /llvm/lib
parent4caf5eb70cfd5a4d01a8cb97ccac28013aa9f3ef (diff)
downloadbcm5719-llvm-0f0e63fe7313f8f3647bd6be66c94fa75fc77759.tar.gz
bcm5719-llvm-0f0e63fe7313f8f3647bd6be66c94fa75fc77759.zip
Make all the vector elements positive in an srem of constant vector.
llvm-svn: 61195
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 4914c110cb7..8d54e0c983a 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud