[Bug tree-optimization/77647] [6/7 Regression] Missed opportunity to use register value causes additional load

2016-10-05 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77647

Jeffrey A. Law  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||law at redhat dot com
 Resolution|--- |DUPLICATE

--- Comment #3 from Jeffrey A. Law  ---
Fundamentally the same issue as 71947.

*** This bug has been marked as a duplicate of bug 71947 ***

[Bug tree-optimization/77647] [6/7 Regression] Missed opportunity to use register value causes additional load

2016-09-20 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77647

Richard Biener  changed:

   What|Removed |Added

 CC||law at gcc dot gnu.org,
   ||rguenth at gcc dot gnu.org
  Known to work||5.4.0
   Target Milestone|--- |6.3
Summary|Missed opportunity to use   |[6/7 Regression] Missed
   |register value causes   |opportunity to use register
   |additional load |value causes additional
   ||load

--- Comment #2 from Richard Biener  ---
DOM doesn't propagate the equivalence on the not unreachable edge, that is,
it doesn't copy-propagate because of PR71947

  if (ret_3 != _5)
goto ;
  else
goto ;

  :
  __builtin_unreachable ();

  :
  _4 = ret_3 + _5;

DOM does the following after Jeffs patch:

Optimizing block #4

1>>> STMT 1 = ret_3 le_expr _5
1>>> STMT 1 = ret_3 ge_expr _5
1>>> STMT 1 = ret_3 eq_expr _5
1>>> STMT 0 = ret_3 ne_expr _5
0>>> COPY ret_3 = _5
0>>> COPY _5 = ret_3
Optimizing statement _4 = ret_3 + _5;
  Replaced 'ret_3' with variable '_5'
  Replaced '_5' with variable 'ret_3'
  Folded to: _4 = ret_3 + _5;

which is of course a quite stupid replacement.  I still believe the change
should be reverted ... Jeff, are you still investigating this?

Works on the GCC 5 branch:

Optimizing block #4

0>>> COPY _5 = ret_3
1>>> STMT 1 = ret_3 le_expr _5
1>>> STMT 1 = ret_3 ge_expr _5
1>>> STMT 1 = ret_3 eq_expr _5
1>>> STMT 0 = ret_3 ne_expr _5
Optimizing statement _4 = ret_3 + _5;
  Replaced '_5' with variable 'ret_3'
LKUP STMT _4 = ret_3 plus_expr ret_3
2>>> STMT _4 = ret_3 plus_expr ret_3

with assembly

foo:
.LFB1:
.cfi_startproc
#APP
# 4 "t.c" 1
movq  (%rdi),%rax

# 0 "" 2
#NO_APP
addq%rax, %rax
ret