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 invalid bcopy -> memcpy replacement


Richard Henderson wrote:
> On Sat, May 22, 2004 at 02:30:19AM +0200, Ulrich Weigand wrote:
> > But won't that return NULL if exp is (based on) a string constant?
> > I gather this is one of the cases this routine is supposed to
> > optimize ...
> 
> That can be changed.

OK, so I've changed get_base_address to accept STRING_CST and also
CONSTRUCTOR expressions.  I've then changed readonly_data_expr to
call get_base_address.

However, get_base_address still potentially returns expressions
that decl_readonly_section cannot handle properly (e.g. PARM_DECLs),
so I've added another check that the address is either a constant
or a static variable declaration before calling the varasm routine.


Bootstrapped/regtested on s390-ibm-linux and s390x-ibm-linux,
fixes the builtins/string-asm-2.c test failures.
OK?

ChangeLog:

	PR tree-optimization/14197
	* builtins.c: Include "tree-gimple.h"
	(readonly_data_expr): Use get_base_address.  Make sure to call 
	decl_readonly_section only on trees it can handle.
	* tree-gimple.c (get_base_address): Accept STRING_CST and
	CONSTRUCTOR expressions.
	* Makefile.in: Update dependencies.

Index: gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1279
diff -c -p -r1.1279 Makefile.in
*** gcc/Makefile.in	20 May 2004 11:45:19 -0000	1.1279
--- gcc/Makefile.in	24 May 2004 10:36:00 -0000
*************** dojump.o : dojump.c $(CONFIG_H) $(SYSTEM
*** 1761,1768 ****
     flags.h function.h $(EXPR_H) $(OPTABS_H) $(INSN_ATTR_H) insn-config.h \
     langhooks.h $(GGC_H) gt-dojump.h
  builtins.o : builtins.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H)\
!    flags.h $(TARGET_H) function.h $(REGS_H) $(EXPR_H) $(OPTABS_H) insn-config.h \
!    $(RECOG_H) output.h typeclass.h hard-reg-set.h toplev.h hard-reg-set.h \
     except.h $(TM_P_H) $(PREDICT_H) libfuncs.h real.h langhooks.h
  calls.o : calls.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) flags.h \
     $(EXPR_H) $(OPTABS_H) langhooks.h $(TARGET_H) \
--- 1761,1768 ----
     flags.h function.h $(EXPR_H) $(OPTABS_H) $(INSN_ATTR_H) insn-config.h \
     langhooks.h $(GGC_H) gt-dojump.h
  builtins.o : builtins.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H)\
!    $(TREE_GIMPLE_H) flags.h $(TARGET_H) function.h $(REGS_H) $(EXPR_H) $(OPTABS_H) \
!    insn-config.h $(RECOG_H) output.h typeclass.h hard-reg-set.h toplev.h hard-reg-set.h \
     except.h $(TM_P_H) $(PREDICT_H) libfuncs.h real.h langhooks.h
  calls.o : calls.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) flags.h \
     $(EXPR_H) $(OPTABS_H) langhooks.h $(TARGET_H) \
Index: gcc/builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.323
diff -c -p -r1.323 builtins.c
*** gcc/builtins.c	15 May 2004 18:17:20 -0000	1.323
--- gcc/builtins.c	24 May 2004 10:36:00 -0000
*************** Software Foundation, 59 Temple Place - S
*** 27,32 ****
--- 27,33 ----
  #include "real.h"
  #include "rtl.h"
  #include "tree.h"
+ #include "tree-gimple.h"
  #include "flags.h"
  #include "regs.h"
  #include "hard-reg-set.h"
*************** readonly_data_expr (tree exp)
*** 7923,7930 ****
  {
    STRIP_NOPS (exp);
  
!   if (TREE_CODE (exp) == ADDR_EXPR)
!     return decl_readonly_section (TREE_OPERAND (exp, 0), 0);
    else
      return false;
  }
--- 7924,7943 ----
  {
    STRIP_NOPS (exp);
  
!   if (TREE_CODE (exp) != ADDR_EXPR)
!     return false;
! 
!   exp = get_base_address (TREE_OPERAND (exp, 0));
!   if (!exp)
!     return false;
! 
!   /* Make sure we call decl_readonly_section only for trees it
!      can handle (since it returns true for everything it doesn't
!      understand).  */
!   if (TREE_CODE (exp) == STRING_CST 
!       || TREE_CODE (exp) == CONSTRUCTOR
!       || (TREE_CODE (exp) == VAR_DECL && TREE_STATIC (exp)))
!     return decl_readonly_section (exp, 0);
    else
      return false;
  }
Index: gcc/tree-gimple.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-gimple.c,v
retrieving revision 2.1
diff -c -p -r2.1 tree-gimple.c
*** gcc/tree-gimple.c	14 May 2004 02:29:22 -0000	2.1
--- gcc/tree-gimple.c	24 May 2004 10:36:01 -0000
*************** get_base_address (tree t)
*** 574,579 ****
--- 574,581 ----
    do
      {
        if (SSA_VAR_P (t)
+ 	  || TREE_CODE (t) == STRING_CST
+ 	  || TREE_CODE (t) == CONSTRUCTOR
  	  || TREE_CODE (t) == INDIRECT_REF)
  	return t;
  


-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de


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