public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][Middle-end]patch for fixing PR 86519
@ 2018-08-14 14:57 Qing Zhao
  2018-08-15  4:25 ` Jeff Law
  0 siblings, 1 reply; 17+ messages in thread
From: Qing Zhao @ 2018-08-14 14:57 UTC (permalink / raw)
  To: gcc Patches; +Cc: jakub Jelinek, jeff Law, richard Biener

[-- Attachment #1: Type: text/plain, Size: 1771 bytes --]

Hi,

PR 86519:New test case gcc.dg/strcmpopt_6.c fails with its introduction in r262636.

***the root cause is:

for the following call to memcmp:   __builtin_memcmp (s->s, "a", 3);
the specified length 3 is larger than the length of "a", it's clearly an out-of-bound access. This new testing case is try to claim that,
For such out-of-bound access, we should NOT expand this call at all. The new added in-lining expansion was prohibited under
such situation, However, the expansion to hardware compare insn (old code) is NOT prohibited under such situation. 
on powerPC, the above call to memcmp is expanded to hardware compare insn. therefore, the testing case failed.

***in addition to the above major issue, there is also one minor issue with the new testing case itself:

dg-final { scan-rtl-dump-times "__builtin_memcmp" 6 "expand” }
this is trying to scan the dumped .expand file to match the string “__builtin_memcmp” exactly 6 times. however, the # of times that
the string “__builtin_memcmp” appears in the .expand file varies on different target or optimization level, in order to avoid such
instability, instead of scanning the .expand file to match the string “__builtin_memcmp”,  scanning the final assembly file to match
the string “memcmp”.

please review the attached simple patch.

thanks.

Qing

gcc/ChangeLog:

+2018-08-14  Qing Zhao  <qing.zhao@oracle.com>
+
+       PR testsuite/86519
+       * builtins.c (expand_builtin_memcmp): Do not expand the call
+       when overflow is detected.
+
gcc/testsuite/ChangeLog:

+2018-08-14  Qing Zhao <qing.zhao@oracle.com>
+
+       PR testsuite/86519
+       * gcc.dg/strcmpopt_6.c: Scan the assembly file instead of
+       the .expand file.
+


[-- Attachment #2: PR86519.patch --]
[-- Type: application/octet-stream, Size: 1827 bytes --]

From 596e7164df0d84748dc6bf6a3cf39e5f85ab8331 Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Tue, 7 Aug 2018 09:52:14 -0700
Subject: [PATCH] fix PR86519

---
 gcc/builtins.c                     | 7 ++++++-
 gcc/testsuite/gcc.dg/strcmpopt_6.c | 6 +++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 39611de..d1d49f5 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -4480,11 +4480,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)
diff --git a/gcc/testsuite/gcc.dg/strcmpopt_6.c b/gcc/testsuite/gcc.dg/strcmpopt_6.c
index 964b9e4..4c6de02 100644
--- a/gcc/testsuite/gcc.dg/strcmpopt_6.c
+++ b/gcc/testsuite/gcc.dg/strcmpopt_6.c
@@ -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 } } */
-- 
1.9.1

[-- Attachment #3: Type: text/plain, Size: 5 bytes --]







^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-08-24  2:55 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-14 14:57 [PATCH][Middle-end]patch for fixing PR 86519 Qing Zhao
2018-08-15  4:25 ` Jeff Law
2018-08-15 16:36   ` Qing Zhao
2018-08-18  3:43     ` Paul Hua
2018-08-18  3:50       ` Jeff Law
2018-08-20  8:57         ` Rainer Orth
2018-08-20 18:13           ` Qing Zhao
2018-08-22 15:10           ` Qing Zhao
2018-08-22 15:50             ` Rainer Orth
2018-08-22 17:05               ` Qing Zhao
2018-08-22 22:01                 ` Jeff Law
2018-08-23 16:13                   ` Qing Zhao
2018-08-24  2:55                     ` Jeff Law
2018-08-20 23:02       ` Qing Zhao
2018-08-21 13:07         ` Paul Hua
     [not found]           ` <2AC2B18F-9442-4C4A-A473-FA1759941220@oracle.com>
2018-08-22  0:25             ` Paul Hua
2018-08-22 14:04               ` Qing Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).