Hi,
this test started to fail recently as the result of the work of Richard S.,
but the underlying issue had been latent for a long time. It boils down to
this excerpt from the VRP1 dump file:
Found new range for _9: [0, 12]
marking stmt to be not simulated again
Visiting statement:
_3 = _9 %[fl] _11;
Found new range for _3: [0, +INF]
which is plain wrong since the sign of FLOOR_MOD_EXPR is the sign of the
divisor and not that of the dividend (the latter is for TRUNC_MOD_EXPR).
I have attached a fix for mainline and another one for the 4.9/5 branches.
Tested on x86_64-suse-linux, OK for all active branches?
2015-10-20 Eric Botcazou <ebotca...@adacore.com>
* fold-const.c (tree_binary_nonnegative_warnv_p) <FLOOR_MOD_EXPR>:
Recurse on operand #1 instead of operand #0.
<CEIL_MOD_EXPR>: Do not recurse.
<ROUND_MOD_EXPR>: Likewise.
--
Eric Botcazou
Index: fold-const.c
===================================================================
--- fold-const.c (revision 229022)
+++ fold-const.c (working copy)
@@ -12982,11 +12982,15 @@ tree_binary_nonnegative_warnv_p (enum tr
return RECURSE (op0) && RECURSE (op1);
case TRUNC_MOD_EXPR:
- case CEIL_MOD_EXPR:
- case FLOOR_MOD_EXPR:
- case ROUND_MOD_EXPR:
+ /* The sign of the remainder is that of the dividend. */
return RECURSE (op0);
+ case FLOOR_MOD_EXPR:
+ /* The sign of the remainder is that of the divisor. */
+ return RECURSE (op1);
+
+ case CEIL_MOD_EXPR:
+ case ROUND_MOD_EXPR:
default:
return tree_simple_nonnegative_warnv_p (code, type);
}
Index: fold-const.c
===================================================================
--- fold-const.c (revision 228932)
+++ fold-const.c (working copy)
@@ -14853,11 +14853,17 @@ tree_binary_nonnegative_warnv_p (enum tr
strict_overflow_p));
case TRUNC_MOD_EXPR:
- case CEIL_MOD_EXPR:
- case FLOOR_MOD_EXPR:
- case ROUND_MOD_EXPR:
+ /* The sign of the remainder is that of the dividend. */
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
+
+ case FLOOR_MOD_EXPR:
+ /* The sign of the remainder is that of the divisor. */
+ return tree_expr_nonnegative_warnv_p (op1,
+ strict_overflow_p);
+
+ case CEIL_MOD_EXPR:
+ case ROUND_MOD_EXPR:
default:
return tree_simple_nonnegative_warnv_p (code, type);
}