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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1
                 CC|                            |law at gcc dot gnu.org

--- Comment #5 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
I think this is fold_using_range getting confused with DOM changing the IL from
under it.

fold_using_range::relation_fold_and_or() is (incorrectly) folding the final
conditional as always true:

  <bb 2> [local count: 79134772]:
  a.0_1 = a;
  b = a.0_1;
  a.1_15 = a.0_1;
  _16 = a.0_1 < -117;
  _17 = a.0_1 >= -83;
  _18 = _16 | _17;
  if (_18 != 0)

But the IL on entry to DOM is actually:

  <bb 2> [local count: 79134772]:
  a.0_1 = a;
  b = a.0_1;
  a.1_15 = a;
  _16 = a.1_15 < -117;
  _17 = a.1_15 >= -83;
  _18 = _16 | _17;
  if (_18 != 0)

DOM replaced a.1_15=a with a.1_15=a.0_1:

Optimizing statement a.1_15 = a;
LKUP STMT a.1_15 = a with .MEM_7
FIND: a.0_1
  Replaced redundant expr 'a' with 'a.0_1'


...and then cproped the a.1_15 into the uses:

Optimizing statement _16 = a.1_15 < -117;
  Replaced 'a.1_15' with variable 'a.0_1'
Optimizing statement _17 = a.1_15 >= -83;
  Replaced 'a.1_15' with variable 'a.0_1'

By the time we get to the conditional, the ranger thinks it can fold the
conditional:

Optimizing statement if (_18 != 0)
  Relation adjustment: _16  and _17  combine to produce [irange] _Bool [1, 1]
  Replaced '_18' with constant '1'

Since the IL on entry to DOM is different than what evrp would see, I added an
evrp instance before DOM and ran it with -O2 -fno-tree-dominator-opts, but evrp
does not fold the conditional.  So this is something particular to what we're
doing in DOM.

In this hacked up evrp instance I see ssa1_dep2 and ssa2_dep2 are both NULL
when we query "_18 = _16 | _17", so we never fold the conditional:

  // Both names will need to have 2 direct dependencies.
  tree ssa1_dep2 = src.gori ()->depend2 (ssa1);
  tree ssa2_dep2 = src.gori ()->depend2 (ssa2);
  if (!ssa1_dep2 || !ssa2_dep2)
    return;

  (gdb) p ssa1_dep2
  $35 = <tree 0x0>
  (gdb) p ssa2_dep2
  $36 = <tree 0x0>

OTOH, in DOM we have:

(gdb) p debug(ssa1_dep2)
a.0_1
$33 = void
(gdb) p debug(ssa2_dep2)
a.0_1
$34 = void
(gdb) 

So the dependencies in DOM's use of ranger in flight are different than what
evrp would see.

Andrew, would the changed IL cause the folding problem above?

Reply via email to