fix execute/pure-1.c
Richard Henderson
rth@redhat.com
Sun Jun 2 13:55:00 GMT 2002
On Sun, Jun 02, 2002 at 03:43:23PM -0400, Kaveh R. Ghazi wrote:
> Thanks very much, I do see improvement at -O1/-O2. However I'm still
> getting failures at -O3 (or -O -finline-functions) on solaris2.7 as
> are you on alpha. :-)
Indeed, I hadn't noticed when I ran the test by hand.
The answer is quite simple -- all of the test functions have been
deferred, and so havn't been examined at the time we compile main.
The following loosens the test in mark_constant_function a bit,
which will help regular applications a tad. It also allows us to
modify the test case such that it can pass at -O3, but will then
fail when testing with -fpic.
I'm tempted to say we should move the definition of __pic__ and
__PIC__ from scattered OS configury and make it a permanent GCC
feature. This would allow us to check for this in test cases.
r~
* alias.c: Include target.h.
(mark_constant_function): Use targetm.binds_local_p instead
of checking TREE_PUBLIC ourselves.
* Makefile.in (alias.o): Add TARGET_H.
* gcc.c-torture/execute/pure-1.c: Don't mark any of the
test functions static.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.885
diff -c -p -d -r1.885 Makefile.in
*** Makefile.in 1 Jun 2002 21:31:34 -0000 1.885
--- Makefile.in 2 Jun 2002 20:43:36 -0000
*************** reorg.o : reorg.c $(CONFIG_H) $(SYSTEM_H
*** 1560,1566 ****
$(RECOG_H) function.h flags.h output.h $(EXPR_H) toplev.h $(PARAMS_H) $(TM_P_H)
alias.o : alias.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) flags.h hard-reg-set.h \
$(BASIC_BLOCK_H) $(REGS_H) toplev.h output.h $(EXPR_H) \
! $(GGC_H) function.h cselib.h $(TREE_H) $(TM_P_H) langhooks.h
regmove.o : regmove.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) insn-config.h \
$(RECOG_H) output.h $(REGS_H) hard-reg-set.h flags.h function.h \
$(EXPR_H) $(BASIC_BLOCK_H) toplev.h $(TM_P_H) except.h reload.h
--- 1560,1566 ----
$(RECOG_H) function.h flags.h output.h $(EXPR_H) toplev.h $(PARAMS_H) $(TM_P_H)
alias.o : alias.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) flags.h hard-reg-set.h \
$(BASIC_BLOCK_H) $(REGS_H) toplev.h output.h $(EXPR_H) \
! $(GGC_H) function.h cselib.h $(TREE_H) $(TM_P_H) langhooks.h $(TARGET_H)
regmove.o : regmove.c $(CONFIG_H) $(SYSTEM_H) $(RTL_H) insn-config.h \
$(RECOG_H) output.h $(REGS_H) hard-reg-set.h flags.h function.h \
$(EXPR_H) $(BASIC_BLOCK_H) toplev.h $(TM_P_H) except.h reload.h
Index: alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/alias.c,v
retrieving revision 1.171
diff -c -p -d -r1.171 alias.c
*** alias.c 26 May 2002 15:01:10 -0000 1.171
--- alias.c 2 Jun 2002 20:43:36 -0000
*************** Software Foundation, 59 Temple Place - S
*** 36,41 ****
--- 36,42 ----
#include "splay-tree.h"
#include "ggc.h"
#include "langhooks.h"
+ #include "target.h"
/* The alias sets assigned to MEMs assist the back-end in determining
which MEMs can alias which other MEMs. In general, two MEMs in
*************** mark_constant_function ()
*** 2572,2583 ****
rtx insn;
int nonlocal_memory_referenced;
! if (TREE_PUBLIC (current_function_decl)
! || TREE_READONLY (current_function_decl)
|| DECL_IS_PURE (current_function_decl)
|| TREE_THIS_VOLATILE (current_function_decl)
|| TYPE_MODE (TREE_TYPE (current_function_decl)) == VOIDmode
! || current_function_has_nonlocal_goto)
return;
/* A loop might not return which counts as a side effect. */
--- 2573,2584 ----
rtx insn;
int nonlocal_memory_referenced;
! if (TREE_READONLY (current_function_decl)
|| DECL_IS_PURE (current_function_decl)
|| TREE_THIS_VOLATILE (current_function_decl)
|| TYPE_MODE (TREE_TYPE (current_function_decl)) == VOIDmode
! || current_function_has_nonlocal_goto
! || !(*targetm.binds_local_p) (current_function_decl))
return;
/* A loop might not return which counts as a side effect. */
Index: testsuite/gcc.c-torture/execute/pure-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.c-torture/execute/pure-1.c,v
retrieving revision 1.1
diff -c -p -d -r1.1 pure-1.c
*** testsuite/gcc.c-torture/execute/pure-1.c 27 May 2002 20:19:53 -0000 1.1
--- testsuite/gcc.c-torture/execute/pure-1.c 2 Jun 2002 20:43:37 -0000
*************** extern int i;
*** 15,29 ****
extern int func0 (int) __attribute__ ((__pure__));
extern int func1 (int) __attribute__ ((__const__));
/* GCC should automatically detect attributes for these functions.
Don't allow -O3 to inline them. */
#define ANI __attribute__ ((__noinline__))
! static int ANI func2 (int a) { return i + a; } /* pure */
! static int ANI func3 (int a) { return a * 3; } /* const */
! static int ANI func4 (int a) { return func0(a) + a; } /* pure */
! static int ANI func5 (int a) { return a + func1(a); } /* const */
! static int ANI func6 (int a) { return func2(a) + a; } /* pure */
! static int ANI func7 (int a) { return a + func3(a); } /* const */
int main ()
{
--- 15,36 ----
extern int func0 (int) __attribute__ ((__pure__));
extern int func1 (int) __attribute__ ((__const__));
+
/* GCC should automatically detect attributes for these functions.
Don't allow -O3 to inline them. */
#define ANI __attribute__ ((__noinline__))
!
! /* ??? If we mark these static, then -O3 will defer them to the end of
! compilation, and we won't have detected anything about them at the
! point main is compiled. Leaving them public works until someone runs
! the testsuite with -fpic, or has an OS for which targetm.binds_local_p
! returns false for some reason. */
! int ANI func2 (int a) { return i + a; } /* pure */
! int ANI func3 (int a) { return a * 3; } /* const */
! int ANI func4 (int a) { return func0(a) + a; } /* pure */
! int ANI func5 (int a) { return a + func1(a); } /* const */
! int ANI func6 (int a) { return func2(a) + a; } /* pure */
! int ANI func7 (int a) { return a + func3(a); } /* const */
int main ()
{
More information about the Gcc-patches
mailing list