Do not expand the call to memcmp at all when overflow is detected.
authorQing Zhao <qing.zhao@oracle.com>
Wed, 15 Aug 2018 16:33:52 +0000 (16:33 +0000)
committerQing Zhao <qinzhao@gcc.gnu.org>
Wed, 15 Aug 2018 16:33:52 +0000 (16:33 +0000)
From-SVN: r263563

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/strcmpopt_6.c

index 8ca8b562a0e71e1a0524b571045700b9ba6b438d..e575b553c42ef8d5fd2b9af0aa9e39d8630dd8c1 100644 (file)
@@ -1,3 +1,9 @@
+2018-08-15  Qing Zhao  <qing.zhao@oracle.com>
+
+       PR testsuite/86519
+       * builtins.c (expand_builtin_memcmp): Do not expand the call
+       when overflow is detected.
+
 2018-08-15  Martin Sebor  <msebor@redhat.com>
 
        PR tree-optimization/71625
index 867d153d79880b909dc05bbce83c076405d0b5d7..6716aabfa7319d76cac4ffa1626528ce458feb6d 100644 (file)
@@ -4481,11 +4481,16 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq)
                                  /*objsize=*/NULL_TREE);
     }
 
+  /* If the specified length exceeds the size of either object, 
+     call the function.  */
+  if (!no_overflow)
+    return NULL_RTX;
+
   /* Due to the performance benefit, always inline the calls first
      when result_eq is false.  */
   rtx result = NULL_RTX;
 
-  if (!result_eq && fcode != BUILT_IN_BCMP && no_overflow)
+  if (!result_eq && fcode != BUILT_IN_BCMP)
     {
       result = inline_expand_builtin_string_cmp (exp, target);
       if (result)
index 0bcf92fe7d2eff0dc7b6bc5987b101e7f2324a0b..bd167b3a77ecd922ec8991e404ad7c8eb18fe270 100644 (file)
@@ -1,3 +1,9 @@
+2018-08-15  Qing Zhao <qing.zhao@oracle.com>
+
+       PR testsuite/86519
+       * gcc.dg/strcmpopt_6.c: Scan the assembly file instead of
+       the .expand file.
+
 2018-08-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
        * gcc.dg/wmain.c: New test.
index 964b9e4839fa16274f831a8a0ee112a19a602f0e..4c6de02824f44ba79765c2f05621ed57860465b2 100644 (file)
@@ -1,7 +1,7 @@
 /* When the specified length exceeds one of the arguments of the call to memcmp, 
    the call to memcmp should NOT be inlined.  */
-/* { dg-do run } */
-/* { dg-options "-O2 -fdump-rtl-expand -Wno-stringop-overflow" } */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wno-stringop-overflow" } */
 
 typedef struct { char s[8]; int x; } S;
 
@@ -33,4 +33,4 @@ int main (void)
 
 }
 
-/* { dg-final { scan-rtl-dump-times "__builtin_memcmp" 6 "expand" } } */
+/* { dg-final { scan-assembler-times "memcmp" 2 } } */