From c6f0626b11b25b4159489e4935086ea49d47c541 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 19 Jun 2019 21:46:09 +0000 Subject: [PATCH] re PR tree-optimization/90626 (fold strcmp(a, b) == 0 to zero when one string length is exact and the other is unequal) PR tree-optimization/90626 gcc/ChangeLog: * tree-ssa-strlen.c (strxcmp_unequal): Fix typos. From-SVN: r272487 --- gcc/ChangeLog | 3 +++ gcc/tree-ssa-strlen.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3f868bacad4..5b67ad0ede3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -11,6 +11,9 @@ 2019-06-19 Martin Sebor + PR tree-optimization/90626 + * tree-ssa-strlen.c (strxcmp_unequal): Fix typos. + PR tree-optimization/90626 * tree-ssa-strlen.c (strxcmp_unequal): New function. (handle_builtin_string_cmp): Call it. diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 80e7f9992d4..74cd6c44874 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -2981,7 +2981,7 @@ strxcmp_unequal (int idx1, int idx2, unsigned HOST_WIDE_INT n) if (idx2 < 0) { len2 = ~idx2; - nulterm1 = true; + nulterm2 = true; } else if (strinfo *si = get_strinfo (idx2)) { @@ -3003,7 +3003,8 @@ strxcmp_unequal (int idx1, int idx2, unsigned HOST_WIDE_INT n) if (len2 > n) len2 = n; - if (len1 != len2 && (nulterm1 || nulterm2)) + if ((len1 < len2 && nulterm1) + || (len2 < len1 && nulterm2)) /* The string lengths are definitely unequal and the result can be folded to one (since it's used for comparison with zero). */ return true; -- 2.30.2