[PATCH][tuples] Fix execute/stdarg-3.c

Richard Guenther rguenther@suse.de
Mon Jul 21 12:22:00 GMT 2008


This fixes the remaining execute failure on the branch which turns
out to be a missed-optimization case that makes our varargs code
compliant with GCC aliasing rules.  In particular the tuples
fold_stmt did no longer transform

 foo_1 = (double *)&vatmp;

to

 foo_1 = &vatmp.d;

thereby violating aliasing rules (type-punning is only valid with
the union).  You can trigger this "failure" on the trunk by
passing -fno-tree-ccp.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the 
branch.

Richard.

2008-07-21  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-ccp.c (fold_gimple_assign): Handle pointer conversions
	like fold_stmt_r did.
	* gimple-pretty-print.c (dump_gimple_cond): Place semicolons
	where trunk did.
	* tree-inline.c (copy_bb): Do not insert GIMPLE_NOPs.

Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c	(revision 138023)
--- tree-ssa-ccp.c	(working copy)
*************** fold_gimple_assign (gimple_stmt_iterator
*** 2681,2686 ****
--- 2681,2706 ----
                return true;
              }
          }
+       else if ((gimple_assign_rhs_code (stmt) == NOP_EXPR
+ 		|| gimple_assign_rhs_code (stmt) == CONVERT_EXPR)
+ 	       && POINTER_TYPE_P (gimple_expr_type (stmt))
+ 	       && POINTER_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (stmt))))
+ 	{
+ 	  tree type = gimple_expr_type (stmt);
+ 	  tree t = maybe_fold_offset_to_reference (gimple_assign_rhs1 (stmt),
+ 						   integer_zero_node,
+ 						   TREE_TYPE (type));
+ 	  if (t)
+ 	    {
+ 	      tree ptr_type = build_pointer_type (TREE_TYPE (t));
+ 	      if (useless_type_conversion_p (type, ptr_type))
+ 		{
+ 		  result = build_fold_addr_expr_with_type (t, ptr_type);
+ 		  gimple_assign_set_rhs_from_tree (si, result);
+ 		  return true;
+ 		}
+ 	    }
+ 	}
        break;
  
      case GIMPLE_BINARY_RHS:
Index: gimple-pretty-print.c
===================================================================
*** gimple-pretty-print.c	(revision 138023)
--- gimple-pretty-print.c	(working copy)
*************** dump_gimple_cond (pretty_printer *buffer
*** 564,579 ****
  	      pp_string (buffer, " goto ");
  	      dump_generic_node (buffer, gimple_cond_true_label (gs),
  				 spc, flags, false);
  	    }
  	  if (gimple_cond_false_label (gs))
  	    {
  	      pp_string (buffer, " else goto ");
  	      dump_generic_node (buffer, gimple_cond_false_label (gs),
  				 spc, flags, false);
  	    }
-           if (gimple_cond_true_label (gs)
- 	      || gimple_cond_false_label (gs))
- 	    pp_semicolon (buffer);
  	}
      }
  }
--- 564,578 ----
  	      pp_string (buffer, " goto ");
  	      dump_generic_node (buffer, gimple_cond_true_label (gs),
  				 spc, flags, false);
+ 	      pp_semicolon (buffer);
  	    }
  	  if (gimple_cond_false_label (gs))
  	    {
  	      pp_string (buffer, " else goto ");
  	      dump_generic_node (buffer, gimple_cond_false_label (gs),
  				 spc, flags, false);
+ 	      pp_semicolon (buffer);
  	    }
  	}
      }
  }
Index: tree-inline.c
===================================================================
*** tree-inline.c	(revision 138023)
--- tree-inline.c	(working copy)
*************** copy_bb (copy_body_data *id, basic_block
*** 1269,1274 ****
--- 1269,1276 ----
  
        id->regimplify = false;
        stmt = remap_gimple_stmt (stmt, id);
+       if (gimple_nop_p (stmt))
+ 	continue;
  
        gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun, orig_stmt);
  



More information about the Gcc-patches mailing list