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: GCC 4.8 and -ftree-loop-distribute-patterns.


On 04/08/2013 10:26 AM, Carlos O'Donell wrote:
> On 04/08/2013 07:41 AM, Adhemerval Zanella wrote:
>> On 04/06/2013 11:01 AM, Carlos O'Donell wrote:
>>> The patch, like my Fedora patch, is incomplete. We need to detect
>>> the compiler feature, set a feature macro, and then conditionally
>>> carry out whatever is required to allow glibc to compile with the
>>> feature enabled.
>>>
>>> In your case it would be to include string.h.
>>>
>>> I'm up to my ears in other work, so I would be more than happy to
>>> give up the glory that goes along with fixing this :-)
>> I'm not a big fan of adding logic to handle a compiler feature to
>> just add or a not an include, however it is up to discussion. I'll
>> work on this fix.
> It's more than that, it's about long-term maintenance of that hack.
> The goal is to get everyone into the habit of checking for features
> instead of GCC versions. That way the maintenance burden is *much*
> easier 5, 10 years down the road. The macros all use features and
> features have strict meanings. There is no such thing as GCC 4.8,
> there are 4.8's for all the distros with lots of patches. We should
> always check for a feature, enable the macro, and adjust using the
> macro. That way reviewing code and headers and conditionals becomes
> much easier and almost self-documenting.
>
> Does that make sense?

Yes, I was considering more the fact it would be more simple to just add
the includes, but your points make sense.

I believe the patch below check pretty much what you said. I tested on
PowerPC64 and I don't see the check-localplt failures for libc.so anymore.
Any tips, comments, advices?

--

2013-04-08  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>

	* config.h.in: Add HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS define.
	* configure.in (libc_cv_predef_loop_distribute_patttern): Check if
	compiler with defined optimization may generate memset/memmove
	library calls for some loop constructions.
	* configure: Regenerate.
	* stdlib/divrem.c: Include <string.h> if
	HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS is defined.
	* stdlib/mul.c: Likewise.
	* stdlib/mul_n.c: Likewise.
	* wcsmbs/wcpncpy.c: Likewise.
	* wcsmbs/wcsncpy.c: Likewise.

---

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 0b50df9..8b83a9c 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
@@ -6942,6 +6943,35 @@ $as_echo "$libc_cv_cc_submachine" >&6; }
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC $CFLAGS implicitly enables -ftree-loop-distribute-patterns" >&5
+$as_echo_n "checking whether $CC $CFLAGS implicitly enables -ftree-loop-distribute-patterns... " >&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
+  if ${CC-cc} $CFLAGS -c -S conftest.c -o - | fgrep "memset" > /dev/null; then
+    libc_cv_predef_loop_distribute_pattterns=yes
+  else
+    libc_cv_predef_loop_distribute_pattterns=no
+  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 d93ca5c..829db77 100644
--- a/configure.in
+++ b/configure.in
@@ -1973,6 +1973,28 @@ if test -n "$submachine"; then
 fi
 AC_SUBST(libc_cv_cc_submachine)
 
+dnl Check whether the compiler may replace some loop constructions by memset/memmove calls.
+AC_CACHE_CHECK([whether $CC $CFLAGS implicitly enables -ftree-loop-distribute-patterns],
+               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
+  if ${CC-cc} $CFLAGS -c -S conftest.c -o - | fgrep "memset" > /dev/null; then
+    libc_cv_predef_loop_distribute_pattterns=yes
+  else
+    libc_cv_predef_loop_distribute_pattterns=no
+  fi
+  rm -f conftest*])
+AC_SUBST(libc_cv_predef_loop_distribute_pattterns)
+if test $libc_cv_predef_loop_distribute_pattterns=yes; then
+  AC_DEFINE(HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS)
+fi
+
 dnl Check whether we have the gd library available.
 AC_MSG_CHECKING(for libgd)
 if test "$with_gd" != "no"; then
diff --git a/stdlib/divrem.c b/stdlib/divrem.c
index 99c782e..cdd4423 100644
--- a/stdlib/divrem.c
+++ b/stdlib/divrem.c
@@ -20,6 +20,9 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include <gmp.h>
+#ifdef HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+#include <string.h>
+#endif
 #include "gmp-impl.h"
 #include "longlong.h"
 
diff --git a/stdlib/mul.c b/stdlib/mul.c
index 1258717..1a95358 100644
--- a/stdlib/mul.c
+++ b/stdlib/mul.c
@@ -19,6 +19,9 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include <gmp.h>
+#ifdef HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+#include <string.h>
+#endif
 #include "gmp-impl.h"
 
 /* Multiply the natural numbers u (pointed to by UP, with USIZE limbs)
diff --git a/stdlib/mul_n.c b/stdlib/mul_n.c
index f0a9a30..abb7bd9 100644
--- a/stdlib/mul_n.c
+++ b/stdlib/mul_n.c
@@ -19,6 +19,9 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include <gmp.h>
+#ifdef HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+#include <string.h>
+#endif
 #include "gmp-impl.h"
 
 /* Multiply the natural numbers u (pointed to by UP) and v (pointed to by VP),
diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c
index 634d335..542fe3f 100644
--- a/wcsmbs/wcpncpy.c
+++ b/wcsmbs/wcpncpy.c
@@ -17,6 +17,9 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <wchar.h>
+#ifdef HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+#include <string.h>
+#endif
 
 
 /* Copy no more than N wide-characters of SRC to DEST, returning the
diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c
index a88f8fc..e228112 100644
--- a/wcsmbs/wcsncpy.c
+++ b/wcsmbs/wcsncpy.c
@@ -17,6 +17,9 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <wchar.h>
+#ifdef HAVE_CC_PREDEF_DISTRIBUTE_PATTERNS
+#include <string.h>
+#endif
 
 
 /* Copy no more than N wide-characters of SRC to DEST.	*/



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