From patchwork Sun Oct 29 16:40:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 159378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp1768416vqb; Sun, 29 Oct 2023 09:41:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJ6Kq6I+SlNagriJujM3RnI4FUqwsvhRC0SzZ+SHk3Fv+Dc7/WHPGqLEHbrnUR+duI1DjJ X-Received: by 2002:a05:6214:5684:b0:66d:7f65:71c9 with SMTP id qm4-20020a056214568400b0066d7f6571c9mr18493855qvb.9.1698597687907; Sun, 29 Oct 2023 09:41:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698597687; cv=pass; d=google.com; s=arc-20160816; b=NyFO+0CoUkB/MXoDBBSEjjyC02vuVl4K+pvbEVyII80/o3eH4ultVq5ADvtNhc4En5 vc35zRXyaKwKDMlw7tZru5WuyQSWoPrfqr5fQaueneDtTDduOP++G/45BkqcK/GYcT8N mvp/rOCQGvmVuzA+APW060s1Cz7WtTQ26iI/HQHxe9GJbtzFw67fHFPC8jOlK6S6GZzi 57ummSeKZnTd19mSx/ZdRPg1G04t1Q0VMl0VziQbwE2jbF64Tixw2Mudt3RjEMPJ/GdU vYragGshxN+i6ogoXb6H6mIBwsw0UR9gXQ1kvDEu/isOl1JlFmdjsg99+a+sbCykhisc umKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to: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 :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Nk+xE6Pijlh1XgPuC+am48B2OJrHyniAiqRE2k7eXyc=; fh=6xfd3IYC8Zt5CA4TsXZHhPmGMhO9cjo3oiHaQc5bSUI=; b=Dc0/OSM03q/fnGleLwOXLezIND59DigSYu6fdZB3MT6K1zNJfx8DHvx2ZK8RXvxqdI 6fXFgm1xe0U9oFJW+0xd4GWYZZUNTuDFRuqcSM3SLdEUOviKfu61gAjekwpH5SsvvtLk v+jZBCbPROTcNWzE6BVtHCdpfGOU9wPieLuc3G/B/Gmr//iaI1WDN9YntbulXmQ/OdTI tb5vBur5+MyNWv/9pA56sprAZ5flDli94dsFnVhSiyabOMhyhQRa+QC/aA6QGwf/eABO wd+TuyyGlinPG+jhhByPaOVQO1oUgJRMc22K5UU420DVieSLPGQMMDwRgK37EooIWvwo 5fGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P0OPBqKb; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w10-20020a0cdf8a000000b00656262151b7si4159376qvl.256.2023.10.29.09.41.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 09:41:27 -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=@gmail.com header.s=20230601 header.b=P0OPBqKb; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8D4E387546D for ; Sun, 29 Oct 2023 16:41:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 8A97F3857C4F for ; Sun, 29 Oct 2023 16:40:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A97F3857C4F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8A97F3857C4F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698597658; cv=none; b=OOK/p4ZFoF+S4lr6zLPz6AK/PMx5AJbLX8gP33L2yJ0vv8w9NJlfchu6j/SQ/sZhQT2b1D1uY5SmRMuhc3jmtPBB5zhLQnwxPO/4p9+OhpePC43kXNJtRtsUI83e7S42e3/ICStLd5EA4vIM8vYLF4XnHetQEgnm3SwNIc8Hbj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698597658; c=relaxed/simple; bh=0IjZA8ECwqysX5BpeogAczwcWFCoFeyQbqcfXKQMwNw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=IYk6fH77Sca40bzrKdJ7v4fwmUxVwTA779kjffZtrKexZO0jjXkgfcjKmbmWUW5An3/IelUzbx8ITWnkb7y3h2aR9tucDhcKWKQuKZstPvnU2bYQamSUZwg23rABnPJlZ4CirZAMmUnItaPsZdEuWh3TXT8pdcCdRuGk06kllXI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b77ab73c6fso2553994b3a.1 for ; Sun, 29 Oct 2023 09:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698597655; x=1699202455; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Nk+xE6Pijlh1XgPuC+am48B2OJrHyniAiqRE2k7eXyc=; b=P0OPBqKbUm7PVvQvndizTq69wp/qnr6iLtyNlxFe4GFzGao+Yev+Uhv00ZaUfc02Dz vbXkQ1CQWqq/f98AvDPDJEqS7BixQn1pUM1aFEM+8JnmYLZxCNNGi3GymrGH0vk0e9px wJnRLo7GjyLYoOcgCAqIjfxTfH7EdQcmkgQuM8AG0hkWVpqo+D0TNS7QsQWyO/g27Bjk pEb5z+pQJlYhHJykui9HC73WTsXWcAahzWp4ado6I6CmxDQxCmX54IgRUXQNIAQSGr/u RNCAD0eI8iBihhT7mv7TNe7Z8aOrN1A8/2mnJn5VzB1ymypjwYi3l3y7vCbCiHg+fOwG kL8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698597655; x=1699202455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nk+xE6Pijlh1XgPuC+am48B2OJrHyniAiqRE2k7eXyc=; b=cibvInzfxBthRwHNyYgh2ezE2cIj52mBoyay75DytIE5YuFQU4Xce7du04ydQ+nIfW tRZ8P/CuwtTfiddhepz7QDThb2vAeg9Tq/HnC/V3X3hmPrVA5jNH0BW5JmENc3RiGTvq GOHDzBoOIiWKUkT+79KoctIlEffBC1a0pBWRrHN1qDLYu12XRVnoOtokLKGcouK7FjbF VBL7V82kEXh7jmlosp4UuhiPVa3RO9ifHI5HMZo5JallV0JZfk69POROkvi9XQX50GGj 52cqGwUTI4ZPVUr2V7iA2D5qatINnsLmJIelQWHJ5Ow24H/rNfpYU0fpjK7uqn5SuF6b yDRg== X-Gm-Message-State: AOJu0YwGhXXzEkzbwNKD5sclfT9UW1TiEcOTrZOUwaQ9Z8iJ/gTdkpvk z7FPAh1yJaDuI/iB1iVKwW1IJGj7qNA= X-Received: by 2002:a05:6a20:4407:b0:17b:62ae:a8bf with SMTP id ce7-20020a056a20440700b0017b62aea8bfmr12697511pzb.30.1698597654968; Sun, 29 Oct 2023 09:40:54 -0700 (PDT) Received: from xeond2.wrightpinski.org ([98.97.118.94]) by smtp.gmail.com with ESMTPSA id w27-20020a63af1b000000b005acd5d7e11bsm3591005pge.35.2023.10.29.09.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 09:40:54 -0700 (PDT) From: Andrew Pinski To: gcc-patches@gcc.gnu.org Cc: Andrew Pinski Subject: [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd Date: Sun, 29 Oct 2023 09:40:48 -0700 Message-Id: <20231029164049.994454-3-pinskia@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231029164049.994454-1-pinskia@gmail.com> References: <20231029164049.994454-1-pinskia@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781108769266490851 X-GMAIL-MSGID: 1781108769266490851 This moves the value_replacement support for jump_function_from_stmt to match pattern. This allows us to optimize things earlier in phiopt1 rather than waiting to phiopt2. Which means phiopt1 needs to be disable for vrp03.c testcase. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd (PTR == 0 ? 0 : &PTR->field): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp03.c: Disable phiopt1. * c-c++-common/analyzer/inlining-3-multiline.c: Likewise. * c-c++-common/analyzer/inlining-3.c: Likewise. * gcc.dg/tree-ssa/phi-opt-value-3.c: New testcase. --- gcc/match.pd | 21 ++++++++++++++++++ .../analyzer/inlining-3-multiline.c | 5 ++++- .../c-c++-common/analyzer/inlining-3.c | 3 +++ .../gcc.dg/tree-ssa/phi-opt-value-3.c | 22 +++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/vrp03.c | 2 +- 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c diff --git a/gcc/match.pd b/gcc/match.pd index 22899c51a2f..9bc945ccada 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4159,6 +4159,27 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cond (eq @0 integer_zerop) @1 (op@2 @1 @0)) @2)) +/* PTR == 0 ? 0 : &PTR->field -> PTR if field offset was 0. */ +(simplify + (cond (eq @0 integer_zerop) integer_zerop ADDR_EXPR@1) + (with { + poly_int64 offset; + tree res = NULL_TREE; + tree tem = @1; + if (TREE_CODE (tem) == SSA_NAME) + if (gassign *def = dyn_cast (SSA_NAME_DEF_STMT (tem))) + if (gimple_assign_rhs_code (def) == ADDR_EXPR) + tem = gimple_assign_rhs1 (def); + + if (TREE_CODE (tem) == ADDR_EXPR) + res = get_addr_base_and_unit_offset (TREE_OPERAND (tem, 0), &offset); + } + (if (res + && TREE_CODE (res) == MEM_REF + && known_eq (mem_ref_offset (res) + offset, 0) + && operand_equal_p (TREE_OPERAND (res, 0), @0)) + (convert @0)))) + /* Simplifications of shift and rotates. */ (for rotate (lrotate rrotate) diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c index fbd20e949b6..9741b91abee 100644 --- a/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c @@ -3,6 +3,9 @@ /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */ /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ +/* Disable phi-opt1 because get_input_file_name gets optimized to just + `return inpf;`. */ +/* { dg-additional-options "-fdisable-tree-phiopt1" } */ #include "../../gcc.dg/analyzer/analyzer-decls.h" typedef __SIZE_TYPE__ size_t; @@ -96,4 +99,4 @@ test (const input_file *inpf) | (4) ...to here | (5) argument 1 ('') NULL where non-null expected | - { dg-end-multiline-output "" { target c++ } } */ \ No newline at end of file + { dg-end-multiline-output "" { target c++ } } */ diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c index 0345585bed2..2b2b4858d45 100644 --- a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c @@ -2,6 +2,9 @@ after early inlining. */ /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */ +/* Disable phi-opt1 because get_input_file_name gets optimized to just + `return inpf;`. */ +/* { dg-additional-options "-fdisable-tree-phiopt1" } */ #include "../../gcc.dg/analyzer/analyzer-decls.h" typedef __SIZE_TYPE__ size_t; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c new file mode 100644 index 00000000000..ad55bd288b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ +struct a +{ + int b[1]; +}; + +int call1(int *a); + +int f(struct a *b) +{ + int *c = b->b; + int t = call1(c); + int *d; + if (b) d = b->b; else d = 0; + int t1 = call1(d); + return t+t1; +} + +/* There should be no if statement and 2 calls to call1. */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */ +/* { dg-final { scan-tree-dump-times "call1 " 2 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c index 4cbaca41332..1adbf33cad3 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1 -fno-thread-jumps" } */ +/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1 -fno-thread-jumps -fdisable-tree-phiopt1" } */ struct A {