From patchwork Fri Feb 9 09:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 198795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp730459dyd; Fri, 9 Feb 2024 01:29:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpfxMQl0o8VTPkGjn0qagfeN33/tu5K6GQoIaj42FWuweLCTVRVkueBJ+AbxXurFcZ9xjz X-Received: by 2002:a05:620a:5641:b0:785:9539:43c3 with SMTP id vw1-20020a05620a564100b00785953943c3mr1149783qkn.19.1707470971348; Fri, 09 Feb 2024 01:29:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707470971; cv=pass; d=google.com; s=arc-20160816; b=1HPlsziiQjbAHnJFaavZTCqCLyUcgJIts8HsdRmNTXOozkjSm+hityrDIcmJJk4xSs +6dLP+egswS10IjJ/kwYSwZSw8wP1mNZlq3nUmbT2wCKy4X2ExYv/ilqBWxxwkaa97/l 8c90SQscceH/3LfY/N28qFpda6gndcmxvCIRpkhQDEDi9/UYOOtcwCzIUx0tY8FzDZGp ORkYwQ/i01cLw2cQYcZ3XNz9Wl4LGLk9KaQj/5F2mwLLpN5Rwz8Qa36OnsEPUtMW7tMx fDWkGgB6oWW0tAEaqr1H1b7549cNSBb0L2m0iugnrg31xgSVE1Vne50UJLqu3YXFakTc M/5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=uYyviMbv0eUdJw6mxKmK0S9+KCFReeNSBMceM/zEaRc=; fh=OoWa1TWVJ+IvFszdRYjNLJjTX9MdkbNdAHPP3ytHiXE=; b=A8WmSvWEqPm88r5uQxBz7xd52DrWThQiRaDbON+okEu0FqVdLNtMP0rR40FJwupxnL TBXiuCQq+nKsFMHWPSuahHVASAGMisovMa6UBbSjnuX7QMyqf5fcJI8em560iQ00V3jT haWvzYQ8AoMrbLCTUTHEOlEjvvkv8watwa/u2Jmn69yAeXKQz4FarLqb8TT01SRcWDLZ IL2ocf4QEIArHwsxn2U3DwOCQghe+DMwAt8XvV8ey/7A3GGMMSLsXeOfjyQDOb8kF7I4 K+v9bvfy/jEOBPIN7KwuQb+HiPaDIwr7PYzXl1I8+r0gsjTyXyinkXOtkj+chRj/He2f 9RzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ES99cx2n; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCXy4aZupKCHYJAp8b1KRIXl4Ij4f6rHc4gZpYmlNJhI1zsB/qiFC2Sp19Qh5yT69YvmQdNvcojXZNxNuTS8DfriM+jXqA== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u9-20020a05620a454900b00785a347f3ccsi1735461qkp.169.2024.02.09.01.29.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 01:29:31 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ES99cx2n; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 152B93858407 for ; Fri, 9 Feb 2024 09:29:31 +0000 (GMT) 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 409333858438 for ; Fri, 9 Feb 2024 09:28:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 409333858438 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 409333858438 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707470918; cv=none; b=hu09FUypWmdKPr93rFCIBYUNrqbIAfRmpqXlX0t3wNP5OXsFWoSr80L86JywAVnREkUzbOgWSL5Qnm9vQ8V9ObPaR37AY/c6mqv0D3iJCEZc3ihVf2PgyBy0bZf/DE3vlf5LPzRJoFkrxvHQG8CfSqtkFAS1AUZQo8xKfn4LKX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707470918; c=relaxed/simple; bh=SJsgmHQMEF61c3Zy3BCFkr1gP90wuHZ1c00xM1I9uyI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=L7uW/jVKMBfHXPq28r2C/Djm0WA3qARSssRzSmWb279HuUc9UJ3whPhphjjSQMwrwOv9pMGS6ogWsj8VoD5o4Drl4+iMNuQ53J/hOliyEoCoQTkOR14LV059e43/Saghq2hFkLDPB945xsLQUYFXYoWGBn9HUeS0fjOZOROv1Yw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707470915; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=uYyviMbv0eUdJw6mxKmK0S9+KCFReeNSBMceM/zEaRc=; b=ES99cx2nG41gCgnT/lBRIjyFoUb7W2aMkI6e42pphWKDXqHTbvdOMbiqXf1AQw5PTyKAMK w+xxc0CepaOxfj7xAQvyTAemk6DuQbG2txg8bQM2Fcop1Pn9WMYaipK6zRVaQ5VVbyZD1G IH1fms7+9C7SPkJdMqo4HmNOyHYU/Ew= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-660-dyoUeqpkMmOFAeQ_Ypt90Q-1; Fri, 09 Feb 2024 04:28:32 -0500 X-MC-Unique: dyoUeqpkMmOFAeQ_Ypt90Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D85B1C05135; Fri, 9 Feb 2024 09:28:32 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40CBBAD68; Fri, 9 Feb 2024 09:28:32 +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 4199STI0640062 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 9 Feb 2024 10:28:29 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4199SSOn640061; Fri, 9 Feb 2024 10:28:28 +0100 Date: Fri, 9 Feb 2024 10:28:28 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law , Vladimir Makarov Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] expand: Fix asm goto expansion [PR113415] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790413081104404313 X-GMAIL-MSGID: 1790413081104404313 Hi! The asm goto expansion ICEs on the following testcase (which normally is rejected later), because expand_asm_stmt emits the code to copy the large var out of the out operand to its memory location into after_rtl_seq ... after_rtl_end sequence and because it is asm goto, it duplicates the sequence on each successor edge of the asm goto. The problem is that with -mstringop-strategy=byte_loop that sequence contains loops, so CODE_LABELs, JUMP_INSNs, with other strategies could contain CALL_INSNs etc. But the copying is done using a loop doing emit_insn (copy_insn (PATTERN (curr))); which does the right thing solely for INSNs, it will do the wrong thing for JUMP_INSNs, CALL_INSNs, CODE_LABELs (with RTL checking even ICE on them), BARRIERs and the like. The following patch partially fixes it (with the hope that such stuff only occurs in asms that really can't be accepted; if one uses say "=rm" or "=g" constraint then the operand uses the memory directly and nothing is copied) by using the duplicate_insn_chain function which is used e.g. in RTL loop unrolling and which can handle JUMP_INSNs, CALL_INSNs, BARRIERs etc. As it is meant to operate on sequences inside of basic blocks, it doesn't handle CODE_LABELs (well, it skips them), so if we need a solution that will be correct at runtime here for those cases, we'd need to do further work (e.g. still use duplicate_insn_chain, but if we notice any CODE_LABELs, walk the sequence again, add copies of the CODE_LABELs and then remap references to the old CODE_LABELs in the copied sequence to the new ones). Because as is now, if the code in one of the sequence copies (where the CODE_LABELs have been left out) decides to jump to such a CODE_LABEL, it will jump to the CODE_LABEL which has been in the original sequence (which the code emits on the last edge, after all, duplicating the sequence EDGE_COUNT times and throwing away the original was wasteful, compared to doing that just EDGE_COUNT - 1 times and using the original. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or do need to handle even CODE_LABELs? 2024-02-09 Jakub Jelinek PR middle-end/113415 * cfgexpand.cc (expand_asm_stmt): For asm goto, use duplicate_insn_chain to duplicate after_rtl_seq sequence instead of hand written loop with emit_insn of copy_insn and emit original after_rtl_seq on the last edge. * gcc.target/i386/pr113415.c: New test. Jakub --- gcc/cfgexpand.cc.jj 2024-01-24 13:11:21.011469855 +0100 +++ gcc/cfgexpand.cc 2024-02-08 18:22:04.699621085 +0100 @@ -3671,16 +3671,21 @@ expand_asm_stmt (gasm *stmt) { edge e; edge_iterator ei; - + unsigned int cnt = EDGE_COUNT (gimple_bb (stmt)->succs); + FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs) { - start_sequence (); - for (rtx_insn *curr = after_rtl_seq; - curr != NULL_RTX; - curr = NEXT_INSN (curr)) - emit_insn (copy_insn (PATTERN (curr))); - rtx_insn *copy = get_insns (); - end_sequence (); + rtx_insn *copy; + if (--cnt == 0) + copy = after_rtl_seq; + else + { + start_sequence (); + duplicate_insn_chain (after_rtl_seq, after_rtl_end, + NULL, NULL); + copy = get_insns (); + end_sequence (); + } insert_insn_on_edge (copy, e); } } --- gcc/testsuite/gcc.target/i386/pr113415.c.jj 2024-02-08 18:26:27.622966847 +0100 +++ gcc/testsuite/gcc.target/i386/pr113415.c 2024-02-08 18:26:11.336193222 +0100 @@ -0,0 +1,11 @@ +/* PR middle-end/113415 */ +/* { dg-do compile } */ +/* { dg-options "-mstringop-strategy=byte_loop" } */ + +void +foo (void) +{ + unsigned long arr[64]; +lab: + __asm__ goto ("" : "=r" (arr) : : : lab); /* { dg-error "impossible constraint in 'asm'" } */ +}