https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87845

            Bug ID: 87845
           Summary: cselib_hasher::hash function does not match with
                    cselib_hasher::equal operator
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
  Target Milestone: ---

As mentioned in the following sub-thread:
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01878.html
we have situations where ::equal returns true for a pair of value, which their
::hash value is different.

Let me demonstrate that on the following example:

$ cat toreduce.i
int a, c, d, e, f, i, j, k, l;
typedef struct {
  char b[8];
} g;
g h;

int o(int, int, int);
int p();
int q();

void m() {
  int n, b = o(a, d, e);
  if (b)
    goto ac;
  if (a)
    p();
  if (c)
    if (d)
      if (l == 0 && n == 0)
        ;
      else {
        h.b[7] = n >> 24;
        h.b[6] = n >> 16;
        h.b[5] = n >> 8;
        h.b[4] = n;
      }
  return;
ac:
  q(k, f, 1, l, &n, i, j);
}

If I apply following patch:
diff --git a/gcc/cselib.c b/gcc/cselib.c
index 6d3a4078c68..821bee6aa86 100644
--- a/gcc/cselib.c
+++ b/gcc/cselib.c
@@ -101,7 +101,7 @@ struct cselib_hasher : nofree_ptr_hash <cselib_val>
 inline hashval_t
 cselib_hasher::hash (const cselib_val *v)
 {
-  return v->hash;
+  return 0;
 }

 /* The equality test for our hash table.  The first argument V is a table

I see a divergence in:

$ diff -u /tmp/before/toreduce.i.279r.postreload
/tmp/after/toreduce.i.279r.postreload
--- /tmp/before/toreduce.i.279r.postreload      2018-11-01 12:48:01.046221868
+0100
+++ /tmp/after/toreduce.i.279r.postreload       2018-11-01 12:48:27.778779308
+0100
@@ -1,7 +1,6 @@

 ;; Function m (m, funcdef_no=0, decl_uid=1924, cgraph_uid=1, symbol_order=10)

-rescanning insn with uid = 46.
 starting the processing of deferred insns
 ending the processing of deferred insns

@@ -16,7 +15,7 @@
...@@ -181,7 +180,8 @@
 (insn 46 67 47 8 (parallel [
             (set (reg:CCZ 17 flags)
                 (compare:CCZ (ior:SI (reg:SI 0 ax [orig:101 l ] [101])
-                        (reg:SI 1 dx))
+                        (mem/c:SI (plus:DI (reg/f:DI 7 sp)
+                                (const_int 12 [0xc])) [1 n+0 S4 A32]))
                     (const_int 0 [0])))
             (clobber (reg:SI 0 ax [orig:101 l ] [101]))
         ]) "/home/marxin/Programming/tramp3d/toreduce.i":19:10 451 {*iorsi_3}

which eventually leads to following assembly divergence:

diff -u 1 2
--- 1   2018-11-01 12:52:07.839338756 +0100
+++ 2   2018-11-01 12:52:07.855339094 +0100
@@ -24,9 +24,9 @@
        movl    d(%rip), %eax
        testl   %eax, %eax
        je      .L1
-       movl    l(%rip), %eax
-       orl     12(%rsp), %eax
        movl    12(%rsp), %edx
+       movl    l(%rip), %eax
+       orl     %edx, %eax
        je      .L1
        movl    %edx, h+4(%rip)
 .L1:

Can please anybody familiar with cselib help me here?
Thanks

Reply via email to