From patchwork Sat Dec 10 09:40:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 31997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1221519wrr; Sat, 10 Dec 2022 01:41:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4egeVqmw4TMtn/R3XGnG9FvSkaQ/QVFt9OouzFfqQi/RHEymFosmMVXCgbvDiCNObM8GZl X-Received: by 2002:a05:6402:35d1:b0:46c:fabc:5897 with SMTP id z17-20020a05640235d100b0046cfabc5897mr10314534edc.7.1670665264839; Sat, 10 Dec 2022 01:41:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670665264; cv=none; d=google.com; s=arc-20160816; b=vlft2G6D9kqghR9sbWQM85ZgvXA2SqWd8tFVaH+2X4c9pVxEOwL6jgF1eIglaNKGYP vgWLOqANWJmGACMVHgmvMMyt348H0LwuG8Bvj50m7mKgW2NEd6FQqXvQiY5ZQy6rRkWN mx3j7/EwVzGFNvAqCle6EQlh5ASk6FhGcssxzzMkLq7ib6Hs5DdN60fTNTaV/Vjvt/qo 4axfQ6xFlnUYYQtcg1Wi4rMK/dDHMe6reyneUblsFLC6X12aE01hHTLSMZOvlTxm1amI 9sBAZ4Xy+FYdwnT1LhHoVbCN6h/+2BtYCCnEqhCGEUfTRK0yExNc3mbh1MU3HzS0EUx0 89Gg== 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=VTKeHYU9xImffw5RnBOBwJVIm/kJcI70X9ARqwEsBLQ=; b=U4qMRBdOyTRJcUSPURCtzLb65By7uH1+gXtV9TiL1Pm0WuTBtiUolY2NYa9/pNCVY/ X1iK3wCFWyxD1dwBAlDpmAWSw4TvxemFHEj5HQ/SBIL1Z0R0kEo/xmW7ErzPEXEy3QUJ EQtijSYOXBMF6LBbkUz8mmUXMQ1AkZvojYkDq3SIUHxRnEWWh5uGRk96M5S1YW2zlbim SlhcUmWqwT01ttWEsETBfq/tYauPGajMjZOUkCwFo1d8D24fwrMK0atj4ECU1Gwa3g2A LSEksb8VEot8q9fqNWVHwq+an7fBAdsQF+l5aXtTpkOj5SrRNg2bM9kTx7hlB1Ih9NzB +E3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=h4DfU1ZF; 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 h11-20020a0564020e0b00b0046b0b4ee617si3347138edh.442.2022.12.10.01.41.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Dec 2022 01:41:04 -0800 (PST) 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=h4DfU1ZF; 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 A1A723852230 for ; Sat, 10 Dec 2022 09:41:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1A723852230 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670665263; bh=VTKeHYU9xImffw5RnBOBwJVIm/kJcI70X9ARqwEsBLQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=h4DfU1ZFi2K5dWsCXyd4NVz6N9T53Yl+am821kHBkIK5OPbbdSOPgmnZSaFVCQKNO WqNuor6GA4dwRBc5SzQIj+T/E7BL0qFVBrHkjqACXLFTWgHE9SsS3cyETvYgWU42sH 4mGxZdO5fbmd3iTr0R9juT6obtaWlZTvvm6zEx7U= 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 77E6938518A0 for ; Sat, 10 Dec 2022 09:40:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77E6938518A0 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-MMj-DsMtPSK6UQHfE6guwg-1; Sat, 10 Dec 2022 04:40:15 -0500 X-MC-Unique: MMj-DsMtPSK6UQHfE6guwg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A63213804072; Sat, 10 Dec 2022 09:40:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 601DDC15BA8; Sat, 10 Dec 2022 09:40:15 +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 2BA9eAj63888046 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 10 Dec 2022 10:40:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BA9e9lo3888045; Sat, 10 Dec 2022 10:40:09 +0100 Date: Sat, 10 Dec 2022 10:40:09 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] ivopts: Fix IP_END handling for asm goto [PR107997] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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 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?1751819500540539806?= X-GMAIL-MSGID: =?utf-8?q?1751819500540539806?= Hi! The following testcase ICEs, because the latch bb ends with asm goto which has both fallthrough to the header and one or more labels in the header too. In that case there is just a single edge out of the latch block, but still the asm goto is stmt_ends_bb_p statement, yet ivopts decides to emit an IV bump at the IP_END position and inserts it into the same bb as the asm goto after it, which then fails verification (control flow in the middle of bb). The following patch fixes it by splitting the latch -> header edge in that case and inserting into the newly created bb, where split_edge -> redirect_edge_and_branch is able to deal with this case correctly. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-12-10 Jakub Jelinek PR tree-optimization/107997 * tree-ssa-loop-ivopts.cc: Include cfganal.h. (create_new_iv) : If ip_end_pos bb is non-empty and ends with a stmt which ends bb, instead of adding iv update after it split the latch edge and insert iterator into the new latch bb. * gcc.c-torture/compile/pr107997.c: New test. Jakub --- gcc/tree-ssa-loop-ivopts.cc.jj 2022-12-05 11:10:37.786670489 +0100 +++ gcc/tree-ssa-loop-ivopts.cc 2022-12-09 14:42:24.722896379 +0100 @@ -131,6 +131,7 @@ along with GCC; see the file COPYING3. #include "builtins.h" #include "tree-vectorizer.h" #include "dbgcnt.h" +#include "cfganal.h" /* For lang_hooks.types.type_for_mode. */ #include "langhooks.h" @@ -7235,6 +7236,12 @@ create_new_iv (struct ivopts_data *data, case IP_END: incr_pos = gsi_last_bb (ip_end_pos (data->current_loop)); after = true; + if (!gsi_end_p (incr_pos) && stmt_ends_bb_p (gsi_stmt (incr_pos))) + { + edge e = find_edge (gsi_bb (incr_pos), data->current_loop->header); + incr_pos = gsi_after_labels (split_edge (e)); + after = false; + } break; case IP_AFTER_USE: --- gcc/testsuite/gcc.c-torture/compile/pr107997.c.jj 2022-12-09 14:45:29.458160841 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr107997.c 2022-12-09 14:45:12.290415073 +0100 @@ -0,0 +1,23 @@ +/* PR tree-optimization/107997 */ + +int a, b; +void bar (int); +int baz (void); + +void * +foo (int x, void *y) +{ + asm goto ("" : : "r" (x || !a) : : l); +l: + if (y) + return 0; + bar (b ? b : x); + while (x--) + { + if (!baz ()) + baz (); + asm goto ("" : : : : l2); + l2:; + } + return y; +}