[llvm-commits] [llvm] r58555 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll
Nick Lewycky
nicholas at mxc.ca
Sat Nov 1 19:41:51 PDT 2008
Author: nicholas
Date: Sat Nov 1 21:41:50 2008
New Revision: 58555
URL: http://llvm.org/viewvc/llvm-project?rev=58555&view=rev
Log:
Fix demanded bits analysis with srem by negative number. Based on a patch
by Richard Osborne.
Added:
llvm/trunk/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=58555&r1=58554&r2=58555&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sat Nov 1 21:41:50 2008
@@ -1274,12 +1274,12 @@
break;
case Instruction::SRem:
if (ConstantInt *Rem = dyn_cast<ConstantInt>(I->getOperand(1))) {
- APInt RA = Rem->getValue();
- if (RA.isPowerOf2() || (-RA).isPowerOf2()) {
+ APInt RA = Rem->getValue().abs();
+ if (RA.isPowerOf2()) {
if (DemandedMask.ule(RA)) // srem won't affect demanded bits
return UpdateValueUsesWith(I, I->getOperand(0));
- APInt LowBits = RA.isStrictlyPositive() ? (RA - 1) : ~RA;
+ APInt LowBits = RA - 1;
APInt Mask2 = LowBits | APInt::getSignBit(BitWidth);
if (SimplifyDemandedBits(I->getOperand(0), Mask2,
LHSKnownZero, LHSKnownOne, Depth+1))
Added: llvm/trunk/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll?rev=58555&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-11-01-SRemDemandedBits.ll Sat Nov 1 21:41:50 2008
@@ -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
+}
More information about the llvm-commits
mailing list