diff mbox series

[PUSHED] PR97359: Do not cache relops in GORI cache.

Message ID 20201010082810.174599-1-aldyh@redhat.com
State New
Headers show
Series [PUSHED] PR97359: Do not cache relops in GORI cache. | expand

Commit Message

Aldy Hernandez Oct. 10, 2020, 8:28 a.m. UTC
logical_stmt_cache::cacheable_p() returns true for relops, but
logical_combine (which does the caching) doesn't handle them and ICEs.
This patch fixes the inconsistency by returning false for relops.

This was working before because even though logical_combine doesn't
handle relops, statements with only one SSA are handled in cache_stmt,
which seems like the only statement we've ever encountered (even through
a full Fedora build).

	lhs = s_5 > 999;

However, with two SSA operands we ICE because logical_combine doesn't
handle them:

	lhs = s_5 > y_8;

We can either return false for relops in cacheable_p, or fix
logical_combine to handle them.  The original idea was to only cache
ANDs and ORs, so I've done the former to unbreak trunk.

We can decide later if there was ever any benefit in caching relops.
Andrew, do you have any thoughts on this?

Pushed to trunk.

gcc/ChangeLog:

	PR tree-optimization/97359
	* gimple-range-gori.cc (logical_stmt_cache::cacheable_p): Only
	handle ANDs and ORs.
	(gori_compute_cache::cache_stmt): Adjust comment.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr97359.c: New test.
---
 gcc/gimple-range-gori.cc       | 10 ++--------
 gcc/testsuite/gcc.dg/pr97359.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr97359.c
diff mbox series

Patch

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index eaf1a445c25..986427669a7 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -1161,12 +1161,6 @@  logical_stmt_cache::cacheable_p (gimple *stmt, const irange *lhs_range) const
     {
       switch (gimple_expr_code (stmt))
 	{
-	case LT_EXPR:
-	case LE_EXPR:
-	case GT_EXPR:
-	case GE_EXPR:
-	case EQ_EXPR:
-	case NE_EXPR:
 	case TRUTH_AND_EXPR:
 	case BIT_AND_EXPR:
 	case TRUTH_OR_EXPR:
@@ -1294,7 +1288,7 @@  gori_compute_cache::cache_stmt (gimple *stmt)
   tree op2 = gimple_range_operand2 (stmt);
   int_range_max r_true_side, r_false_side;
 
-  // LHS = s_5 > 999.
+  // LHS = s_5 && 999.
   if (TREE_CODE (op2) == INTEGER_CST)
     {
       range_operator *handler = range_op_handler (code, TREE_TYPE (lhs));
@@ -1305,7 +1299,7 @@  gori_compute_cache::cache_stmt (gimple *stmt)
       handler->op1_range (r_false_side, type, m_bool_zero, op2_range);
       m_cache->set_range (lhs, op1, tf_range (r_true_side, r_false_side));
     }
-  // LHS = s_5 > b_8.
+  // LHS = s_5 && b_8.
   else if (tree cached_name = m_cache->same_cached_name (op1, op2))
     {
       tf_range op1_range, op2_range;
diff --git a/gcc/testsuite/gcc.dg/pr97359.c b/gcc/testsuite/gcc.dg/pr97359.c
new file mode 100644
index 00000000000..142542e404c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97359.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -w" } */
+
+typedef unsigned int uint32_t;
+int a;
+void b(uint32_t c) {
+  uint32_t *d = &c;
+  for (; a;)
+    for (;; (*d %= a) / (*d > 1 > (c > 0)) ?: d)
+      ;
+}