From patchwork Tue May 2 08:08:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 89266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp434649vqo; Tue, 2 May 2023 01:09:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ak5xRCJJwmYM60oVhKdYGnoILZmrzu6K5ziQPdYZDrybKZgOKo3/DH9/D94LyyO7HEGXX X-Received: by 2002:a17:906:d54c:b0:95f:a89d:efb7 with SMTP id cr12-20020a170906d54c00b0095fa89defb7mr19005710ejc.69.1683014953948; Tue, 02 May 2023 01:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683014953; cv=none; d=google.com; s=arc-20160816; b=H+wls4temkcvL7vzBHAsn31fh7cx8YZpPUOiDDjm8+Q5FyDE74ZeIZvHupSND229aJ u4cNdbk28FQe0Jh9gaM8rP7Ghd3PQNoTSfWY8EHr3D+tKfTETWP6ApxTYm3bPkcuzcKF +O3/EdIYnkpDwRm2b3tgA+/Lh0foKZANV7c+JdxXasaFqCAffEs8HrpmVsZHpC/skNGh AOdKp2iHFrms2ScoAzTrMoxBn34+rUr0+2V/GG9roWHAjr9bqU5nljTOS4aWC8OdDRvv gFwwGvtS1eDGGr0hif2s9OJ8/63qLwqEiIW4G0kaz9/pNfTnKYAE713zQOe4/2+Zt/yj yKXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=gMc+3wfe1y3MnkLOH5c+e/qCFGo34uaO8pgLLR4RsEA=; b=ce+rVMAww57LOpnB3QmOgfs+tSxJHPjUVTy60vK620Ne7ryI0UxVPingEV7U7B2AC4 FwRPiJ5eVDa00r20wcpT/q8TgO/P5gnM17dgKiPzmbC/Az8pZa7kcj05lhclxLQQ5Rww eLgpx3Uu3+KFUPAw365sx1mKGPSNy7RxtlSLbQqtKR9DjFpQ7DfAOlH1jW+NU80+QV7z ekv7uVKtVrA6Ct2tnE5QIoXLuhBh/1jhpoTc1S2EVTdVGoaTyfikXbz+uKAugl23BBwY arC2iGuPesG/+W5oEKWSFMob5spfazQ9P8Xq3QU7ljCcK9nY3cXwu3OWdrp9kXv/eKE4 i2NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UjVrmOLZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gn20-20020a1709070d1400b0095393d60b70si28490536ejc.616.2023.05.02.01.09.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 01:09:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UjVrmOLZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 955203857BB2 for ; Tue, 2 May 2023 08:09:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 955203857BB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683014952; bh=gMc+3wfe1y3MnkLOH5c+e/qCFGo34uaO8pgLLR4RsEA=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UjVrmOLZTlgpVUorOgjkogtnUVDxVQlV5WxxDX6xmTTAV5qviZW7EnRpP81+eMf8s hBLIiGJXAiFz94LxS5tutPY823Q7YlXsdDANXQ3gaAgb5L+9F0FWiXkS8ux7RA7qnJ AaHBEWgGp+vvJebBTM89EZslqoD5aMmkPrxI0By8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 345063858D28 for ; Tue, 2 May 2023 08:08:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 345063858D28 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-X4oewkyGMCS6281PnpOdkg-1; Tue, 02 May 2023 04:08:24 -0400 X-MC-Unique: X4oewkyGMCS6281PnpOdkg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61EF2811E7D; Tue, 2 May 2023 08:08:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.156]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22EE02026DFD; Tue, 2 May 2023 08:08:24 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 34288L3X3117455 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 2 May 2023 10:08:21 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 34288KZa3117453; Tue, 2 May 2023 10:08:20 +0200 Date: Tue, 2 May 2023 10:08:19 +0200 To: Uros Bizjak , Hongtao Liu , hjl.tools@gmail.com Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Fix up handling of debug insns in STV [PR109676] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764769087925446104?= X-GMAIL-MSGID: =?utf-8?q?1764769087925446104?= Hi! The following testcase ICEs because STV replaces there (debug_insn 114 47 51 8 (var_location:TI D#3 (reg:TI 91 [ p ])) -1 (nil)) with (debug_insn 114 47 51 8 (var_location:TI D#3 (reg:V1TI 91 [ p ])) -1 (nil)) which is invalid because of the mode mismatch. STV has fix_debug_reg_uses function which is supposed to fix this up and adjust such debug insns into (debug_insn 114 47 51 8 (var_location:TI D#3 (subreg:TI (reg:V1TI 91 [ p ]) 0)) -1 (nil)) but it doesn't trigger here. The IL before stv1 has: (debug_insn 114 47 51 8 (var_location:TI D#3 (reg:TI 91 [ p ])) -1 (nil)) ... (insn 63 62 64 8 (set (mem/c:TI (reg/f:DI 89 [ .result_ptr ]) [0 .mStorage+0 S16 A32]) (reg:TI 91 [ p ])) "pr109676.C":4:48 87 {*movti_internal} (expr_list:REG_DEAD (reg:TI 91 [ p ]) (nil))) in bb 8 and (insn 97 96 98 9 (set (reg:TI 91 [ p ]) (mem/c:TI (plus:DI (reg/f:DI 19 frame) (const_int -32 [0xffffffffffffffe0])) [0 p+0 S16 A128])) "pr109676.C":26:12 87 {*movti_internal} (nil)) (insn 98 97 99 9 (set (mem/c:TI (plus:DI (reg/f:DI 19 frame) (const_int -64 [0xffffffffffffffc0])) [0 tmp+0 S16 A128]) (reg:TI 91 [ p ])) "pr109676.C":26:12 87 {*movti_internal} (nil)) in bb9. PUT_MODE on a REG is done in two spots in timode_scalar_chain::convert_insn, one is: switch (GET_CODE (dst)) { case REG: if (GET_MODE (dst) == TImode) { PUT_MODE (dst, V1TImode); fix_debug_reg_uses (dst); } if (GET_MODE (dst) == V1TImode) when seeing the REG in SET_DEST and another one the hunk the patch adjusts. Because bb 8 comes first in the order the pass walks the bbs, we first notice the TImode pseudo on insn 63 where it is SET_SRC, use PUT_MODE there unconditionally, so for a shared REG it changes all other uses in the IL, and then don't call fix_debug_reg_uses because DF_REG_DEF_CHAIN (REGNO (src)) is non-NULL - the REG is set in insn 97 but we haven't processed it yet. Later on we process insn 97, but because the REG in SET_DEST already has V1TImode, we don't do anything, even when the src handling code earlier relied on it being done. The following patch fixes this by using similar code for both dst and src, in particular calling fix_debug_reg_uses once when we actually change REG mode from TImode to V1TImode, and not later on. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/13.2? 2023-05-02 Jakub Jelinek PR debug/109676 * config/i386/i386-features.cc (timode_scalar_chain::convert_insn): If src is REG, change its mode to V1TImode and call fix_debug_reg_uses for it only if it still has TImode. Don't decide whether to call fix_debug_reg_uses based on whether SRC is ever set or not. * g++.target/i386/pr109676.C: New test. Jakub --- gcc/config/i386/i386-features.cc.jj 2023-03-03 11:18:33.100296735 +0100 +++ gcc/config/i386/i386-features.cc 2023-05-01 14:50:45.559668773 +0200 @@ -1635,10 +1635,11 @@ timode_scalar_chain::convert_insn (rtx_i switch (GET_CODE (src)) { case REG: - PUT_MODE (src, V1TImode); - /* Call fix_debug_reg_uses only if SRC is never defined. */ - if (!DF_REG_DEF_CHAIN (REGNO (src))) - fix_debug_reg_uses (src); + if (GET_MODE (src) == TImode) + { + PUT_MODE (src, V1TImode); + fix_debug_reg_uses (src); + } break; case MEM: --- gcc/testsuite/g++.target/i386/pr109676.C.jj 2023-05-01 14:58:09.024329438 +0200 +++ gcc/testsuite/g++.target/i386/pr109676.C 2023-05-01 14:57:46.566650471 +0200 @@ -0,0 +1,46 @@ +// PR debug/109676 +// { dg-do compile { target c++11 } } +// { dg-options "-O2 -g -march=alderlake" } + +template +struct A { + T a; + char b; + template + A (U x, int) : a{x} {} + A (...); + T foo () { return a; } +}; +bool bar (); +struct B { int c, d; unsigned char e[8]; }; +bool baz (); +struct C { C () : f () {} B &boo () { return f; } B f; }; + +A +qux () +{ + { + A p; + bool t = true; + for (; bar ();) + if (baz ()) + { + t = false; + break; + } + if (t) + p.b = false; + return p; + } +} + +A +garply () +{ + C g; + A h = qux (); + if (!h.b) + return 0; + g.boo () = h.foo (); + return A{g, 0}; +}