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 loop optimization bug


Hi,

this is a regression present at -O2 on the mainline and 4.3 branch.  For the 
attached testcase, ivopts takes the address of something like
  VIEW_CONVERT_EXPR <PLUS_EXPR <..,..>>
which results in the creation of a temporary and thus wrong code.

Fixed by teaching may_be_nonaddressable_p about this problematic case.  Tested 
on i586-suse-linux, OK for mainline and 4.3 branch?


2008-10-06  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-ssa-loop-ivopts.c (may_be_nonaddressable_p): Return true for
	binary and comparison expressions.


2008-10-06  Eric Botcazou  <ebotcazou@adacore.com>

        * gnat.dg/loop_optimization4.adb: New test.
	* gnat.dg/loop_optimization4_pkg.ad[sb]: New helper.


-- 
Eric Botcazou
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c	(revision 140904)
+++ tree-ssa-loop-ivopts.c	(working copy)
@@ -1541,7 +1541,9 @@ may_be_unaligned_p (tree ref, tree step)
 static bool
 may_be_nonaddressable_p (tree expr)
 {
-  switch (TREE_CODE (expr))
+  enum tree_code code = TREE_CODE (expr);
+
+  switch (code)
     {
     case TARGET_MEM_REF:
       /* TARGET_MEM_REFs are translated directly to valid MEMs on the
@@ -1571,6 +1573,9 @@ may_be_nonaddressable_p (tree expr)
       return true;
 
     default:
+      if (TREE_CODE_CLASS (code) == tcc_binary
+	  || TREE_CODE_CLASS (code) == tcc_comparison)
+	return true;
       break;
     }
 
-- { dg-do run }
-- { dg-options "-O2" }

with Loop_Optimization4_Pkg; use Loop_Optimization4_Pkg;

procedure Loop_Optimization4 is
begin
  Add ("Nothing");
end;
package body Loop_Optimization4_Pkg is

   procedure Add (Phrase : String) is
   begin
      if Debug_Buffer_Len = Max_Debug_Buffer_Len then
         return;
      end if;
      for I in Phrase'Range loop
         Debug_Buffer_Len := Debug_Buffer_Len + 1;
         Debug_Buffer (Debug_Buffer_Len) := Phrase (I);
         if Debug_Buffer_Len = Max_Debug_Buffer_Len then
            exit;
         end if;
      end loop;
   end Add;

end Loop_Optimization4_Pkg;
package Loop_Optimization4_Pkg is

   Max_Debug_Buffer_Len : Natural := 8 * 1024;
   Debug_Buffer : String (1 .. Max_Debug_Buffer_Len);
   Debug_Buffer_Len : Natural range 0 .. Max_Debug_Buffer_Len;

   procedure Add (Phrase : String);

end Loop_Optimization4_Pkg;

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