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]

define_expand returning insn broke reload_cse_move2add


Ever since define_expands were modified so as to always return insns,
instead of a simple patterns, reload_cse_move2add got pretty much
disabled on any targets that happen to have add patterns defined as
define_expands, instead of define_insns.  This patch fixes this
problem.  Bootstrapped on athlon-pc-linux-gnu.  Ok to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva at redhat dot com>

	* optabs.c: Comment that gen_add2_insn and others may actually
	return emitted insns, if the gen functions turn out to return
	emitted insns.
	* reload1.c (reload_cse_move2add): Cope with emitted insns from
	gen_add2_insn.

Index: gcc/optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.168
diff -u -p -r1.168 optabs.c
--- gcc/optabs.c 21 Mar 2003 16:58:35 -0000 1.168
+++ gcc/optabs.c 9 Apr 2003 12:46:17 -0000
@@ -4512,8 +4512,9 @@ emit_conditional_add (target, code, op0,
   return target;
 }
 
-/* These functions generate an insn body and return it
-   rather than emitting the insn.
+/* These functions attempt to generate an insn body, rather than
+   emitting the insn, but if the gen function already emits them, we
+   make no attempt to turn them back into naked patterns.
 
    They do not protect from queued increments,
    because they may be used 1) in protect_from_queue itself
Index: gcc/reload1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reload1.c,v
retrieving revision 1.386
diff -u -p -r1.386 reload1.c
--- gcc/reload1.c 30 Mar 2003 13:30:56 -0000 1.386
+++ gcc/reload1.c 9 Apr 2003 12:46:23 -0000
@@ -9162,8 +9162,16 @@ reload_cse_move2add (first)
 		    validate_change (insn, &SET_SRC (pat), reg, 0);
 		  else if (rtx_cost (new_src, PLUS) < rtx_cost (src, SET)
 			   && have_add2_insn (reg, new_src))
-		    validate_change (insn, &PATTERN (insn),
-				     gen_add2_insn (reg, new_src), 0);
+		    {
+		      rtx newpat = gen_add2_insn (reg, new_src);
+		      if (INSN_P (newpat) && NEXT_INSN (newpat) == NULL_RTX)
+			newpat = PATTERN (newpat);
+		      /* If it was the first insn of a sequence or
+			 some other emitted insn, validate_change will
+			 reject it.  */
+		      validate_change (insn, &PATTERN (insn),
+				       newpat, 0);
+		    }
 		  else
 		    {
 		      enum machine_mode narrow_mode;
@@ -9243,9 +9251,15 @@ reload_cse_move2add (first)
 		      else if ((rtx_cost (new_src, PLUS)
 				< COSTS_N_INSNS (1) + rtx_cost (src3, SET))
 			       && have_add2_insn (reg, new_src))
-			success
-			  = validate_change (next, &PATTERN (next),
-					     gen_add2_insn (reg, new_src), 0);
+			{
+			  rtx newpat = gen_add2_insn (reg, new_src);
+			  if (INSN_P (newpat)
+			      && NEXT_INSN (newpat) == NULL_RTX)
+			    newpat = PATTERN (newpat);
+			  success
+			    = validate_change (next, &PATTERN (next),
+					       newpat, 0);
+			}
 		      if (success)
 			delete_insn (insn);
 		      insn = next;
-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva at {redhat dot com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva at {lsd dot ic dot unicamp dot br, gnu.org}
Free Software Evangelist                Professional serial bug killer

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