diff mbox series

[COMMITTED] PR tree-optimization/103003 - Don't register nonsensical relations.

Message ID fc32ce14-f679-6a6e-b825-00eaa8b05670@redhat.com
State New
Headers show
Series [COMMITTED] PR tree-optimization/103003 - Don't register nonsensical relations. | expand

Commit Message

Andrew MacLeod Nov. 1, 2021, 1:31 p.m. UTC
The testcase in question has a stmt of the form:
    _10 = _4 <= _4;

We know this resolves to true, but when proce3ssing outgoing edges on 
the following branch, we try to register the relations

_4 <= _4  and _4 > _4 on the 2 outgoing edges...  which is nonsense of 
course.

this patch simply changes the registry to bai is the 2 ssa_anames are 
the same.

If the relation is ==, then equality is already implied, and any other 
relation just doesn't make much sense.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew
diff mbox series

Patch

commit 0187c03be31a58ba561d535687dc00c94f0ff1aa
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Sat Oct 30 11:00:49 2021 -0400

    Don't register nonsensical relations.
    
            gcc/
            PR tree-optimization/103003
            * value-relation.cc (dom_oracle::register_relation): If the 2
            ssa names are the same, don't register any relation.
    
            gcc/testsuite/
            * gcc.dg/pr103003.c: New.

diff --git a/gcc/testsuite/gcc.dg/pr103003.c b/gcc/testsuite/gcc.dg/pr103003.c
new file mode 100644
index 00000000000..d3d65f8b6a6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103003.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+typedef char int8_t;
+int8_t c_4, uli_5;
+unsigned short us_6;
+void func_1() {
+  int uli_9;
+  short ptr_16ptr_11 = &uli_9; /* { dg-warning "initialization of*" } */
+  for (; us_6 <= 6;)
+    if ((us_6 *= uli_9) < (uli_5 || 0) ?: ((c_4 = us_6) >= us_6) - uli_5)
+      uli_9 = 9;
+}
diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index f572bcd4dc2..f1e46d38de1 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -877,7 +877,13 @@  relation_oracle::register_edge (edge e, relation_kind k, tree op1, tree op2)
 void
 dom_oracle::register_relation (basic_block bb, relation_kind k, tree op1,
 			       tree op2)
-{  // Equivalencies are handled by the equivalence oracle.
+{
+  // If the 2 ssa_names are the same, do nothing.  An equivalence is implied,
+  // and no other relation makes sense.
+  if (op1 == op2)
+    return;
+
+  // Equivalencies are handled by the equivalence oracle.
   if (k == EQ_EXPR)
     equiv_oracle::register_relation (bb, k, op1, op2);
   else