Commit b99d7d97 by Qing Zhao Committed by Qing Zhao

Do not expand the call to memcmp at all when overflow is detected.

From-SVN: r263563
parent 0cd020ae
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> 2018-08-15 Martin Sebor <msebor@redhat.com>
PR tree-optimization/71625 PR tree-optimization/71625
......
...@@ -4481,11 +4481,16 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq) ...@@ -4481,11 +4481,16 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq)
/*objsize=*/NULL_TREE); /*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 /* Due to the performance benefit, always inline the calls first
when result_eq is false. */ when result_eq is false. */
rtx result = NULL_RTX; 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); result = inline_expand_builtin_string_cmp (exp, target);
if (result) if (result)
......
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> 2018-08-15 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
* gcc.dg/wmain.c: New test. * gcc.dg/wmain.c: New test.
......
/* When the specified length exceeds one of the arguments of the call to memcmp, /* When the specified length exceeds one of the arguments of the call to memcmp,
the call to memcmp should NOT be inlined. */ the call to memcmp should NOT be inlined. */
/* { dg-do run } */ /* { dg-do compile } */
/* { dg-options "-O2 -fdump-rtl-expand -Wno-stringop-overflow" } */ /* { dg-options "-O2 -Wno-stringop-overflow" } */
typedef struct { char s[8]; int x; } S; typedef struct { char s[8]; int x; } S;
...@@ -33,4 +33,4 @@ int main (void) ...@@ -33,4 +33,4 @@ int main (void)
} }
/* { dg-final { scan-rtl-dump-times "__builtin_memcmp" 6 "expand" } } */ /* { dg-final { scan-assembler-times "memcmp" 2 } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment