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
This commit is contained in:
Nick Lewycky 2008-12-18 06:31:11 +00:00
parent 31535f1f04
commit 2a8f6597a3
2 changed files with 30 additions and 0 deletions

View File

@ -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;
}

View File

@ -0,0 +1,7 @@
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {i8 2, i8 2}
; PR2756
define <2 x i8> @foo(<2 x i8> %x) {
%A = srem <2 x i8> %x, <i8 2, i8 -2>
ret <2 x i8> %A
}