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.
This commit is contained in:
Aldy Hernandez 2020-10-10 08:28:52 +02:00
parent c74a0e82fa
commit 14db1dfcd1
2 changed files with 13 additions and 8 deletions

View File

@ -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;

View File

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