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]

Re: [PATCH] Fix PR23109


On Thu, 28 Jul 2005, Richard Henderson wrote:

> On Thu, Jul 28, 2005 at 05:04:33PM +0200, Richard Guenther wrote:
> > 	* tree-ssa-loop-im.c (determine_invariantness_stmt): Honour
> > 	trapping math during hoisting 1/d.
> 
> This is ok.
> 
> > 	* tree-ssa-math-opts.c (gate_cse_reciprocals): Likewise.
> 
> I don't like this one.  It prevents
> 
> 	b = foo;
> 	z = a/b + c/b;
> 
> from being converted, even though everything is in the same basic block.
> I would much prefer that the optimization pass check dominators instead.

In this case we transform it to

  b = foo;
  tmp = a + c;
  z = tmp/b;

anyway with unsafe-math-optimizations on.

But you mean a patch like the following?  (I still miss a testcase
with correct post-dominator that is not handled by code elsewhere)

Richard.


Index: tree-ssa-math-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-math-opts.c,v
retrieving revision 2.2
diff -c -3 -p -r2.2 tree-ssa-math-opts.c
*** tree-ssa-math-opts.c	25 Jun 2005 02:01:43 -0000	2.2
--- tree-ssa-math-opts.c	29 Jul 2005 10:26:59 -0000
*************** execute_cse_reciprocals_1 (block_stmt_it
*** 69,74 ****
--- 69,83 ----
    imm_use_iterator use_iter;
    tree t, new_stmt, type;
    int count = 0;
+   basic_block post_dom_bb;
+   bool ok = !flag_trapping_math;
+ 
+   /* The insertion point post-dominator.  */
+   if (flag_trapping_math)
+     {
+       gcc_assert (dom_computed[CDI_POST_DOMINATORS] == DOM_OK);
+       post_dom_bb = get_immediate_dominator (CDI_POST_DOMINATORS, bsi->bb);
+     }
  
    /* Find uses.  */
    FOR_EACH_IMM_USE_FAST (use_p, use_iter, def)
*************** execute_cse_reciprocals_1 (block_stmt_it
*** 77,89 ****
        if (TREE_CODE (use_stmt) == MODIFY_EXPR
  	  && TREE_CODE (TREE_OPERAND (use_stmt, 1)) == RDIV_EXPR
  	  && TREE_OPERAND (TREE_OPERAND (use_stmt, 1), 1) == def)
! 	{
! 	  if (++count == 2)
! 	    break;
! 	}
      }
  
!   if (count < 2)
      return;
  
    /* Make a variable with the replacement and substitute it.  */
--- 86,102 ----
        if (TREE_CODE (use_stmt) == MODIFY_EXPR
  	  && TREE_CODE (TREE_OPERAND (use_stmt, 1)) == RDIV_EXPR
  	  && TREE_OPERAND (TREE_OPERAND (use_stmt, 1), 1) == def)
!         {
!           ++count;
!           /* Check if the use post-dominates the insertion point.  */
!           if (bb_for_stmt (use_stmt) == post_dom_bb)
!             ok = true;
!         }
!       if (count >= 2 && ok)
!         break;
      }
  
!   if (count < 2 || !ok)
      return;
  
    /* Make a variable with the replacement and substitute it.  */
*************** static void
*** 116,121 ****
--- 129,138 ----
  execute_cse_reciprocals (void)
  {
    basic_block bb;
+ 
+   if (flag_trapping_math)
+     calculate_dominance_info (CDI_POST_DOMINATORS);
+ 
    FOR_EACH_BB (bb)
      {
        block_stmt_iterator bsi;
*************** execute_cse_reciprocals (void)
*** 143,148 ****
--- 160,168 ----
  	    execute_cse_reciprocals_1 (&bsi, def, false);
  	}
      }
+ 
+   if (flag_trapping_math)
+     free_dominance_info (CDI_POST_DOMINATORS);
  }
  
  struct tree_opt_pass pass_cse_reciprocals =


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