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: 1856758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=P0OPBqKb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SJMbv2YhPz1yQ4 for ; Mon, 30 Oct 2023 03:41:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 509BD3865C25 for ; Sun, 29 Oct 2023 16:41:13 +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-Google-Smtp-Source: AGHT+IGaXaW94ZqI7Snb+Fcib+6Gz+XWrbgSPqzAb/5nMDo1Fa1R/E4hAWQluwon2qgQ/byJBRrVwA== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 {