diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-01-19 09:26:13 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-01-19 09:26:13 +0100 |
commit | b834435c8fa4cb9424787fe3044a49fef7992de8 (patch) | |
tree | 229604493332e62ed597166cf8cac53a00edeac6 /gcc/fold-const.cc | |
parent | 29a6db635f5eb38ba34d15a6ee35b00e753740e4 (diff) | |
download | gcc-b834435c8fa4cb9424787fe3044a49fef7992de8.zip gcc-b834435c8fa4cb9424787fe3044a49fef7992de8.tar.gz gcc-b834435c8fa4cb9424787fe3044a49fef7992de8.tar.bz2 |
fold-const: Optimize &"foo"[0] == "foo" [PR89074]
This is a non-C++ related part from the PR89074 address_compare changes.
For "foo" == "foo" we already optimize this from the (cmp @0 @0)
simplification, because we use operand_equal_p in that case
and operand_equal_p also compares the STRING_CSTs bytes rather than
just addresses.
2022-01-19 Jakub Jelinek <jakub@redhat.com>
PR c++/89074
* fold-const.cc (address_compare): Consider different STRING_CSTs
with the same lengths that memcmp the same as equal, not different.
* gcc.dg/tree-ssa/pr89074.c: New test.
Diffstat (limited to 'gcc/fold-const.cc')
-rw-r--r-- | gcc/fold-const.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index ff6a749..8fe633c 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -16587,6 +16587,15 @@ address_compare (tree_code code, tree type, tree op0, tree op1, || TREE_CODE (base1) == SSA_NAME || TREE_CODE (base1) == STRING_CST)) equal = (base0 == base1); + /* Assume different STRING_CSTs with the same content will be + merged. */ + if (equal == 0 + && TREE_CODE (base0) == STRING_CST + && TREE_CODE (base1) == STRING_CST + && TREE_STRING_LENGTH (base0) == TREE_STRING_LENGTH (base1) + && memcmp (TREE_STRING_POINTER (base0), TREE_STRING_POINTER (base1), + TREE_STRING_LENGTH (base0)) == 0) + equal = 1; if (equal == 1) { if (code == EQ_EXPR |