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]

[patch] Fix wrong code generated by FRE


Hi,

this is a regression present on mainline/4.5 branch.  The compiler generates 
wrong code at -O and above (for platforms that still use SJLJ exceptions).

The problem is FRE computing that:

  D.2449_11 = P8b_3->d;

loads 0 after:

  P8b_3->r{off: D.2453_9 * 4} = {};

although the 'd' and 'r' components don't overlap.


  /* 2) Assignment from an empty CONSTRUCTOR.  */
  else if (is_gimple_reg_type (vr->type)
	   && gimple_assign_single_p (def_stmt)
	   && gimple_assign_rhs_code (def_stmt) == CONSTRUCTOR
	   && CONSTRUCTOR_NELTS (gimple_assign_rhs1 (def_stmt)) == 0)
    {
      tree base2;
      HOST_WIDE_INT offset2, size2, maxsize2;
      base2 = get_ref_base_and_extent (gimple_assign_lhs (def_stmt),
				       &offset2, &size2, &maxsize2);
      if (operand_equal_p (base, base2, 0)
	  && offset2 <= offset
	  && offset2 + size2 >= offset + maxsize)
	{
	  tree val = fold_convert (vr->type, integer_zero_node);
	  unsigned int value_id = get_or_alloc_constant_value_id (val);
	  return vn_reference_insert_pieces (vuse, vr->set, vr->type,
					     VEC_copy (vn_reference_op_s,
						       heap, vr->operands),
					     val, value_id);
	}
    }

(gdb) p debug_gimple_stmt(def_stmt)
# .MEM_21 = VDEF <.MEM_24>
P8b_3->r{off: D.2453_9 * 4} = {};

(gdb) p debug_generic_expr(base2)
*P8b_3
$46 = void
(gdb) p offset2
$47 = 0
(gdb) p size2
$48 = 192
(gdb) p maxsize2
$49 = -1


Tested on x86_64-suse-linux, OK for the mainline and 4.5 branch when reopened?


2010-12-15  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-ssa-sccvn.c (vn_reference_lookup_3): Always punt if the call to
	get_ref_base_and_extent returns -1 as the max size.


2010-12-15  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt13.adb: New test.
	* gnat.dg/opt13_pkg.ad[sb]: New helper.


-- 
Eric Botcazou
Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c	(revision 167721)
+++ tree-ssa-sccvn.c	(working copy)
@@ -1339,6 +1339,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
       size2 = TREE_INT_CST_LOW (gimple_call_arg (def_stmt, 2)) * 8;
       if ((unsigned HOST_WIDE_INT)size2 / 8
 	  == TREE_INT_CST_LOW (gimple_call_arg (def_stmt, 2))
+	  && maxsize2 >= 0
 	  && operand_equal_p (base, base2, 0)
 	  && offset2 <= offset
 	  && offset2 + size2 >= offset + maxsize)
@@ -1362,7 +1363,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree
       HOST_WIDE_INT offset2, size2, maxsize2;
       base2 = get_ref_base_and_extent (gimple_assign_lhs (def_stmt),
 				       &offset2, &size2, &maxsize2);
-      if (operand_equal_p (base, base2, 0)
+      if (maxsize2 >= 0
+	  && operand_equal_p (base, base2, 0)
 	  && offset2 <= offset
 	  && offset2 + size2 >= offset + maxsize)
 	{
@@ -1383,7 +1385,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree
 	       || handled_component_p (gimple_assign_rhs1 (def_stmt))))
     {
       tree base2;
-      HOST_WIDE_INT offset2, size2;
+      HOST_WIDE_INT offset2, size2, maxsize2;
       int i, j;
       VEC (vn_reference_op_s, heap) *rhs = NULL;
       vn_reference_op_t vro;
@@ -1396,8 +1398,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree
       base2 = ao_ref_base (&lhs_ref);
       offset2 = lhs_ref.offset;
       size2 = lhs_ref.size;
-      if ((base != base2
-	   && !operand_equal_p (base, base2, 0))
+      maxsize2 = lhs_ref.max_size;
+      if (maxsize2 < 0
+	  || (base != base2 && !operand_equal_p (base, base2, 0))
 	  || offset2 > offset
 	  || offset2 + size2 < offset + maxsize)
 	return (void *)-1;
-- { dg-do run }
-- { dg-options "-O" }

with Opt13_Pkg; use Opt13_Pkg;

procedure Opt13 is
  T : My_Type;
begin
  Allocate (T);
  if N /= 1 then
    raise Program_Error;
  end if;
end;
package body Opt13_Pkg is

  subtype Index_Type is Natural range 0 .. 16;

  type Arr is array (Index_Type range <>) of Integer;

  type Rec is record
    F1, F2, F3 : Float;
    N : Natural;
    B1, B2 : Boolean;
    F4 : Float;
  end record;

  type Data (D : Index_Type) is record
    A : Arr (1 .. D);
    R : Rec;
  end record;

  Zero : constant Rec := (0.0, 0.0, 0.0, 0, False, False, 0.0);

  procedure Allocate (T : out My_Type) is
  begin
    T := new Data (Index_Type'last);
    T.R := Zero;

    for I in 1 .. T.A'last loop
      N := 1;
    end loop;
  end;

end Opt13_Pkg;
package Opt13_Pkg is

    N : Natural := 0;

    type My_Type is private;

    procedure Allocate (T : out My_Type);

private

    type Data;

    type My_Type is access Data;

end Opt13_Pkg;

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