[Bug tree-optimization/47413] Constant Propagation and Virtual Function Tables

2017-08-18 Thread law at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47413

Jeffrey A. Law  changed:

   What|Removed |Added

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

--- Comment #4 from Jeffrey A. Law  ---
Fixed, not really sure when though:

int main() ()
{
  struct obj * obj;
  int _1;

;;   basic block 2, loop depth 0, count 0, freq 1, maybe hot
;;prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED)
;;pred:   ENTRY [100.0%]  (FALLTHRU,EXECUTABLE)
  obj_5 = malloc (8);
  if (obj_5 == 0B)
goto ; [30.86%]
  else
goto ; [69.14%]
;;succ:   4 [30.9%]  (TRUE_VALUE,EXECUTABLE)
;;3 [69.1%]  (FALSE_VALUE,EXECUTABLE)

;;   basic block 3, loop depth 0, count 0, freq 6914, maybe hot
;;prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)
;;pred:   2 [69.1%]  (FALSE_VALUE,EXECUTABLE)
  printf ("%d\n", 1337);
;;succ:   4 [100.0%]  (FALLTHRU,EXECUTABLE)

;;   basic block 4, loop depth 0, count 0, freq 1, maybe hot
;;prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED)
;;pred:   2 [30.9%]  (TRUE_VALUE,EXECUTABLE)
;;3 [100.0%]  (FALLTHRU,EXECUTABLE)
  # _1 = PHI <0(2), 1(3)>
  return _1;
;;succ:   EXIT [100.0%]

}

Note passing 1337 directly into the printf call.

[Bug tree-optimization/47413] Constant Propagation and Virtual Function Tables

2014-09-29 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47413

--- Comment #3 from rguenther at suse dot de rguenther at suse dot de ---
On Fri, 26 Sep 2014, hubicka at gcc dot gnu.org wrote:

 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47413
 
 Jan Hubicka hubicka at gcc dot gnu.org changed:
 
What|Removed |Added
 
  CC||hubicka at gcc dot gnu.org
 
 --- Comment #2 from Jan Hubicka hubicka at gcc dot gnu.org ---
 Current mainline gets pretty close:
 ;; Function int f1337(obj*) (_ZL5f1337P3obj, funcdef_no=19, decl_uid=3418,
 cgraph_uid=19, symbol_order=19)
 
 int f1337(obj*) (struct obj * obj)
 {
   bb 2:
   return 1337;
 
 }
 
 
 
 ;; Function int main() (main, funcdef_no=22, decl_uid=3427, cgraph_uid=22,
 symbol_order=22) (executed once)
 
 Removing basic block 5
 int main() ()
 {
   struct obj * obj;
   int _1;
   int _10;
 
   bb 2:
   obj_7 = malloc (8);
   if (obj_7 == 0B)
 goto bb 4;
   else
 goto bb 3;
 
   bb 3:
   obj_7-vtab = vtab1337;
   _10 = f1337 (obj_7);
   printf (%d\n, _10);
 
   bb 4:
   # _1 = PHI 0(2), 1(3)
   return _1;
 
 }
 
 So we are down to one missing inline. After FRE we get:
 
   bb 2:
   obj_13 = malloc (8);
   if (obj_13 == 0B)
 goto bb 4;
   else
 goto bb 3;
 
   bb 3:
   obj_13-vtab = vtab1337;
 
   bb 4:
   # _14 = PHI 0B(2), obj_13(3)
   if (_14 == 0B)
 goto bb 6;
   else
 goto bb 5;
 
   bb 5:
   _4 = _14-vtab;
   _15 = _4-f;
   _16 = _15 (_14);
   printf (%d\n, _16);
 
 
 So purely local problem. I suppose FRE could propagate through by knowing that
 on the other path program with segfault?

Not in the way value-numbering works (it value-numbers _14 as VARYING
obviously).  The above feels like a missed jump-threading opportunity
to me.  Eventually we could also help DOM/copyprop with replacing
the test by _14 != ohj_13 ...

In my view DOM should be able to figure out a value for _14
on the else edge as well (doesn't exactly fit DOM but certainly
most easily implemented there)


[Bug tree-optimization/47413] Constant Propagation and Virtual Function Tables

2014-09-26 Thread hubicka at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47413

Jan Hubicka hubicka at gcc dot gnu.org changed:

   What|Removed |Added

 CC||hubicka at gcc dot gnu.org

--- Comment #2 from Jan Hubicka hubicka at gcc dot gnu.org ---
Current mainline gets pretty close:
;; Function int f1337(obj*) (_ZL5f1337P3obj, funcdef_no=19, decl_uid=3418,
cgraph_uid=19, symbol_order=19)

int f1337(obj*) (struct obj * obj)
{
  bb 2:
  return 1337;

}



;; Function int main() (main, funcdef_no=22, decl_uid=3427, cgraph_uid=22,
symbol_order=22) (executed once)

Removing basic block 5
int main() ()
{
  struct obj * obj;
  int _1;
  int _10;

  bb 2:
  obj_7 = malloc (8);
  if (obj_7 == 0B)
goto bb 4;
  else
goto bb 3;

  bb 3:
  obj_7-vtab = vtab1337;
  _10 = f1337 (obj_7);
  printf (%d\n, _10);

  bb 4:
  # _1 = PHI 0(2), 1(3)
  return _1;

}

So we are down to one missing inline. After FRE we get:

  bb 2:
  obj_13 = malloc (8);
  if (obj_13 == 0B)
goto bb 4;
  else
goto bb 3;

  bb 3:
  obj_13-vtab = vtab1337;

  bb 4:
  # _14 = PHI 0B(2), obj_13(3)
  if (_14 == 0B)
goto bb 6;
  else
goto bb 5;

  bb 5:
  _4 = _14-vtab;
  _15 = _4-f;
  _16 = _15 (_14);
  printf (%d\n, _16);


So purely local problem. I suppose FRE could propagate through by knowing that
on the other path program with segfault?


[Bug tree-optimization/47413] Constant Propagation and Virtual Function Tables

2011-01-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47413

Richard Guenther rguenth at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2011.01.25 11:35:50
 CC||rguenth at gcc dot gnu.org
 Ever Confirmed|0   |1

--- Comment #1 from Richard Guenther rguenth at gcc dot gnu.org 2011-01-25 
11:35:50 UTC ---
With GCC 4.6 I see

bb 3:
  obj_11-vtab = vtab1337;
  D.3820_15 = f1337 (obj_11);
  printf (%d\n[0], D.3820_15);

so it calls f1337 directly, but it doesn't inline it.

We are partly confused by the CFG caused by the NULL test:

bb 2:
  obj_11 = malloc (8);
  if (obj_11 == 0B)
goto bb 4;
  else
goto bb 3;

bb 3:
  obj_11-vtab = vtab1337;

bb 4:
  # obj_12 = PHI 0B(2), obj_11(3)
  if (obj_12 == 0B)
goto bb 6;
  else
goto bb 5;

bb 5:
  D.3822_13 = obj_12-vtab;
  D.3821_14 = D.3822_13-f;
  D.3820_15 = D.3821_14 (obj_12);

so it takes several iterations through different optimizers to eventually
constant propagate the function address (jump-threading the test in BB4,
which only happens late by DOM).