mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-09 18:55:33 +00:00
Fix demanded bits analysis with srem by negative number. Based on a patch
by Richard Osborne. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58555 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
21440acc06
commit
8e39432ea9
@ -1274,12 +1274,12 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, APInt DemandedMask,
|
|||||||
break;
|
break;
|
||||||
case Instruction::SRem:
|
case Instruction::SRem:
|
||||||
if (ConstantInt *Rem = dyn_cast<ConstantInt>(I->getOperand(1))) {
|
if (ConstantInt *Rem = dyn_cast<ConstantInt>(I->getOperand(1))) {
|
||||||
APInt RA = Rem->getValue();
|
APInt RA = Rem->getValue().abs();
|
||||||
if (RA.isPowerOf2() || (-RA).isPowerOf2()) {
|
if (RA.isPowerOf2()) {
|
||||||
if (DemandedMask.ule(RA)) // srem won't affect demanded bits
|
if (DemandedMask.ule(RA)) // srem won't affect demanded bits
|
||||||
return UpdateValueUsesWith(I, I->getOperand(0));
|
return UpdateValueUsesWith(I, I->getOperand(0));
|
||||||
|
|
||||||
APInt LowBits = RA.isStrictlyPositive() ? (RA - 1) : ~RA;
|
APInt LowBits = RA - 1;
|
||||||
APInt Mask2 = LowBits | APInt::getSignBit(BitWidth);
|
APInt Mask2 = LowBits | APInt::getSignBit(BitWidth);
|
||||||
if (SimplifyDemandedBits(I->getOperand(0), Mask2,
|
if (SimplifyDemandedBits(I->getOperand(0), Mask2,
|
||||||
LHSKnownZero, LHSKnownOne, Depth+1))
|
LHSKnownZero, LHSKnownOne, Depth+1))
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {ret i1 true}
|
||||||
|
; PR2993
|
||||||
|
|
||||||
|
define i1 @foo(i32 %x) {
|
||||||
|
%1 = srem i32 %x, -1
|
||||||
|
%2 = icmp eq i32 %1, 0
|
||||||
|
ret i1 %2
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user