From d0d7f887b79cba3eb3e37c2dc7d59bc85e405ca9 Mon Sep 17 00:00:00 2001 From: Bernd Schmidt Date: Thu, 29 Sep 2016 11:21:20 -0500 Subject: [PATCH] builtins.c (expand_builtin_memcmp): don't swap args unless result is only being compared with zero. 2016-09-29 Bernd Schmidt * builtins.c (expand_builtin_memcmp): don't swap args unless result is only being compared with zero. From-SVN: r240625 --- gcc/ChangeLog | 5 +++++ gcc/builtins.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 189228f987b..bb83b064865 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-09-29 Bernd Schmidt + + * builtins.c (expand_builtin_memcmp): don't swap args unless + result is only being compared with zero. + 2016-09-29 Marek Polacek * dwarf2out.c (loc_descriptor): Add fall through comment. diff --git a/gcc/builtins.c b/gcc/builtins.c index 04dcf95acd2..35cb109bc4b 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -3707,11 +3707,13 @@ expand_builtin_memcmp (tree exp, rtx target, bool result_eq) by_pieces_constfn constfn = NULL; - const char *src_str = c_getstr (arg1); - if (src_str == NULL) - src_str = c_getstr (arg2); - else - std::swap (arg1_rtx, arg2_rtx); + const char *src_str = c_getstr (arg2); + if (result_eq && src_str == NULL) + { + src_str = c_getstr (arg1); + if (src_str != NULL) + std::swap (arg1_rtx, arg2_rtx); + } /* If SRC is a string constant and block move would be done by pieces, we can avoid loading the string from memory -- 2.30.2