mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 06:33:24 +00:00
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:
parent
31535f1f04
commit
2a8f6597a3
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user