https://gcc.gnu.org/g:285e8e2a2bd4652e6beaed6e65444c4295a77bc2

commit r17-4173-g285e8e2a2bd4652e6beaed6e65444c4295a77bc2
Author: Andrew MacLeod <[email protected]>
Date:   Thu Sep 10 14:17:58 2026 -0400

    Fix ranger transitive table.
    
    The transitive relation table was incorrect for equal and not equal.
    x == y, y != z  was producing no relation for x,z  rather than x != z.
    Likewise x != y, y == z was not producing x != z.
    
            gcc/
            * value-relation.cc (rr_transitive_table): Update.
    
            gcc/testsuite/
            * gcc.dg/tree-ssa/evrp-trans3.c: New.

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/evrp-trans3.c | 23 +++++++++++++++++++++++
 gcc/value-relation.cc                       |  4 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp-trans3.c 
b/gcc/testsuite/gcc.dg/tree-ssa/evrp-trans3.c
new file mode 100644
index 000000000000..fb6cfc41107e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/evrp-trans3.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+void link_error ();
+
+/* The transitive table was incorrect for x == y, y != z. */
+void test1 (int x, int y, int z)
+{
+  if (x == y)
+    if (y != z)
+      if (x == z)
+        link_error ();
+}
+
+/* The transitive table was incorrect for x != y, y == z. */
+void test2 (int x, int y, int z)
+{
+  if (x != y)
+    if (y == z)
+      if (x == z)
+        link_error ();
+}
+/* { dg-final { scan-tree-dump-not "link_error" "evrp" } } */
diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index 2e95d12b5785..afe78ed50b71 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -169,10 +169,10 @@ static const unsigned char 
rr_transitive_table[VREL_LAST][VREL_LAST] = {
     VREL_GE, VREL_VARYING },
 // VREL_EQ
   { VREL_VARYING, VREL_VARYING, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_EQ,
-    VREL_VARYING },
+    VREL_NE },
 // VREL_NE
   { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
-    VREL_VARYING, VREL_VARYING, VREL_VARYING } };
+    VREL_VARYING, VREL_NE, VREL_VARYING } };
 
 // Apply transitive operation between relation R1 and relation R2, and
 // return the resulting relation, if any.

Reply via email to