public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-3762] PR97359: Do not cache relops in GORI cache.
@ 2020-10-10  8:26 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2020-10-10  8:26 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:14db1dfcd18e4d2712a043bdcd3976fcfb0642c2

commit r11-3762-g14db1dfcd18e4d2712a043bdcd3976fcfb0642c2
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Sat Oct 10 08:28:52 2020 +0200

    PR97359: Do not cache relops in GORI cache.
    
    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.
    
    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.

Diff:
---
 gcc/gimple-range-gori.cc       | 10 ++--------
 gcc/testsuite/gcc.dg/pr97359.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 8 deletions(-)

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)
+      ;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-10  8:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10  8:26 [gcc r11-3762] PR97359: Do not cache relops in GORI cache Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).