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.
{
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:
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));
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;
--- /dev/null
+/* { 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)
+ ;
+}