This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug optimization/14731] [tree-ssa] missed jump threading on the tree level


------- Additional Comments From law at redhat dot com  2004-05-04 20:59 -------
Subject: Re:  New: [tree-ssa] missed jump threading on 
 the tree level

In message <20040325065108.14731.pinskia@gcc.gnu.org>, "pinskia at gcc dot gnu 
dot org" writes:
 >Some more missed jump threading on the tree level.
 >#ifdef __cplusplus
 >#define _Bool bool
 >#endif
 >
 >int link_error(void);
 >int s(void);
 >
 >int t(int i)
 >{
 >  _Bool g = i == 4;
 > int h = g;
 > _Bool j = h;
 > int k = j;
 > _Bool l = k == 0;
 > _Bool o = !l;
 > int m = o;
 >
 > if (m)
 >  if (i != 4)
 >   return link_error();
 > return 0;
 >}
Yes.  The easiest way I see to deal with this is to have the forward
propagation code handle cascading opportunities to forward propagate
single use variables.

That turns out to be rather easy by having two worklists (one for 
statements to reexamine, one for variables which we may be able to
propagate).  We iterate until the worklists are empty.


So before the single use variable propagation phase we have something
like this:


  # BLOCK 0
  # PRED: ENTRY [100.0%]  (fallthru)
  g_1 = i_5 == 4;
  j_2 = g_1 != 0;
  l_3 = j_2 == 0;
  o_4 = l_3 == 0;
  if (o_4 != 0) goto <L12>; else goto <L14>;
  # SUCC: 3 [50.0%]  (false) 1 [50.0%]  (true)

  # BLOCK 1
  # PRED: 0 [50.0%]  (true)
<L12>:;
  if (i_5 != 4) goto <L13>; else goto <L14>;
  # SUCC: 3 [31.9%]  (false) 2 [68.0%]  (true)
  [ ... ]


After forward propagation we have:
  # BLOCK 0
  # PRED: ENTRY [100.0%]  (fallthru)
  if (i_5 == 4) goto <L12>; else goto <L14>;
  # SUCC: 3 [50.0%]  (false) 1 [50.0%]  (true)
  
  # BLOCK 1 
  # PRED: 0 [50.0%]  (true) 
<L12>:;
  if (i_5 != 4) goto <L13>; else goto <L14>;
  # SUCC: 3 [31.9%]  (false) 2 [68.0%]  (true)
  [ ... ]


Which DOM then turns into:

  # BLOCK 0 
  # PRED: ENTRY [100.0%]  (fallthru,exec)
  return 0;
  # SUCC: EXIT [100.0%] 


Which looks like what we want :-)

jeff



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14731


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]