From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id DC47D385C017 for ; Tue, 31 Mar 2020 07:04:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DC47D385C017 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-224-0wrZdm-BNpeJxPMyZ3mzAg-1; Tue, 31 Mar 2020 03:04:24 -0400 X-MC-Unique: 0wrZdm-BNpeJxPMyZ3mzAg-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 BA17618A5500; Tue, 31 Mar 2020 07:04:23 +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 4B6CB5C1C5; Tue, 31 Mar 2020 07:04:23 +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 02V74KAC025795; Tue, 31 Mar 2020 09:04:21 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 02V74Ivw025714; Tue, 31 Mar 2020 09:04:18 +0200 Date: Tue, 31 Mar 2020 09:04:18 +0200 From: Jakub Jelinek To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] combine: Fix split_i2i3 ICE [PR94291] Message-ID: <20200331070418.GB2212@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=-21.0 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: Tue, 31 Mar 2020 07:04:28 -0000 Hi! The following testcase ICEs on armv7hl-linux-gnueabi. try_combine is called on: (gdb) p debug_rtx (i3) (insn 20 12 22 2 (set (mem/c:SI (plus:SI (reg/f:SI 102 sfp) (const_int -4 [0xfffffffffffffffc])) [1 x+0 S4 A32]) (reg:SI 125)) "pr94291.c":7:8 241 {*arm_movsi_insn} (expr_list:REG_DEAD (reg:SI 125) (nil))) (gdb) p debug_rtx (i2) (insn 12 7 20 2 (parallel [ (set (reg:CC 100 cc) (compare:CC (reg:SI 121 [ ]) (const_int 0 [0]))) (set (reg:SI 125) (reg:SI 121 [ ])) ]) "pr94291.c":7:8 248 {*movsi_compare0} (expr_list:REG_UNUSED (reg:CC 100 cc) (nil))) and tries to recognize cc =3D r121 cmp 0; [sfp-4] =3D r121 parallel, but that isn't recognized, so it splits it into two: split_i2i3 [sfp-4] =3D r121 followed by cc =3D r121 cmp 0 which is recognized, but ICEs because the code below insist that the SET_DEST of newi2pat (or first set in PARALLEL thereof) must be a REG or SUBREG of REG, but it is a MEM in this case. I don't see any condition that would guarantee that, perhaps for the swap_i2i3 case it was somehow guaranteed. As the code just wants to update LOG_LINKS and LOG_LINKS are only for registers, not for MEM or anything else, the patch just doesn't update thos= e if it isn't a REG or SUBREG of REG. Bootstrapped/regtested on armv7hl-linux-gnueabi and powerpc64le-linux, ok for trunk? 2020-03-31 Jakub Jelinek =09PR rtl-optimization/94291 =09* combine.c (try_combine): For split_i2i3, don't assume SET_DEST =09must be a REG or SUBREG of REG; if it is not one of these, don't =09update LOG_LINKs. =09* gcc.dg/pr94291.c: New test. --- gcc/combine.c.jj=092020-02-25 13:56:19.514076091 +0100 +++ gcc/combine.c=092020-03-30 17:23:17.579654895 +0200 @@ -4351,25 +4351,29 @@ try_combine (rtx_insn *i3, rtx_insn *i2, if (GET_CODE (x) =3D=3D PARALLEL) =09x =3D XVECEXP (newi2pat, 0, 0); =20 - /* It can only be a SET of a REG or of a SUBREG of a REG. */ - unsigned int regno =3D reg_or_subregno (SET_DEST (x)); - - bool done =3D false; - for (rtx_insn *insn =3D NEXT_INSN (i3); -=09 !done -=09 && insn -=09 && NONDEBUG_INSN_P (insn) -=09 && BLOCK_FOR_INSN (insn) =3D=3D this_basic_block; -=09 insn =3D NEXT_INSN (insn)) + if (REG_P (SET_DEST (x)) +=09 || (GET_CODE (SET_DEST (x)) =3D=3D SUBREG +=09 && REG_P (SUBREG_REG (SET_DEST (x))))) =09{ -=09 struct insn_link *link; -=09 FOR_EACH_LOG_LINK (link, insn) -=09 if (link->insn =3D=3D i3 && link->regno =3D=3D regno) -=09 { -=09=09link->insn =3D i2; -=09=09done =3D true; -=09=09break; -=09 } +=09 unsigned int regno =3D reg_or_subregno (SET_DEST (x)); + +=09 bool done =3D false; +=09 for (rtx_insn *insn =3D NEXT_INSN (i3); +=09 !done +=09 && insn +=09 && NONDEBUG_INSN_P (insn) +=09 && BLOCK_FOR_INSN (insn) =3D=3D this_basic_block; +=09 insn =3D NEXT_INSN (insn)) +=09 { +=09 struct insn_link *link; +=09 FOR_EACH_LOG_LINK (link, insn) +=09=09if (link->insn =3D=3D i3 && link->regno =3D=3D regno) +=09=09 { +=09=09 link->insn =3D i2; +=09=09 done =3D true; +=09=09 break; +=09=09 } +=09 } =09} } =20 --- gcc/testsuite/gcc.dg/pr94291.c.jj=092020-03-30 17:22:47.876092906 +0200 +++ gcc/testsuite/gcc.dg/pr94291.c=092020-03-30 17:22:22.230471072 +0200 @@ -0,0 +1,14 @@ +/* PR rtl-optimization/94291 */ +/* { dg-do compile } */ +/* { dg-options "-Og" } */ + +unsigned a; + +unsigned +foo (void) +{ + unsigned x + =3D (__builtin_sub_overflow ((long long) a, 0, &x) + ? 1 : (__INTPTR_TYPE__) __builtin_memmove (&x, foo, 1)); + return a; +} =09Jakub