PR middle-end/39443
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 Mar 2009 17:46:23 +0000 (17:46 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 Mar 2009 17:46:23 +0000 (17:46 +0000)
* optabs.c (set_user_assembler_libfunc): New function.
* expr.h (set_user_assembler_libfunc): New prototype.
* c-common.c: Include libfuncs.h.
(set_builtin_user_assembler_name): Call set_user_assembler_libfunc
for memcmp, memset, memcpy, memmove and abort.
* Makefile.in (c-common.o): Depend on libfuncs.h.

* gcc.dg/pr39443.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@144910 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/Makefile.in
gcc/c-common.c
gcc/expr.h
gcc/optabs.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr39443.c [new file with mode: 0644]

index 18264af..7af0db0 100644 (file)
@@ -1,5 +1,13 @@
 2009-03-17  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/39443
+       * optabs.c (set_user_assembler_libfunc): New function.
+       * expr.h (set_user_assembler_libfunc): New prototype.
+       * c-common.c: Include libfuncs.h.
+       (set_builtin_user_assembler_name): Call set_user_assembler_libfunc
+       for memcmp, memset, memcpy, memmove and abort.
+       * Makefile.in (c-common.o): Depend on libfuncs.h.
+
        PR debug/39412
        * dwarf2out.c (gen_inlined_enumeration_type_die,
        gen_inlined_structure_type_die, gen_inlined_union_type_die,
index be5634f..d4d6683 100644 (file)
@@ -1890,7 +1890,7 @@ c-common.o : c-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
        $(TARGET_H) $(C_TREE_H) tree-iterator.h langhooks.h tree-mudflap.h \
        intl.h opts.h $(REAL_H) $(CPPLIB_H) $(TREE_INLINE_H) $(HASHTAB_H) \
        $(BUILTINS_DEF) $(CGRAPH_H) $(BASIC_BLOCK_H) $(TARGET_DEF_H) \
-       $(GIMPLE_H)
+       $(GIMPLE_H) libfuncs.h
 
 c-pretty-print.o : c-pretty-print.c $(C_PRETTY_PRINT_H) \
        $(C_TREE_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(REAL_H) \
index a84113f..cc00511 100644 (file)
@@ -51,6 +51,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "target-def.h"
 #include "gimple.h"
 #include "fixed-value.h"
+#include "libfuncs.h"
 
 cpp_reader *parse_in;          /* Declared in c-pragma.h.  */
 
@@ -4401,10 +4402,28 @@ set_builtin_user_assembler_name (tree decl, const char *asmspec)
 
   builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
   set_user_assembler_name (builtin, asmspec);
-  if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMCPY)
-    init_block_move_fn (asmspec);
-  else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMSET)
-    init_block_clear_fn (asmspec);
+  switch (DECL_FUNCTION_CODE (decl))
+    {
+    case BUILT_IN_MEMCPY:
+      init_block_move_fn (asmspec);
+      memcpy_libfunc = set_user_assembler_libfunc ("memcpy", asmspec);
+      break;
+    case BUILT_IN_MEMSET:
+      init_block_clear_fn (asmspec);
+      memset_libfunc = set_user_assembler_libfunc ("memset", asmspec);
+      break;
+    case BUILT_IN_MEMMOVE:
+      memmove_libfunc = set_user_assembler_libfunc ("memmove", asmspec);
+      break;
+    case BUILT_IN_MEMCMP:
+      memcmp_libfunc = set_user_assembler_libfunc ("memcmp", asmspec);
+      break;
+    case BUILT_IN_ABORT:
+      abort_libfunc = set_user_assembler_libfunc ("abort", asmspec);
+      break;
+    default:
+      break;
+    }
 }
 
 /* The number of named compound-literals generated thus far.  */
index 730f805..216de87 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for code generation pass of GNU compiler.
    Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -786,6 +786,7 @@ extern void init_all_optabs (void);
 
 /* Call this to initialize an optab function entry.  */
 extern rtx init_one_libfunc (const char *);
+extern rtx set_user_assembler_libfunc (const char *, const char *);
 
 extern int vector_mode_valid_p (enum machine_mode);
 
index ed59f5e..f7e44db 100644 (file)
@@ -6072,6 +6072,24 @@ init_one_libfunc (const char *name)
   return XEXP (DECL_RTL (decl), 0);
 }
 
+/* Adjust the assembler name of libfunc NAME to ASMSPEC.  */
+
+rtx
+set_user_assembler_libfunc (const char *name, const char *asmspec)
+{
+  tree id, decl;
+  void **slot;
+  hashval_t hash;
+
+  id = get_identifier (name);
+  hash = htab_hash_string (name);
+  slot = htab_find_slot_with_hash (libfunc_decls, id, hash, NO_INSERT);
+  gcc_assert (slot);
+  decl = (tree) *slot;
+  set_user_assembler_name (decl, asmspec);
+  return XEXP (DECL_RTL (decl), 0);
+}
+
 /* Call this to reset the function entry for one optab (OPTABLE) in mode
    MODE to NAME, which should be either 0 or a string constant.  */
 void
index d93660e..ae361a5 100644 (file)
@@ -1,5 +1,8 @@
 2009-03-17  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/39443
+       * gcc.dg/pr39443.c: New test.
+
        PR debug/39412
        * gcc.dg/debug/pr39412.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr39443.c b/gcc/testsuite/gcc.dg/pr39443.c
new file mode 100644 (file)
index 0000000..1baa63a
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR middle-end/39443 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler-not "memcmp" } } */
+
+typedef __SIZE_TYPE__ size_t;
+
+extern int memcmp (const void *s1, const void *s2, size_t n)
+  __attribute__ ((__nothrow__, __pure__));
+extern __typeof (memcmp) memcmp __asm__ ("memory_compare");
+
+int
+test (char *s, char *t, int cnt)
+{
+  if (__builtin_expect (cnt, 0))
+    return memcmp (s, t, cnt);
+  return 0;
+}