RFA: Fix PR42027 (performance regression)

Michael Matz matz@suse.de
Wed Dec 9 16:07:00 GMT 2009


Hi,

the testcase contains a loop with an exit test like so:

  for (k=0; (k<511)&&(k<=j); ++k)

That's converted by the tree optimizers into (k<511)&(k<=j).  For targets 
where jumps are cheap this should have expanded to two jumps, not an 
explicit and.  That it was nevertheless was due to me splitting out 
do_jump_1 from do_jump, and not taking care of two fallthroughs from 
TRUTH_AND_EXPR to TRUTH_ANDIF_EXPR, resp. TRUTH_OR_EXPR to 
TRUTH_ORIF_EXPR.  So independend of jump costs it always chose the 
explicit AND form.  Luckily this oversight didn't result in wrong code to 
be generated (as now it fell through from TRUTH_AND_EXPR to TRUTH_OR_EXPR, 
oops :) just to fall further through to the normal expansion).

In any case, this fixes the performance regression.  Regstrapped on 
x86_64-linux (all langs+Ada), okay for trunk?


Ciao,
Michael.
-- 
	PR tree-optimization/42027
	* dojump.c (do_jump <TRUTH_AND_EXPR, TRUTH_OR_EXPR>): Go to
	TRUTH_ANDIF_EXPR resp. TRUTH_ORIF_EXPR expander, instead of
	falling through.

Index: dojump.c
===================================================================
--- dojump.c	(revision 155107)
+++ dojump.c	(working copy)
@@ -458,6 +458,7 @@ do_jump (tree exp, rtx if_false_label, r
     case LTGT_EXPR:
     case TRUTH_ANDIF_EXPR:
     case TRUTH_ORIF_EXPR:
+    other_code:
       do_jump_1 (code, TREE_OPERAND (exp, 0), TREE_OPERAND (exp, 1),
 		 if_false_label, if_true_label);
       break;
@@ -547,6 +548,8 @@ do_jump (tree exp, rtx if_false_label, r
 		       false) >= 4
 	  || TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
 	goto normal;
+      code = TRUTH_ANDIF_EXPR;
+      goto other_code;
 
     case BIT_IOR_EXPR:
     case TRUTH_OR_EXPR:
@@ -556,6 +559,8 @@ do_jump (tree exp, rtx if_false_label, r
       if (BRANCH_COST (optimize_insn_for_speed_p (), false)>= 4
 	  || TREE_SIDE_EFFECTS (TREE_OPERAND (exp, 1)))
 	goto normal;
+      code = TRUTH_ORIF_EXPR;
+      goto other_code;
 
       /* Fall through and generate the normal code.  */
     default:



More information about the Gcc-patches mailing list