From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 96C1B394BE03; Fri, 14 May 2021 14:54:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96C1B394BE03 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Check for matching CONST_VECTOR encodings [PR99929] X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/vendors/redhat/heads/gcc-8-branch X-Git-Oldrev: 6331cd93c5054d0ac598e48b2ed05649a399ee53 X-Git-Newrev: cc89aab0e924f5f8f871b35180ff139955893516 Message-Id: <20210514145430.96C1B394BE03@sourceware.org> Date: Fri, 14 May 2021 14:54:30 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2021 14:54:30 -0000 https://gcc.gnu.org/g:cc89aab0e924f5f8f871b35180ff139955893516 commit cc89aab0e924f5f8f871b35180ff139955893516 Author: Richard Sandiford Date: Mon Apr 26 09:36:48 2021 +0100 Check for matching CONST_VECTOR encodings [PR99929] PR99929 is one of those “how did we get away with this for so long” bugs: the equality routines weren't checking whether two variable-length CONST_VECTORs had the same encoding. This meant that: { 1, 0, 0, 0, 0, 0, ... } would appear to be equal to: { 1, 0, 1, 0, 1, 0, ... } since both are represented using the elements { 1, 0 }. gcc/ PR rtl-optimization/99929 * rtl.h (same_vector_encodings_p): New function. * cse.c (exp_equiv_p): Check that CONST_VECTORs have the same encoding. * cselib.c (rtx_equal_for_cselib_1): Likewise. * jump.c (rtx_renumbered_equal_p): Likewise. * lra-constraints.c (operands_match_p): Likewise. * reload.c (operands_match_p): Likewise. * rtl.c (rtx_equal_p_cb, rtx_equal_p): Likewise. (cherry picked from commit a87d3f964df31d4fbceb822c6d293e85c117d992) Diff: --- gcc/cse.c | 5 +++++ gcc/cselib.c | 5 +++++ gcc/jump.c | 5 +++++ gcc/lra-constraints.c | 5 +++++ gcc/reload.c | 5 +++++ gcc/rtl.c | 10 ++++++++++ gcc/rtl.h | 17 +++++++++++++++++ 7 files changed, 52 insertions(+) diff --git a/gcc/cse.c b/gcc/cse.c index a73a771041a..2382b24d816 100644 --- a/gcc/cse.c +++ b/gcc/cse.c @@ -2627,6 +2627,11 @@ exp_equiv_p (const_rtx x, const_rtx y, int validate, bool for_gcse) CASE_CONST_UNIQUE: return x == y; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case LABEL_REF: return label_ref_label (x) == label_ref_label (y); diff --git a/gcc/cselib.c b/gcc/cselib.c index 5a978c1f4b8..de5d9d4e2ba 100644 --- a/gcc/cselib.c +++ b/gcc/cselib.c @@ -938,6 +938,11 @@ rtx_equal_for_cselib_1 (rtx x, rtx y, machine_mode memmode, int depth) case DEBUG_EXPR: return 0; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case DEBUG_IMPLICIT_PTR: return DEBUG_IMPLICIT_PTR_DECL (x) == DEBUG_IMPLICIT_PTR_DECL (y); diff --git a/gcc/jump.c b/gcc/jump.c index f379048f636..112317cd7e1 100644 --- a/gcc/jump.c +++ b/gcc/jump.c @@ -1767,6 +1767,11 @@ rtx_renumbered_equal_p (const_rtx x, const_rtx y) CASE_CONST_UNIQUE: return 0; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case LABEL_REF: /* We can't assume nonlocal labels have their following insns yet. */ if (LABEL_REF_NONLOCAL_P (x) || LABEL_REF_NONLOCAL_P (y)) diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c index 1e98df48132..80502441945 100644 --- a/gcc/lra-constraints.c +++ b/gcc/lra-constraints.c @@ -759,6 +759,11 @@ operands_match_p (rtx x, rtx y, int y_hard_regno) CASE_CONST_UNIQUE: return false; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case LABEL_REF: return label_ref_label (x) == label_ref_label (y); case SYMBOL_REF: diff --git a/gcc/reload.c b/gcc/reload.c index 88299a8a905..0e4f72065a2 100644 --- a/gcc/reload.c +++ b/gcc/reload.c @@ -2291,6 +2291,11 @@ operands_match_p (rtx x, rtx y) CASE_CONST_UNIQUE: return 0; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case LABEL_REF: return label_ref_label (x) == label_ref_label (y); case SYMBOL_REF: diff --git a/gcc/rtl.c b/gcc/rtl.c index dc03e1e5426..61cd4474586 100644 --- a/gcc/rtl.c +++ b/gcc/rtl.c @@ -460,6 +460,11 @@ rtx_equal_p_cb (const_rtx x, const_rtx y, rtx_equal_p_callback_function cb) CASE_CONST_UNIQUE: return 0; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case DEBUG_IMPLICIT_PTR: return DEBUG_IMPLICIT_PTR_DECL (x) == DEBUG_IMPLICIT_PTR_DECL (y); @@ -602,6 +607,11 @@ rtx_equal_p (const_rtx x, const_rtx y) CASE_CONST_UNIQUE: return 0; + case CONST_VECTOR: + if (!same_vector_encodings_p (x, y)) + return false; + break; + case DEBUG_IMPLICIT_PTR: return DEBUG_IMPLICIT_PTR_DECL (x) == DEBUG_IMPLICIT_PTR_DECL (y); diff --git a/gcc/rtl.h b/gcc/rtl.h index 31567126c83..fb2e088f7d1 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -3035,6 +3035,23 @@ vec_series_p (const_rtx x, rtx *base_out, rtx *step_out) return const_vec_series_p (x, base_out, step_out); } +/* Return true if CONST_VECTORs X and Y, which are known to have the same mode, + also have the same encoding. This means that they are equal whenever their + operands are equal. */ + +inline bool +same_vector_encodings_p (const_rtx x, const_rtx y) +{ + /* Don't be fussy about the encoding of constant-length vectors, + since XVECEXP (X, 0) and XVECEXP (Y, 0) list all the elements anyway. */ + if (poly_uint64 (CONST_VECTOR_NUNITS (x)).is_constant ()) + return true; + + return (CONST_VECTOR_NPATTERNS (x) == CONST_VECTOR_NPATTERNS (y) + && (CONST_VECTOR_NELTS_PER_PATTERN (x) + == CONST_VECTOR_NELTS_PER_PATTERN (y))); +} + /* Return the unpromoted (outer) mode of SUBREG_PROMOTED_VAR_P subreg X. */ inline scalar_int_mode