disabling branch probability guessing (patch)

Aldy Hernandez aldyh@redhat.com
Mon Jan 15 14:09:00 GMT 2001


hi guys.

Here is a patch that adds an option to disable guessing of branch
probabilities (-fno-guess-branch-probability).

One of our clients is trying to use __builtin_expect and is getting
unexpected results because estimate_probability() in predict.c is 
guessing the branch probability in an undetermined way.  This patch
solves the problem by providing an option to disable the probability
guessing altogether.

Ok to install?
Aldy

2001-01-12  Aldy Hernandez  <aldyh@redhat.com>

	* gcc/toplev.c (flag_guess_branch_prob): New.
	(f_options): Add guess-branch-probability option.
	(rest_of_decl_compilation): Only estimate branch probability if
	flag set.
	(main): set flag_guess_branch_prob.

	* gcc/flags.h (flag_guess_branch_prob): New.

Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.416
diff -c -r1.416 toplev.c
*** toplev.c	2001/01/10 23:06:16	1.416
--- toplev.c	2001/01/15 21:19:25
***************
*** 868,873 ****
--- 868,876 ----
  /* This will perform a peephole pass before sched2.  */
  int flag_peephole2 = 0;
  
+ /* This will try to guess branch probabilities.  */
+ int flag_guess_branch_prob = 0;
+ 
  /* -fbounded-pointers causes gcc to compile pointers as composite
     objects occupying three words: the pointer value, the base address
     of the referent object, and the address immediately beyond the end
***************
*** 1136,1141 ****
--- 1139,1146 ----
     "Process #ident directives"},
    { "peephole2", &flag_peephole2, 1,
      "Enables an rtl peephole pass run before sched2" },
+   { "guess-branch-probability", &flag_guess_branch_prob, 1,
+     "Enables guessing of branch probabilities" },
    {"math-errno", &flag_errno_math, 1,
     "Set errno after built-in math functions"},
    {"bounded-pointers", &flag_bounded_pointers, 1,
***************
*** 3253,3259 ****
        flow_loops_find (&loops, LOOP_TREE);
  
        /* Estimate using heuristics if no profiling info is available.  */
!       estimate_probability (&loops);
  
        if (rtl_dump_file)
  	flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
--- 3258,3265 ----
        flow_loops_find (&loops, LOOP_TREE);
  
        /* Estimate using heuristics if no profiling info is available.  */
!       if (flag_guess_branch_prob)
! 	estimate_probability (&loops);
  
        if (rtl_dump_file)
  	flow_loops_dump (&loops, rtl_dump_file, NULL, 0);
***************
*** 4651,4656 ****
--- 4657,4663 ----
        flag_caller_saves = 1;
        flag_force_mem = 1;
        flag_peephole2 = 1;
+       flag_guess_branch_prob = 1;
  #ifdef INSN_SCHEDULING
        flag_schedule_insns = 1;
        flag_schedule_insns_after_reload = 1;
Index: flags.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flags.h,v
retrieving revision 1.56
diff -c -r1.56 flags.h
*** flags.h	2001/01/05 22:55:23	1.56
--- flags.h	2001/01/15 21:19:27
***************
*** 531,536 ****
--- 531,539 ----
  /* Perform a peephole pass before sched2. */
  extern int flag_peephole2;
  
+ /* Try to guess branch probablities.  */
+ extern int flag_guess_branch_prob;
+ 
  /* -fbounded-pointers causes gcc to compile pointers as composite
     objects occupying three words: the pointer value, the base address
     of the referent object, and the address immediately beyond the end


More information about the Gcc-patches mailing list