summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-06 07:01:22 +0000
committerChris Lattner <sabre@nondot.org>2004-07-06 07:01:22 +0000
commit7fd5f0745a6e9649c2d6a9e50566975b8adb9384 (patch)
tree660181ef684c343371b50810fb5c0710e18d22d7 /llvm/lib/Transforms/Scalar/InstructionCombining.cpp
parent2c9fdbe6cb818e88ef4cd2428e4066708bd2671f (diff)
downloadbcm5719-llvm-7fd5f0745a6e9649c2d6a9e50566975b8adb9384.tar.gz
bcm5719-llvm-7fd5f0745a6e9649c2d6a9e50566975b8adb9384.zip
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. llvm-svn: 14637
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index c0d0591c9b3..fad2730d84c 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/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.
OpenPOWER on IntegriCloud