From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 9D03C385B80B for ; Fri, 3 Apr 2020 17:42:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D03C385B80B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-z6xRcBycO1-CyB3akxfZ3Q-1; Fri, 03 Apr 2020 13:42:15 -0400 X-MC-Unique: z6xRcBycO1-CyB3akxfZ3Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF75E107ACC4; Fri, 3 Apr 2020 17:42:14 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-52.ams2.redhat.com [10.36.113.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E2345C1BE; Fri, 3 Apr 2020 17:42:14 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 033HgCDR002432; Fri, 3 Apr 2020 19:42:12 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 033HgAqm002431; Fri, 3 Apr 2020 19:42:10 +0200 Date: Fri, 3 Apr 2020 19:42:10 +0200 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cselib: Don't consider SP_DERIVED_VALUE_P values as useless [PR94468] Message-ID: <20200403174210.GE2212@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Spam-Status: No, score=-19.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2020 17:42:19 -0000 Hi! The following testcase ICEs, because at one point we see the SP_DERIVED_VALUE_P VALUE as useless (not PRESERVED_VALUE_P and no locs) and so expect it to be discarded as useless. But, later on we are adding some new VALUE that is equivalent to it, and when adding the equivalency that that new VALUE is equal to this SP_DERIVED_VALUE_P, new_elt_loc_list has code for VALUE canonicalization and reverses addition if uid is smaller, and at that point a new loc is added to the SP_DERIVED_VALUE_P VALUE and it isn't discarded as useless anymore. Now, I think we don't want to discard the SP_DERIVED_VALUE_P values even if they have no locs, because they still have the special behaviour that they then force other new VALUEs to be canonicalized against them, which is what this patch implements. I've not set PRESERVED_VALUE_P on the SP_DERIVED_VALUE_P at the creation time, because whether a VALUE is preserved or not is something that affects var-tracking decisions quite = a lot and we shouldn't set it blindly on other VALUEs. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or, to avoid the repetitive code, should I introduce static bool cselib_useless_value_p (cselib_val *v) { return (v->locs =3D=3D 0 =09 && !PRESERVED_VALUE_P (v->val_rtx) =09 && !SP_DERIVED_VALUE_P (v->val_rtx))); } predicate and use it in those 6 spots? 2020-04-03 Jakub Jelinek =09PR rtl-optimization/94468 =09* cselib.c (references_value_p): Formatting fix. =09(discard_useless_locs, discard_useless_values, =09cselib_invalidate_regno_val, cselib_invalidate_mem, =09cselib_record_set): Don't consider SP_DERIVED_VALUE_P values useless. =09* g++.dg/opt/pr94468.C: New test. --- gcc/cselib.c.jj=092020-04-02 14:28:02.620577679 +0200 +++ gcc/cselib.c=092020-04-03 17:08:54.295282018 +0200 @@ -629,8 +629,8 @@ references_value_p (const_rtx x, int onl int i, j; =20 if (GET_CODE (x) =3D=3D VALUE - && (! only_useless || -=09 (CSELIB_VAL_PTR (x)->locs =3D=3D 0 && !PRESERVED_VALUE_P (x)))) + && (! only_useless +=09 || (CSELIB_VAL_PTR (x)->locs =3D=3D 0 && !PRESERVED_VALUE_P (x)))) return 1; =20 for (i =3D GET_RTX_LENGTH (code) - 1; i >=3D 0; i--) @@ -666,7 +666,10 @@ discard_useless_locs (cselib_val **x, vo =09p =3D &(*p)->next; } =20 - if (had_locs && v->locs =3D=3D 0 && !PRESERVED_VALUE_P (v->val_rtx)) + if (had_locs + && v->locs =3D=3D 0 + && !PRESERVED_VALUE_P (v->val_rtx) + && !SP_DERIVED_VALUE_P (v->val_rtx)) { if (setting_insn && DEBUG_INSN_P (setting_insn)) =09n_useless_debug_values++; @@ -684,7 +687,9 @@ discard_useless_values (cselib_val **x, { cselib_val *v =3D *x; =20 - if (v->locs =3D=3D 0 && !PRESERVED_VALUE_P (v->val_rtx)) + if (v->locs =3D=3D 0 + && !PRESERVED_VALUE_P (v->val_rtx) + && !SP_DERIVED_VALUE_P (v->val_rtx)) { if (cselib_discard_hook) =09cselib_discard_hook (v); @@ -2370,7 +2375,10 @@ cselib_invalidate_regno_val (unsigned in =09} } =20 - if (had_locs && v->locs =3D=3D 0 && !PRESERVED_VALUE_P (v->val_rtx)) + if (had_locs + && v->locs =3D=3D 0 + && !PRESERVED_VALUE_P (v->val_rtx) + && !SP_DERIVED_VALUE_P (v->val_rtx)) { if (setting_insn && DEBUG_INSN_P (setting_insn)) =09n_useless_debug_values++; @@ -2515,7 +2523,10 @@ cselib_invalidate_mem (rtx mem_rtx) =09 unchain_one_elt_loc_list (p); =09} =20 - if (had_locs && v->locs =3D=3D 0 && !PRESERVED_VALUE_P (v->val_rtx)) + if (had_locs +=09 && v->locs =3D=3D 0 +=09 && !PRESERVED_VALUE_P (v->val_rtx) +=09 && !SP_DERIVED_VALUE_P (v->val_rtx)) =09{ =09 if (setting_insn && DEBUG_INSN_P (setting_insn)) =09 n_useless_debug_values++; @@ -2593,14 +2604,18 @@ cselib_record_set (rtx dest, cselib_val =09 REG_VALUES (dreg)->elt =3D src_elt; =09} =20 - if (src_elt->locs =3D=3D 0 && !PRESERVED_VALUE_P (src_elt->val_rtx)) + if (src_elt->locs =3D=3D 0 +=09 && !PRESERVED_VALUE_P (src_elt->val_rtx) +=09 && !SP_DERIVED_VALUE_P (src_elt->val_rtx)) =09n_useless_values--; new_elt_loc_list (src_elt, dest); } else if (MEM_P (dest) && dest_addr_elt !=3D 0 =09 && cselib_record_memory) { - if (src_elt->locs =3D=3D 0 && !PRESERVED_VALUE_P (src_elt->val_rtx)) + if (src_elt->locs =3D=3D 0 +=09 && !PRESERVED_VALUE_P (src_elt->val_rtx) +=09 && !SP_DERIVED_VALUE_P (src_elt->val_rtx)) =09n_useless_values--; add_mem_for_addr (dest_addr_elt, src_elt, dest); } --- gcc/testsuite/g++.dg/opt/pr94468.C.jj=092020-04-03 17:16:38.804457422 += 0200 +++ gcc/testsuite/g++.dg/opt/pr94468.C=092020-04-03 17:16:18.450756522 +020= 0 @@ -0,0 +1,57 @@ +// PR rtl-optimization/94468 +// { dg-do compile { target c++11 } } +// { dg-options "-O2" } +// { dg-additional-options "-fPIC" { target fpic } } + +bool a(); +enum b {}; +class c; +template struct d; +template struct d { + typedef e i; +}; +struct j { j(void(int, j *, c *, void **, bool *)) {} }; +template struct m : public j { + l ab; + static void ac(int, j *, c *, void **, bool *); + m(l f) : j(ac), ab(f) {} +}; +b ad; +struct c { + template + void ae(typename d::i *p, n af, typename d::i *ag, o ah) { + ai(p, &af, ag, &ah, new m(ah), ad, &d::i::aj); + } + void ai(c *, void *, c *, void *, j *, b, int *); +}; +struct r : public c { static int aj; void t(); }; +struct al : public c { + static int aj; + void am(); + void ao(); + void ap(); +}; +struct aq { aq(const int &, const int & =3D int()); }; +struct ar : public c { ~ar(); }; +struct as : public ar { + as(); + void at(); + void au(); + void av(); +}; +struct u : public c { void ax(); }; +struct ay { int az(); }; +struct ba : public c { static int aj; void bb(); }; +struct bc : public al { bc() { if (a()) am(); } }; +as::as() { + al *bd =3D new bc; + ae(bd, &al::ao, this, &as::au); + ae(bd, &al::ap, this, &as::av); + r be; + u bf; + ae(&be, &r::t, &bf, &u::ax); + c bg =3D *bd; + ae(static_cast(&bg), &ba::bb, this, &as::at); + ay bh; + aq am(bh.az()); +} =09Jakub