This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix extract_range_from_cond (PR tree-optimization/19060)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jeff Law <law at redhat dot com>, Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 4 Jan 2005 12:46:50 -0500
- Subject: [PATCH] Fix extract_range_from_cond (PR tree-optimization/19060)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
If extract_range_from_cond sees x < min or x > max condition, it will
create a range min .. max_with_TREE_OVERFLOW (or min_with_TREE_OVERFLOW .. max).
The following patch fixes it.
Ok if regression testing passes?
It seems that fold-const.c doesn't optimize x < TYPE_MIN_VALUE (TREE_TYPE (x))
or x > TYPE_MAX_VALUE (TREE_TYPE (x)), so it should probably be taught about
that too.
BTW: simplify_cond_and_lookup_avail_expr completely ignores the inverted
value of the second extract_range_from_cond. I haven't so far managed to
write a testcase that would prove that it is wrong, but I certainly don't
understand how that can be right.
2005-01-04 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/19060
* tree-ssa-dom.c (extract_range_from_cond) <case GT_EXPR, LT_EXPR>:
Special case extremes.
* gcc.c-torture/execute/20050104-1.c: New test.
--- gcc/tree-ssa-dom.c.jj 2004-12-28 22:03:26.000000000 +0100
+++ gcc/tree-ssa-dom.c 2005-01-04 17:50:05.289690562 +0100
@@ -1,5 +1,5 @@
/* SSA Dominator optimizations for trees
- Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Contributed by Diego Novillo <dnovillo@redhat.com>
This file is part of GCC.
@@ -3204,9 +3204,17 @@ extract_range_from_cond (tree cond, tree
break;
case GT_EXPR:
- low = int_const_binop (PLUS_EXPR, op1, integer_one_node, 1);
high = TYPE_MAX_VALUE (type);
- inverted = 0;
+ if (tree_int_cst_equal (op1, high))
+ {
+ low = TYPE_MIN_VALUE (type);
+ inverted = 1;
+ }
+ else
+ {
+ low = int_const_binop (PLUS_EXPR, op1, integer_one_node, 1);
+ inverted = 0;
+ }
break;
case LE_EXPR:
@@ -3216,9 +3224,17 @@ extract_range_from_cond (tree cond, tree
break;
case LT_EXPR:
- high = int_const_binop (MINUS_EXPR, op1, integer_one_node, 1);
low = TYPE_MIN_VALUE (type);
- inverted = 0;
+ if (tree_int_cst_equal (op1, low))
+ {
+ high = TYPE_MAX_VALUE (type);
+ inverted = 1;
+ }
+ else
+ {
+ high = int_const_binop (MINUS_EXPR, op1, integer_one_node, 1);
+ inverted = 0;
+ }
break;
default:
--- gcc/testsuite/gcc.c-torture/execute/20050104-1.c.jj 2005-01-04 17:58:38.280637238 +0100
+++ gcc/testsuite/gcc.c-torture/execute/20050104-1.c 2005-01-04 17:59:01.243555813 +0100
@@ -0,0 +1,23 @@
+/* PR tree-optimization/19060 */
+
+void abort (void);
+
+static
+long long min ()
+{
+ return -__LONG_LONG_MAX__ - 1;
+}
+
+void
+foo (long long j)
+{
+ if (j > 10 || j < min ())
+ abort ();
+}
+
+int
+main (void)
+{
+ foo (10);
+ return 0;
+}
Jakub