From patchwork Mon Aug 28 09:35:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Di Zhao OS X-Patchwork-Id: 137016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp3213063vqm; Mon, 28 Aug 2023 02:35:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXDinsUr3wG5pf3s3UZxJ0DPEcSiTSgA7qfp0Ax80lAyJJD6p2ShJlSKzTqS07KUGPceZ+ X-Received: by 2002:a05:6402:149a:b0:523:1e0a:e12e with SMTP id e26-20020a056402149a00b005231e0ae12emr19328637edv.23.1693215357883; Mon, 28 Aug 2023 02:35:57 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d14-20020a50fb0e000000b0052696268680si2434426edq.635.2023.08.28.02.35.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 02:35:57 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=IM+ad4Ze; arc=fail (signature failed); 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D12583858409 for ; Mon, 28 Aug 2023 09:35:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D12583858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693215356; bh=6mhF6RPTCkjRRlXzjM4D1cROKJCWY9n8lMG+D0aOj8g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IM+ad4ZeVqpDLFsd6Nj+IciqzHI5seEr3FWQzgt8zMKTc9S4dJMStK9v3NDwk6wno J9kYmeUWJIQaXGhaDU3vW8DU4+3qqh9g/2U2auqq3wX18mnNAcCy4Au4hFa9q9/PLn dWc3SRn35bMMjE4C1U5C9rYH6HpI+ryR3MTasjvU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2099.outbound.protection.outlook.com [40.107.220.99]) by sourceware.org (Postfix) with ESMTPS id 09CE63858D28 for ; Mon, 28 Aug 2023 09:35:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09CE63858D28 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJ1Tdl0Qy2oiHYZfAOG2gpWvgSuSDImYDcu0Q7zrUgZKnfDHr9wd82WrOmoIAGPO6dpCf5V6AxK+I0BrEOaUzrt7b/GDiG7xjhNQILXIWVjrAJyjoa5Sufza6d4dUO5V8usBLVROld7hnHnjM0oOno758D1J1C1s3CiIWRdEJDCY2CPKJyOTdsT2Msx3C3uudhX07wExGXOzVIPY4kV8qzjo8g5lpF0Bx/ttLtUAIjgabsFN2aKKLsaM+EVI1I6S4kFFnhvv19JRDHIMNrBPFLRRFg3178SsMnl+ASvCK9GCsXhLpsuXvO+PMnPwhje/FqqgDabYD3/7NGcksNYu9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6mhF6RPTCkjRRlXzjM4D1cROKJCWY9n8lMG+D0aOj8g=; b=eHQ71nBstLB1UIwPGSXjWWk711Yv+F+gh3f7lvm6/crUSSuvAbEh4RqBuu4DQxWEn7mK0hLfkY3wdPgQkD8iVt+f7tb2+trnKqpTW6ipiPIu0S6tv/wxZLvV+SIG/4oyJzxbSJixUJh8gp128otqJfjr/bCQGgwfGOtvf6Q5qbEfCCpEqDzb5oZ+zJhIBZVZZHoBSpLQ1B59+28RFoqvWk59oVii8enhPLsccUSpwmfWf18wcK1/x+YdKeO1CW+luJ6OvWAH+8yM1waA9jXpoDbHC6+raug621BkI9lr1yIDiasxxmdRO+pqWwE3Xs8xAOX6C3Y20biv0LwK742SZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none Received: from SN6PR01MB4240.prod.exchangelabs.com (2603:10b6:805:ae::22) by CYYPR01MB8568.prod.exchangelabs.com (2603:10b6:930:c4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.34; Mon, 28 Aug 2023 09:35:01 +0000 Received: from SN6PR01MB4240.prod.exchangelabs.com ([fe80::44ff:531:6d29:85a]) by SN6PR01MB4240.prod.exchangelabs.com ([fe80::44ff:531:6d29:85a%7]) with mapi id 15.20.6699.034; Mon, 28 Aug 2023 09:35:01 +0000 To: "gcc-patches@gcc.gnu.org" Subject: [PATCH] alias-analyis: try to find ADDR_EXPR for SSA_NAME ptr Thread-Topic: [PATCH] alias-analyis: try to find ADDR_EXPR for SSA_NAME ptr Thread-Index: AdnZkow7HMUSgOgfTrqLdpO6hWOV1w== Date: Mon, 28 Aug 2023 09:35:00 +0000 Message-ID: Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_ActionId=094bf1ab-f77d-48ee-84a4-7cf2d7c3ea1e; MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_ContentBits=0; MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_Enabled=true; MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_Method=Standard; MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_Name=Confidential (Default); MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_SetDate=2023-08-28T09:24:34Z; MSIP_Label_5b82cb1d-c2e0-4643-920a-bbe7b2d7cc47_SiteId=3bc2b170-fd94-476d-b0ce-4229bdc904a7; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SN6PR01MB4240:EE_|CYYPR01MB8568:EE_ x-ms-office365-filtering-correlation-id: d5b9e1c3-ba20-49c0-1895-08dba7aa0d18 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: IhyjlKYSHQHZT+iiRg21MWQlFPnprqsxFgFVpANj8tzyMRrJLE20oAX1+XySB1iKs1M1hszLAikmoMLwGGpZvLbBsb8YH9I5DTjLGqCWgX7JTFn3nPj/VmLqv7YPC7evci+2xkFDLmYuRnW5TDkc8pTZicgSaHOQdequQ6kbVf6QWRsTMSlq+w/4Ayut8hCqlqGROL4c4ywtzPbrrjSvOnNgj3tkbzXPc5UawEqecdFi2PrBlYTNlfmiUl6w8SrVkO3j8RGBscHD/R6ybUQagM7dFwihtYKL783oeEvuTe14znGJxgl8HyVpz7b8lgELK1dFLhlR70LJ3AOeT/aZDg6gnxnbR9tAy7CxF2mu4yDT05IU1kQPhuc2Gj9TVe98xaPAFhvGxpz6iL91jSjyUmVyItZqadwQ5s2kDfh+Q9tDV3MVNZghaoYfIK8n0aIiq/N4dz+aSyR6YL8AsrNnzABDd8E0/IlP9rr+e5zsAZai0rSsoeSZ9XuH8nlcWigETawzpPVBuweO+rI1jIDeHkdRXp+Ud9B89Z8PQF/VJzZLhi+RMR+5+fyk6MhUtHG3EXAWjB7310/x4o0kYqJa2FsENaCwl6O7YOhvJBZ9LFgkG8dizr04NLbw/cnQJp/Tet0RsXtfZWxioDxhO5MKHQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR01MB4240.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(39850400004)(396003)(376002)(346002)(136003)(451199024)(186009)(1800799009)(9686003)(6506007)(7696005)(71200400001)(26005)(478600001)(83380400001)(2906002)(64756008)(66476007)(316002)(6916009)(66446008)(66556008)(52536014)(76116006)(41300700001)(66946007)(8676002)(5660300002)(8936002)(33656002)(86362001)(55016003)(38070700005)(38100700002)(122000001)(37363002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: tIlWyCYciIgmoRkrJvMsnAkUHVL67H80QM5QQpfOu47mVOhuKI0105cKWllDGgOewMVxfgKzA98SKbOPAVvkvXsiaRku2JGkXERa1V67O+sRnGpt1CVqBTWaZ7MRsswJs19xTD5gB9ul/FHeB16Reg5Kv8rYSVu1EmH1vAQYez8Wh/4HaDxea+B7CrSReNNsVUNq06iJq84MfFVGThOUTgY1zcWIYhDsva1ZIrC77HxZBCScnINOzhEFy73acD9p7mJUfuAZAj/tlMudF57U3D8yomNQrfFmX9o08Xk+GdN+c+YmjLjmr+soaxKqPLjynj9GZyn4B+Sxc57IhZzpqAord/Gj7zi8pYqa8kOpQ7ZUYyzO4vsa3fONEwhEQrH/l0C8HzqgOale0RB63SALqB4bw5Oxpy0YpDVjvqlwx5nwq5d5PUmD93pHtng5F7ppXQOxncEC4cHg1vKg0n3Zxqf2zmdazTIndFG4xvvib3i7jT/1TaykN+wRw5ShxoPvIvqLJkRx002MLuy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ThI7TigTFKsQ== MIME-Version: 1.0 X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR01MB4240.prod.exchangelabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5b9e1c3-ba20-49c0-1895-08dba7aa0d18 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Aug 2023 09:35:00.8838 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: udijiv2chFhiTaXjV/mGP4JzoKnTrbU13PapbIvY1abISGqYunlUjAC7NAjC9naZAXCkjRlQAC7mnL4g2AQydz9guErnbjzVDMP1xa/R2E5prVQOJi2OMgU8LzubJhYM X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR01MB8568 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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: , X-Patchwork-Original-From: Di Zhao OS via Gcc-patches From: Di Zhao OS Reply-To: Di Zhao OS Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775464986836245507 X-GMAIL-MSGID: 1775464986836245507 This patch tries to improve alias-analysis between an SSA_NAME and a declaration a little. For a case like: int array1[10], array2[10]; ptr1 = array1 + x; ptr2 = ptr1 + y; , *ptr2 should not alias with array2. If we can't disambiguate from points-to information, this patch tries to find a determined ADDR_EXPR following the defining statements and then disambiguate by compare_base_decls. On spec2017 502.gcc, there are several thousands of new non-aliasing relation found. (No obvious improvements or regressions found, though.) Bootstrapped and tested on aarch64-unknown-linux-gnu. Thanks, Di Zhao gcc/ChangeLog: * tree-ssa-alias.cc (ptr_deref_may_alias_decl_p): try to find ADDR_EXPR for SSA_NAME ptrs. --- gcc/tree-ssa-alias.cc | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index cf38fe506a8..a6fe1e7b227 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -271,6 +271,38 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl) return ptr_deref_may_alias_decl_p (ptr, decl); } + if (TREE_CODE (ptr) == SSA_NAME) + { + /* First disambiguate from points-to information. */ + pi = SSA_NAME_PTR_INFO (ptr); + if (pi && !pt_solution_includes (&pi->pt, decl)) + return false; + + /* Try to find an ADDR_EXPR by walking the defining statements, so we can + probably disambiguate from compare_base_decls. */ + gimple *def_stmt; + while ((def_stmt = SSA_NAME_DEF_STMT (ptr))) + { + if (is_gimple_assign (def_stmt) + && gimple_assign_rhs_code (def_stmt) == POINTER_PLUS_EXPR) + { + ptr = gimple_assign_rhs1 (def_stmt); + if (TREE_CODE (ptr) != SSA_NAME) + break; + } + /* See if we can find a certain defining source. */ + else if (gimple_code (def_stmt) == GIMPLE_PHI + && gimple_phi_num_args (def_stmt) == 1) + { + ptr = PHI_ARG_DEF (def_stmt, 0); + if (TREE_CODE (ptr) != SSA_NAME) + break; + } + else + break; + } + } + /* ADDR_EXPR pointers either just offset another pointer or directly specify the pointed-to set. */ if (TREE_CODE (ptr) == ADDR_EXPR) @@ -279,7 +311,7 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl) if (base && (TREE_CODE (base) == MEM_REF || TREE_CODE (base) == TARGET_MEM_REF)) - ptr = TREE_OPERAND (base, 0); + return ptr_deref_may_alias_decl_p (TREE_OPERAND (base, 0), decl); else if (base && DECL_P (base)) return compare_base_decls (base, decl) != 0; @@ -294,13 +326,7 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl) if (!may_be_aliased (decl)) return false; - /* If we do not have useful points-to information for this pointer - we cannot disambiguate anything else. */ - pi = SSA_NAME_PTR_INFO (ptr); - if (!pi) - return true; - - return pt_solution_includes (&pi->pt, decl); + return true; } /* Return true if dereferenced PTR1 and PTR2 may alias.