mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 04:39:44 +00:00
Fix an abort in instcombine when folding creates a vector rem instruction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43743 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f1ba1cad38
commit
cff550995b
@ -2622,6 +2622,7 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
|
||||
if (I.getType()->isInteger()) {
|
||||
APInt Mask(APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()));
|
||||
if (MaskedValueIsZero(Op1, Mask) && MaskedValueIsZero(Op0, Mask)) {
|
||||
// X sdiv Y -> X udiv Y, iff X and Y don't have sign bit set
|
||||
return BinaryOperator::createUDiv(Op0, Op1, I.getName());
|
||||
}
|
||||
}
|
||||
@ -2811,6 +2812,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) {
|
||||
Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
|
||||
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
||||
|
||||
// Handle the integer rem common cases
|
||||
if (Instruction *common = commonIRemTransforms(I))
|
||||
return common;
|
||||
|
||||
@ -2823,12 +2825,14 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
|
||||
return &I;
|
||||
}
|
||||
|
||||
// If the top bits of both operands are zero (i.e. we can prove they are
|
||||
// If the sign bits of both operands are zero (i.e. we can prove they are
|
||||
// unsigned inputs), turn this into a urem.
|
||||
APInt Mask(APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()));
|
||||
if (MaskedValueIsZero(Op1, Mask) && MaskedValueIsZero(Op0, Mask)) {
|
||||
// X srem Y -> X urem Y, iff X and Y don't have sign bit set
|
||||
return BinaryOperator::createURem(Op0, Op1, I.getName());
|
||||
if (I.getType()->isInteger()) {
|
||||
APInt Mask(APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()));
|
||||
if (MaskedValueIsZero(Op1, Mask) && MaskedValueIsZero(Op0, Mask)) {
|
||||
// X srem Y -> X urem Y, iff X and Y don't have sign bit set
|
||||
return BinaryOperator::createURem(Op0, Op1, I.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
9
test/Transforms/InstCombine/vector-srem.ll
Normal file
9
test/Transforms/InstCombine/vector-srem.ll
Normal file
@ -0,0 +1,9 @@
|
||||
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {srem <4 x i32>}
|
||||
|
||||
define <4 x i32> @foo(<4 x i32> %t, <4 x i32> %u)
|
||||
{
|
||||
%k = sdiv <4 x i32> %t, %u
|
||||
%l = mul <4 x i32> %k, %u
|
||||
%m = sub <4 x i32> %t, %l
|
||||
ret <4 x i32> %m
|
||||
}
|
Loading…
Reference in New Issue
Block a user