This is the mail archive of the gcc-patches@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]

[PATCH] Fix cut-and-pasto in ifcvt.c/find_if_case_2



I think I've found a bug in ifcvt.c/find_if_case_2().

I noticed this problem because map_fog.i fails to be optimized
as well as before. I tracked this down to an optimization which
is not being performed; specifically case 2 of the IF-THEN-ELSE
conversion:

/* Look for IF-THEN-ELSE cases in which one of THEN or ELSE is
   transformable, but not necessarily the other.  There need be no
   JOIN block.

   Return TRUE if we were successful at converting the the block.

   Cases we'd like to look at:
...
   (2)
        if (test) goto E; // x not live
        x = big();
        goto L;
        E:
        x = b;
        goto M;

   becomes

        x = b;
        if (test) goto M;
        x = big();
        goto L;

This optimization is performed by find_if_case_2(). One of the
conditions for applying this optimization is failing:

  /* ELSE is small.  */
  if (count_bb_insns (then_bb) > BRANCH_COST)
    return FALSE;

This code looks suspicious because the comments do not match the code.
The comment says "check if ELSE is small" but it's actually testing
the size of the THEN basic block.

This code appears in gcc-3.0.4 as well, but the RTX generated by 3.0.4
just happens to match this condition, e.g.  (count_bb_insns(then_bb) < BRANCH_COST)
so the optimization was applied successfully.

If I patch this code to:

  /* ELSE is small.  */
  if (count_bb_insns (else_bb) > BRANCH_COST) 
    return FALSE;

then the optimization works as expected and the number of cache alignments
generated due to BARRIER decreases significantly.

Before patch:

[tm@localhost test]$ grep "align 5" map_fog_partial.s | wc -l
    113

After patch:

[tm@localhost test]$ grep "align 5" map_fog_partial.s | wc -l
     17

I'm currently bootstrapping on x86-linux, but as this machine is slow
(P2/300) it will take a while...can anybody with a faster machine help?

Here is the patch:

2002-08-07  Toshiyasu Morita  <toshiyasu.morita@hsa.hitachi.com>

	* ifcvt.c (find_if_case_2): Test correct basic block for size.

*** ifcvt.c.bak	Wed Aug  7 10:18:02 2002
--- ifcvt.c	Wed Aug  7 16:13:12 2002
*************** find_if_case_2 (test_bb, then_edge, else
*** 2769,2775 ****
  	     test_bb->index, else_bb->index);
  
    /* ELSE is small.  */
!   if (count_bb_insns (then_bb) > BRANCH_COST)
      return FALSE;
  
    /* Registers set are dead, or are predicable.  */
--- 2769,2775 ----
  	     test_bb->index, else_bb->index);
  
    /* ELSE is small.  */
!   if (count_bb_insns (else_bb) > BRANCH_COST)
      return FALSE;
  
    /* Registers set are dead, or are predicable.  */


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