condexec merge part 6

Richard Henderson rth@cygnus.com
Wed Apr 26 23:02:00 GMT 2000


Always estimate branch probabilities if we don't have real data.

This code does a better job than mostly_true_jump from reorg.c
(which should now be gutted, but I didn't yet); can be used to
set branch prediction bits on branches; and will shortly be used
to control whether or not certain if-conversion changes are
performed, and from which side of the branch.

Also fixes a bug in jump.c.


r~

        * jump.c (invert_jump): Always invert REG_BR_PROB.  Do it correctly.

        * bb-reorder.c (reorder_basic_blocks): Don't run estimate_probability.
        * flow.c (calculate_loop_depth): Remove.
        * output.h (calculate_loop_depth): Don't declare.
        * toplev.c (rest_of_compilation): Expand calculate_loop_depth
        inline; run estimate_probability at the same time.

Index: bb-reorder.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/bb-reorder.c,v
retrieving revision 1.5
diff -c -p -d -r1.5 bb-reorder.c
*** bb-reorder.c	2000/04/18 01:32:43	1.5
--- bb-reorder.c	2000/04/27 05:54:40
*************** reorder_basic_blocks ()
*** 813,822 ****
    /* Dump loop information.  */
    flow_loops_dump (&loops_info, rtl_dump_file, 0);
  
-   /* Estimate using heuristics if no profiling info is available.  */
-   if (! flag_branch_probabilities)
-     estimate_probability (&loops_info);
- 
    reorder_last_visited = BASIC_BLOCK (0);
  
    for (i = 0; i < n_basic_blocks; i++)
--- 813,818 ----
Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.261
diff -c -p -d -r1.261 flow.c
*** flow.c	2000/04/27 05:42:25	1.261
--- flow.c	2000/04/27 05:54:40
*************** tidy_fallthru_edges ()
*** 2469,2491 ****
  	tidy_fallthru_edge (s, b, c);
      }
  }
- 
- /* Discover and record the loop depth at the head of each basic block.  */
- 
- void
- calculate_loop_depth (dump)
-      FILE *dump;
- {
-   struct loops loops;
- 
-   /* The loop infrastructure does the real job for us.  */
-   flow_loops_find (&loops);
- 
-   if (dump)
-     flow_loops_dump (&loops, dump, 0);
- 
-   flow_loops_free (&loops);
- }
  
  /* Perform data flow analysis.
     F is the first insn of the function; FLAGS is a set of PROP_* flags
--- 2469,2474 ----
Index: jump.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/jump.c,v
retrieving revision 1.117
diff -c -p -d -r1.117 jump.c
*** jump.c	2000/04/18 22:34:10	1.117
--- jump.c	2000/04/27 05:54:40
*************** invert_jump (jump, nlabel)
*** 4431,4447 ****
  
    if (redirect_jump (jump, nlabel))
      {
!       if (flag_branch_probabilities)
! 	{
! 	  rtx note = find_reg_note (jump, REG_BR_PROB, 0);
  
! 	  /* An inverted jump means that a probability taken becomes a
! 	     probability not taken.  Subtract the branch probability from the
! 	     probability base to convert it back to a taken probability.
! 	     (We don't flip the probability on a branch that's never taken.  */
! 	  if (note && XINT (XEXP (note, 0), 0) >= 0)
! 	    XINT (XEXP (note, 0), 0) = REG_BR_PROB_BASE - XINT (XEXP (note, 0), 0);
! 	}
  
        return 1;
      }
--- 4431,4443 ----
  
    if (redirect_jump (jump, nlabel))
      {
!       /* An inverted jump means that a probability taken becomes a
! 	 probability not taken.  Subtract the branch probability from the
! 	 probability base to convert it back to a taken probability.  */
  
!       rtx note = find_reg_note (jump, REG_BR_PROB, 0);
!       if (note)
! 	XEXP (note, 0) = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (note, 0)));
  
        return 1;
      }
Index: output.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/output.h,v
retrieving revision 1.46
diff -c -p -d -r1.46 output.h
*** output.h	2000/04/27 04:42:08	1.46
--- output.h	2000/04/27 05:54:40
*************** extern int regno_clobbered_at_setjmp	PAR
*** 134,140 ****
  extern void dump_flow_info		PARAMS ((FILE *));
  extern void find_basic_blocks		PARAMS ((rtx, int, FILE *));
  extern void cleanup_cfg			PARAMS ((rtx));
- extern void calculate_loop_depth      PARAMS ((FILE *));
  extern void free_basic_block_vars     PARAMS ((int));
  extern void set_block_num             PARAMS ((rtx, int));
  #endif
--- 134,139 ----
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.324
diff -c -p -d -r1.324 toplev.c
*** toplev.c	2000/04/27 04:42:09	1.324
--- toplev.c	2000/04/27 05:54:40
*************** rest_of_compilation (decl)
*** 3246,3252 ****
         find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
         cleanup_cfg (insns);
         if (optimize)
! 	 calculate_loop_depth (rtl_dump_file);
         life_analysis (insns, rtl_dump_file, PROP_FINAL);
         mark_constant_function ();
       });
--- 3246,3267 ----
         find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
         cleanup_cfg (insns);
         if (optimize)
! 	 {
! 	   struct loops loops;
! 
! 	   /* Discover and record the loop depth at the head of each basic
! 	      block.  The loop infrastructure does the real job for us.  */
! 	   flow_loops_find (&loops);
! 
! 	   /* Estimate using heuristics if no profiling info is available.  */
! 	   if (! flag_branch_probabilities)
! 	     estimate_probability (&loops);
! 
! 	   if (rtl_dump_file)
! 	     flow_loops_dump (&loops, rtl_dump_file, 0);
! 
! 	   flow_loops_free (&loops);
! 	 }
         life_analysis (insns, rtl_dump_file, PROP_FINAL);
         mark_constant_function ();
       });


More information about the Gcc-patches mailing list