diff options
author | Chris Lattner <sabre@nondot.org> | 2004-07-06 07:01:22 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-07-06 07:01:22 +0000 |
commit | 5b73c08896ce402212993ca938f64b056f68e0a1 (patch) | |
tree | 7e2c0bd485b3d266f007e20d7d3edcb8c74729ea | |
parent | f77afbb2756ab4eb1c25d2e799e87158df757acf (diff) |
Implement InstCombine/sub.ll:test15: X % -Y === X % Y
Also, remove X % -1 = 0, because it's not true for unsigneds, and the
signed case is superceeded by this new handling.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14637 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index c0d0591c9b..fad2730d84 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -844,11 +844,18 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) { Instruction *InstCombiner::visitRem(BinaryOperator &I) { + if (I.getType()->isSigned()) + if (Value *RHSNeg = dyn_castNegVal(I.getOperand(1))) + if (RHSNeg != I.getOperand(1)) { // Avoid problems with MININT + // X % -Y -> X % Y + AddUsesToWorkList(I); + I.setOperand(1, RHSNeg); + return &I; + } + if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) { if (RHS->equalsInt(1)) // X % 1 == 0 return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); - if (RHS->isAllOnesValue()) // X % -1 == 0 - return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // Check to see if this is an unsigned remainder with an exact power of 2, // if so, convert to a bitwise and. |