aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Kenner <kenner@gcc.gnu.org>1993-07-05 17:55:06 -0400
committerRichard Kenner <kenner@gcc.gnu.org>1993-07-05 17:55:06 -0400
commit05a0d5eabb68d036b5717738d601abac96a46c96 (patch)
tree1aa578f5f8f27c53c867e8d77a854a7f50cda9dd /gcc/fold-const.c
parent40083ddf51610448fcdbb96591065678675ecbce (diff)
downloadgcc-05a0d5eabb68d036b5717738d601abac96a46c96.zip
gcc-05a0d5eabb68d036b5717738d601abac96a46c96.tar.gz
gcc-05a0d5eabb68d036b5717738d601abac96a46c96.tar.bz2
(fold, case EQ_EXPR, LE_EXPR): If comparing results of signed MOD with
zero, use an unsigned MOD. From-SVN: r4852
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 60b5e99..d03ae53 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4163,6 +4163,25 @@ fold (expr)
arg1));
}
+ /* If this is an NE or EQ comparison of zero against the result of a
+ signed MOD operation, make the MOD operation unsigned since it
+ is simpler and equivalent. */
+ if ((code == NE_EXPR || code == EQ_EXPR)
+ && integer_zerop (arg1)
+ && ! TREE_UNSIGNED (TREE_TYPE (arg0))
+ && (TREE_CODE (arg0) == TRUNC_MOD_EXPR
+ || TREE_CODE (arg0) == CEIL_MOD_EXPR
+ || TREE_CODE (arg0) == FLOOR_MOD_EXPR
+ || TREE_CODE (arg0) == ROUND_MOD_EXPR))
+ {
+ tree newtype = unsigned_type (TREE_TYPE (arg0));
+ tree newmod = build (TREE_CODE (arg0), newtype,
+ convert (newtype, TREE_OPERAND (arg0, 0)),
+ convert (newtype, TREE_OPERAND (arg0, 1)));
+
+ return build (code, type, newmod, convert (newtype, arg1));
+ }
+
/* If this is an NE comparison of zero with an AND of one, remove the
comparison since the AND will give the correct value. */
if (code == NE_EXPR && integer_zerop (arg1)