* fold-const.c (tree_expr_nonnegative_p): Only return true for
ABS_EXPR when flag_wrapv is false because of INT_MIN.
(tree_expr_nonzero_p): Always call tree_expr_nonzero_p on the argument
of an ABS_EXPR.
(fold_unary): Always fold ABS_EXPR<ABS_EXPR<x>> into
ABS_EXPR<x>.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102184
138bc75d-0d04-0410-961f-
82ee72b054a4
+2005-07-19 James A. Morrison <phython@gcc.gnu.org>
+
+ * fold-const.c (tree_expr_nonnegative_p): Only return true for
+ ABS_EXPR when flag_wrapv is false because of INT_MIN.
+ (tree_expr_nonzero_p): Always call tree_expr_nonzero_p on the argument
+ of an ABS_EXPR.
+ (fold_unary): Always fold ABS_EXPR<ABS_EXPR<x>> into
+ ABS_EXPR<x>.
+
2005-07-20 Giovanni Bajo <giovannibajo@libero.it>
Make CONSTRUCTOR use VEC to store initializers.
TREE_TYPE (targ0),
targ0));
}
- else if (tree_expr_nonnegative_p (arg0))
+ /* ABS_EXPR<ABS_EXPR<x>> = ABS_EXPR<x> even if flag_wrapv is on. */
+ else if (tree_expr_nonnegative_p (arg0) || TREE_CODE (arg0) == ABS_EXPR)
return arg0;
/* Strip sign ops from argument. */
switch (TREE_CODE (t))
{
case ABS_EXPR:
- return 1;
+ /* We can't return 1 if flag_wrapv is set because
+ ABS_EXPR<INT_MIN> = INT_MIN. */
+ if (!flag_wrapv)
+ return 1;
+ break;
case INTEGER_CST:
return tree_int_cst_sgn (t) >= 0;
switch (TREE_CODE (t))
{
case ABS_EXPR:
- if (!TYPE_UNSIGNED (type) && !flag_wrapv)
- return tree_expr_nonzero_p (TREE_OPERAND (t, 0));
+ return tree_expr_nonzero_p (TREE_OPERAND (t, 0));
case INTEGER_CST:
/* We used to test for !integer_zerop here. This does not work correctly
+2005-07-19 James A. Morrison <phython@gcc.gnu.org>
+
+ * gcc.dg/fold-abs-1.c: New test.
+ * gcc.dg/fold-abs-2.c: New test.
+ * gcc.dg/fold-abs-3.c: New test.
+
2005-07-20 Giovanni Bajo <giovannibajo@libero.it>
Make CONSTRUCTOR use VEC to store initializers.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fwrapv" } */
+#define ABS(x) (x > 0 ? x : -x)
+int f (int a, int b) {
+ if ((ABS(a) | b) != 0) return 1;
+ else return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O1 -fwrapv" } */
+#include <limits.h>
+void exit (int);
+void abort ();
+#define ABS(x) (x > 0 ? x : -x)
+int f (int a) {
+ if (ABS(a) >= 0) return 1;
+ else return 0;
+}
+
+int main (int argc, char *argv[]) {
+ if (f(INT_MIN))
+ abort ();
+ else
+ exit (0);
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple -fwrapv" } */
+#define ABS(x) (x > 0 ? x : -x)
+int f (int a) {
+ return ABS (ABS(a));
+}
+
+/* { dg-final { scan-tree-dump-times "ABS" 1 "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */