From patchwork Sat Apr 22 22:09:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 86641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1911524vqo; Sat, 22 Apr 2023 15:11:38 -0700 (PDT) X-Google-Smtp-Source: AKy350bT9bQNpQoFag16DSfyFZK4/PRjwhbE79wHBH13aLh9r9usZgiiD1pb09Xklw5VfnYjj02x X-Received: by 2002:a17:906:cb9b:b0:953:1f45:3ced with SMTP id mf27-20020a170906cb9b00b009531f453cedmr6192576ejb.8.1682201498326; Sat, 22 Apr 2023 15:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682201498; cv=none; d=google.com; s=arc-20160816; b=04sfvijZkcnDtthcIo3qxIfupIcAAtyamxL8XfAu83Ep0cn6a1600CIJROOVKEUTb8 6Hnm8b8AHLcU4sYHiEJpO0i7L7ithqDTOP7FrtEVeFCAPb8+FvqYydcR0skXJEr4z00w VTs5V/omzo1XXCELu9uQL8ffZsAFXQMP8CI/fxuQ+tIcBv0SOfkjKSGidrxP/nqk6xk4 Inb2hUeb1OXEIaCYUqGmUwvgSjKEooATAF4yLvQH3NBHq7sN0+eso9xlKEmZVcZvTF7M 18qct/+gNpcGTalZreApRLLfSPcKYxPMiIEjh9DoED+Jyxv7vq35acbCWLHeJn/tL6DW Gyrw== 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-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=70yBC6Tngm2NSXLKMIoxaw8cEQ6mozev4dYAcDbhjWM=; b=TjvR7rcZmS8N48brUEOpA0C08UifpJwaCKAzo7xfu24F+KSKHOvKZ66+rYdVb3Vt16 NceHY/WgLGzd85eR5FF9D1hvSDIY5ieSAG0LdpPPIAt9T5Yhli/eKpi+mA6F1NG28twN UJone0ei4w336vX7UMr4IwbAwG0Ky7zVs0b/vb09scDI4HWSW+gGQYF0xKS7YkiHT1Ap yp2hrgXCk+qLWRElhojwlRrc6mRkW7b1HlCY58dQFavoQVtMUAy7INj1bVId3WMQ9/Ix hMEHGsLYXQNAbQuWc+Lqcaiw7jjQwhr3MsawBJxF/+rlw89D8i6caCF2hID87d5h+OhZ Q1fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FkDbRag+; 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 gv12-20020a170906f10c00b0094f3a2fa2cfsi5645156ejb.146.2023.04.22.15.11.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 15:11:38 -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=FkDbRag+; 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 554B63851C15 for ; Sat, 22 Apr 2023 22:10:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 554B63851C15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682201438; bh=70yBC6Tngm2NSXLKMIoxaw8cEQ6mozev4dYAcDbhjWM=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=FkDbRag+on9quk5/lb++tMyJDxr6skD2Qad8LDII4umIMkujksTeRkrLY6EGPL6NJ XJHamCMol2Gersr8+5Uz/w3PAC/I7IGQp/HHpOOEe25xxU9CcwVIDGSMCYzjmlhQa3 mEEdVVUUo+xyLj4Q5SrFunCXmsCVzVUA7pUiQvyk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 8D7C63858409 for ; Sat, 22 Apr 2023 22:09:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D7C63858409 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33MLGWqD006595 for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q4egjhp9y-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 22 Apr 2023 15:09:44 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 22 Apr 2023 15:09:32 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sat, 22 Apr 2023 15:09:32 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 0FBD03F709B; Sat, 22 Apr 2023 15:09:31 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 5/6] PHIOPT: Ignore predicates for match-and-simplify phi-opt Date: Sat, 22 Apr 2023 15:09:20 -0700 Message-ID: <20230422220921.452264-6-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230422220921.452264-1-apinski@marvell.com> References: <20230422220921.452264-1-apinski@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: miUDq592cyj5aOHxh6RxQN6-EiZT6nW3 X-Proofpoint-GUID: miUDq592cyj5aOHxh6RxQN6-EiZT6nW3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-22_15,2023-04-21_01,2023-02-09_01 X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski 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?1763916118585248123?= X-GMAIL-MSGID: =?utf-8?q?1763916118585248123?= This fixes a missed optimization where early phi-opt would not work when there was predicates. The easiest fix is to change empty_bb_or_one_feeding_into_p to ignore those statements while checking for only feeding statement. Note phi-opt-23.c and phi-opt-24.c still fail as we don't handle diamond form in match_and_simplify phiopt yet. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): Instead of calling last_and_only_stmt, look for the last statement manually. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ssa-ifcombine-13.c: Add -fno-ssa-phiopt. --- .../gcc.dg/tree-ssa/ssa-ifcombine-13.c | 4 +++- gcc/tree-ssa-phiopt.cc | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c index 425eb3d6481..7976544c79b 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c @@ -1,5 +1,7 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1" } */ +/* Disable phi-opt as it is no longer confused by predicate which had allowed ifcombine to work in the past. + Note this testcase is about ifcombine rather than phi-opt. */ +/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1 -fno-ssa-phiopt" } */ _Bool f1(_Bool a, _Bool b) { diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index cb4d8788b56..ffd6a4e6f35 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -962,9 +962,27 @@ empty_bb_or_one_feeding_into_p (basic_block bb, if (!gimple_seq_empty_p (phi_nodes (bb))) return false; - stmt_to_move = last_and_only_stmt (bb); + gimple_stmt_iterator gsi; + + gsi = gsi_start_nondebug_after_labels_bb (bb); + while (!gsi_end_p (gsi)) + { + gimple *s = gsi_stmt (gsi); + gsi_next_nondebug (&gsi); + /* Skip over Predict and nop statements. */ + if (gimple_code (s) == GIMPLE_PREDICT + || gimple_code (s) == GIMPLE_NOP) + continue; + /* If there is more one statement return false. */ + if (stmt_to_move) + return false; + stmt_to_move = s; + } + + /* The only statement here was a Predict or a nop statement + so return true. */ if (!stmt_to_move) - return false; + return true; if (gimple_vuse (stmt_to_move)) return false;