This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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] Fixes tree-loop-distribute-patterns issues


On 18-06-2013 17:56, Roland McGrath wrote:
> What was discussed before was using a configure check.  In general it's
> better to use empirical checks rather than version checks, even if in
> practice a version check is going to suffice.  In this case, it does not
> seem difficult to write a configure check.
>
> Other macros of this sort we have are defined in lowercase
> (internal_function, etc.).  Some of those have names indicative of their
> important semantics rather than echoing the syntax of the implementation.
> I think we should use such a name for this case too.  I haven't thought of
> a particularly good name, but I don't think it should include "tree",
> "distribute", or "patterns".
>
> Attributes can appear in function definitions, right before the return
> type.  There's no need for a separate forward declaration.
>
> The most obvious place we need these annotations is on the simple_*
> functions in string/test-*.c, so I would start by adding it to all those.
> That seems like the right initial set that goes in the change that
> introduces the macro and serves as implicit documentation of its use.
> Then we can take on each actual implementation that might be affected.
>
>
> Thanks,
> Roland
>
Thanks for the reviews, I change it to use a configure check instead and
changed the compiler attribute name a simpler one. I also added the attribute
on the string/test-*.c as you suggested. I put all the changes on one patch
since the string/memset.c and string/memmove.c modification are required so
loader can work correctly.

Tested on PPC64/PPC32 with -mcpu=powerpc and -mcpu=powerpc64.

---

2013-06-19  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>

	* config.h.in (HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS): New define.
	* configure.in (libc_cv_predef_loop_distribute_patttern): Check if
	compiler plus optimization may generate memset/memmove library calls
	for some loop constructions. 
	* include/libc-symbols.h (libc_disable_loop_to_calls): Define to
	disable loop transformation to library calls.
	* string/memmove.c (MEMMOVE): Disable loop transformation to avoid
	recursive call.
	* string/memset.c (memset): Likewise.
	* string/test-memmove.c (simple_memmove): Disable loop transformation
	to library calls.
	* string/test-memset.c (simple_memset): Likewise.
	* configure: Regenerated.

--

diff --git a/config.h.in b/config.h.in
index 8c2479e..f598e82 100644
--- a/config.h.in
+++ b/config.h.in
@@ -69,6 +69,9 @@
 /* Define if the compiler supports __builtin_memset.  */
 #undef	HAVE_BUILTIN_MEMSET
 
+/* Define if compiler implicitly defines -ftree-loop-distribute-patterns.  */
+#undef  HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+
 /* Define if the regparm attribute shall be used for local functions
    (gcc on ix86 only).  */
 #undef	USE_REGPARMS
diff --git a/configure b/configure
index 09d8336..7a718b4 100755
--- a/configure
+++ b/configure
@@ -598,6 +598,7 @@ have_selinux
 have_libcap
 have_libaudit
 LIBGD
+libc_cv_predef_loop_distribute_pattterns
 libc_cv_cc_submachine
 libc_cv_cc_nofma
 exceptions
@@ -6933,6 +6934,36 @@ $as_echo "$libc_cv_cc_submachine" >&6; }
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC $CFLAGS implicitly replaces loops constructions \
+by function calls" >&5
+$as_echo_n "checking whether $CC $CFLAGS implicitly replaces loops constructions \
+by function calls... " >&6; }
+if ${libc_cv_predef_loop_distribute_pattterns+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+  cat > conftest.c << EOF
+void foo (int *vec, int size) {
+  int i=0;
+  int *p = vec;
+  for (i=0; i<size; ++i, ++p)
+    *p = 0;
+}
+EOF
+libc_cv_predef_loop_distribute_pattterns=no
+  if ${CC-cc} $CFLAGS -c -S conftest.c -o - | fgrep "memset" > /dev/null; then
+    libc_cv_predef_loop_distribute_pattterns=yes
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_predef_loop_distribute_pattterns" >&5
+$as_echo "$libc_cv_predef_loop_distribute_pattterns" >&6; }
+if test $libc_cv_predef_loop_distribute_pattterns = yes; then
+  $as_echo "#define HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS 1" >>confdefs.h
+
+fi
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libgd" >&5
 $as_echo_n "checking for libgd... " >&6; }
 if test "$with_gd" != "no"; then
diff --git a/configure.in b/configure.in
index 8b11081..d2adcf5 100644
--- a/configure.in
+++ b/configure.in
@@ -1964,6 +1964,29 @@ if test -n "$submachine"; then
 fi
 AC_SUBST(libc_cv_cc_submachine)
 
+dnl Check whether the compiler may replace some loop constructions
+dnl by memset/memmove calls.
+AC_CACHE_CHECK([whether $CC $CFLAGS implicitly replaces loops constructions \
+by function calls],
+               libc_cv_predef_loop_distribute_pattterns, [
+  cat > conftest.c << EOF
+void foo (int *vec, int size) {
+  int i=0;
+  int *p = vec;
+  for (i=0; i<size; ++i, ++p)
+    *p = 0;
+}
+EOF
+libc_cv_predef_loop_distribute_pattterns=no
+  if ${CC-cc} $CFLAGS -c -S conftest.c -o - | fgrep "memset" > /dev/null; then
+    libc_cv_predef_loop_distribute_pattterns=yes
+  fi
+  rm -f conftest*])
+if test $libc_cv_predef_loop_distribute_pattterns = yes; then
+  AC_DEFINE(HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS)
+fi
+AC_SUBST(libc_cv_predef_loop_distribute_pattterns)
+
 dnl Check whether we have the gd library available.
 AC_MSG_CHECKING(for libgd)
 if test "$with_gd" != "no"; then
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index f043ce0..0affa79 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -782,4 +782,11 @@ for linking")
 #define libc_ifunc_hidden_def(name) \
   libc_ifunc_hidden_def1 (__GI_##name, name)
 
+#ifdef HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+# define libc_disable_loop_to_calls \
+    __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
+#else
+# define libc_disable_loop_to_calls
+#endif
+
 #endif /* libc-symbols.h */
diff --git a/string/memmove.c b/string/memmove.c
index 9dcd2f1..e377c2b 100644
--- a/string/memmove.c
+++ b/string/memmove.c
@@ -40,7 +40,7 @@
 #define MEMMOVE memmove
 #endif
 
-rettype
+libc_disable_loop_to_calls rettype
 MEMMOVE (a1, a2, len)
      a1const void *a1;
      a2const void *a2;
diff --git a/string/memset.c b/string/memset.c
index 868be53..89d49d3 100644
--- a/string/memset.c
+++ b/string/memset.c
@@ -20,7 +20,7 @@
 
 #undef memset
 
-void *
+libc_disable_loop_to_calls void *
 memset (dstpp, c, len)
      void *dstpp;
      int c;
diff --git a/string/test-memmove.c b/string/test-memmove.c
index 4ec55b2..78f415b 100644
--- a/string/test-memmove.c
+++ b/string/test-memmove.c
@@ -46,7 +46,7 @@ IMPL (simple_memmove, 0)
 IMPL (memmove, 1)
 #endif
 
-char *
+libc_disable_loop_to_calls char *
 simple_memmove (char *dst, const char *src, size_t n)
 {
   char *ret = dst;
diff --git a/string/test-memset.c b/string/test-memset.c
index 9981fce..4d0f6d6 100644
--- a/string/test-memset.c
+++ b/string/test-memset.c
@@ -63,7 +63,7 @@ builtin_memset (char *s, int c, size_t n)
 }
 #endif
 
-char *
+libc_disable_loop_to_calls char *
 simple_memset (char *s, int c, size_t n)
 {
   char *r = s, *end = s + n;


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