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



bin.cheng <amker.cheng at gmail dot com> changed:



           What    |Removed                     |Added

----------------------------------------------------------------------------

                 CC|                            |amker.cheng at gmail dot

                   |                            |com



--- Comment #17 from bin.cheng <amker.cheng at gmail dot com> 2012-11-20 
07:08:18 UTC ---

Hi,

I spent some time analyzing this bug and I think I understand the problem now.

For below dump file from trunk/cris-elf when compiling the attached k.c:

;; Function foo (foo, funcdef_no=0, decl_uid=1323, cgraph_uid=0)



;; 1 loops found

;;

;; Loop 0

;;  header 0, latch 1

;;  depth 0, outer -1

;;  nodes: 0 1 2 3 4 5 6 7 8 9 10 11

;; 2 succs { 10 3 }

;; 3 succs { 11 4 }

;; 4 succs { 11 }

;; 5 succs { 6 7 }

;; 6 succs { 9 }

;; 7 succs { 6 8 }

;; 8 succs { 9 }

;; 9 succs { 1 }

;; 10 succs { 5 6 }

;; 11 succs { 5 8 }

foo (int n, int l, int m, int r)

{

  int v;

  int g.1;

  int g.0;



  <bb 2>:

  if (n_4(D) <= 9)

    goto <bb 10>;

  else

    goto <bb 3>;



  <bb 3>:

  if (m_5(D) > 100)

    goto <bb 11>;

  else

    goto <bb 4>;



  <bb 4>:

  goto <bb 11>;



  <bb 5>:

  # v_14 = PHI <v_13(11), r_7(D)(10)>

  g.0_9 = g;

  g.1_10 = g.0_9 + 1;

  g = g.1_10;

  if (n_4(D) <= 9)

    goto <bb 6>;

  else

    goto <bb 7>;



  <bb 6>:

  # v_17 = PHI <v_14(5), v_14(7), r_7(D)(10)>

  blah (v_17);

  goto <bb 9>;



  <bb 7>:

  if (m_5(D) > 100)

    goto <bb 6>;

  else

    goto <bb 8>;



  <bb 8>:



  <bb 9>:

  return 0;



  <bb 10>:

  if (m_5(D) != 0)

    goto <bb 5>;

  else

    goto <bb 6>;



  <bb 11>:

  # v_13 = PHI <r_7(D)(3), v_6(D)(4)>

  if (m_5(D) != 0)

    goto <bb 5>;

  else

    goto <bb 8>;



}



There are two flaws in tree-ssa-uninit.c revealing this bug.

1. GCC try to find def_chains from cd_root(which is the closest dominating bb 

for phi_bb) to phi_bb, but only find use_predicates from phi_bb to use_bb. In

general case with canonical CFG, this is fine, but in non-canonical CFG, it's

possible to have ancestor basic block of phi_bb in def_chains which have branch

that never reach to phi_bb, like basic block 10 reported in this PR. In this

scenario the corresponding condition should not be counted in

def_chains(edge<10, 5> in this case).

There are two methods to fix this:

   a) find use predicates from dom(phi_bb), rather than phi_bb in non-canonical

CFGs.

   b) prune branch conditions that are irrelevant to this use/def in

def_chains.

Method a is simpler, but the problem is it results in more dep_chains which

might exceeds the limit MAX_NUM_CHAINS. As for method b), I haven't got any

clue to implement it.



2. When calling is_use_properly_guarded in find_uninit_use, GCC finds

predicates from source basic block if the use_stmt is a phi node. This results

in missing condition at the end of each def_chain. Different from the first

issue, this can be easily fixed.

Reply via email to