aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorQing Zhao <qing.zhao@oracle.com>2017-11-17 05:32:05 +0000
committerJeff Law <law@gcc.gnu.org>2017-11-16 22:32:05 -0700
commitcaed5c92712701509413c579fb004faa965e4004 (patch)
treee6a25de7a4c912e87fdd28ec9a45b3cfc6aa2388 /gcc/gimple-fold.c
parent5958557b750254f28954d1ed6a3ce0b9cb48c6fb (diff)
downloadgcc-caed5c92712701509413c579fb004faa965e4004.zip
gcc-caed5c92712701509413c579fb004faa965e4004.tar.gz
gcc-caed5c92712701509413c579fb004faa965e4004.tar.bz2
re PR middle-end/78809 (Inline strcmp with small constant strings)
2017-11-15 Qing Zhao <qing.zhao@oracle.com> PR middle-end/78809 * gimple-fold.c (gimple_fold_builtin_string_compare): Add handling of replacing call to strncmp with corresponding call to strcmp when meeting conditions. PR middle-end/78809 * gcc.dg/strcmpopt_1.c: New test. From-SVN: r254856
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index adb6f3b..1ed6383 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -2258,6 +2258,21 @@ gimple_fold_builtin_string_compare (gimple_stmt_iterator *gsi)
return true;
}
+ /* If length is larger than the length of one constant string,
+ replace strncmp with corresponding strcmp */
+ if (fcode == BUILT_IN_STRNCMP
+ && length > 0
+ && ((p2 && (size_t) length > strlen (p2))
+ || (p1 && (size_t) length > strlen (p1))))
+ {
+ tree fn = builtin_decl_implicit (BUILT_IN_STRCMP);
+ if (!fn)
+ return false;
+ gimple *repl = gimple_build_call (fn, 2, str1, str2);
+ replace_call_with_call_and_fold (gsi, repl);
+ return true;
+ }
+
return false;
}