From patchwork Fri Nov 11 13:46:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=E+uPQAZr; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N80V53yCxz23lT for ; Sat, 12 Nov 2022 00:51:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D79E3858C60 for ; Fri, 11 Nov 2022 13:51:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D79E3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668174664; bh=RqtOi7Gadx7ikaItofBYHINiwWQKpAIm9hIHZ0t1SEg=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=E+uPQAZrUt2zpyFXkD6zO7LXiwCGATUubMGrxtlj64SEMGKetm52Bd9raV0nuXYhc 2Mjq25W7omT1tN2fonMan88g46Jl1jZE4SUvzugQNPIb9qo/ldUlVIlmWDP1Hlq1ft 52elDkjdm9hDsevSOuwtI8p8br3gMOH21aSUjEe0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150058.outbound.protection.outlook.com [40.107.15.58]) by sourceware.org (Postfix) with ESMTPS id 7BB603858D1E for ; Fri, 11 Nov 2022 13:50:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BB603858D1E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=c5ilo1o9C7H/8czb8e5rB50ztR8EW+ydpaiywQgxgp6U1v2K9nryb6JHp+CECs1WYJjRz+hYmYeo5HCMAP4+lg81hTUnDGLRRPTHhNibO6BUBmHchXkY2IwDgpiezafCYsShq+kvscMFh115DnaDPZLFXZfochUtUpvu2dq1X+mP3+NVjfDSVM12kyYzGrZm3Yf28fEc1L6xq+zOsbjjTZWhlgy3ZkSQn/moOaa6UZG6IU7nzI70KriwrjGbyHNWatYT5bz4sqCD+lbRrSvg7jYkU3E1u1IkkonOpDoHWxjtGORK0O4BERouhluZlsA1NQJNLDLQjRQ1Lz/VmDBMmA== ARC-Message-Signature: i=2; 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=RqtOi7Gadx7ikaItofBYHINiwWQKpAIm9hIHZ0t1SEg=; b=j5CiTOr6s6+B++3HnI5OoV/Axrgjf3zpIQCgvtAZjr3NBQdaFpkIc+JhQRKj0fLBtec1kWmy+uOmhbh/krXNzg7RsCaHCOE7p/7j9juMKCYkHxPepr8vo+9Vm1HfdQSkkEkBaU9fdct9VTL4fcr7ayEGtXNrCkwzCD6GAy0M3gTBWZ8B37qFzLvNOIqlSzyf24S/LoZxP4mIBk4xZnsMsdqXE3nJVL29HGGNaKa/F13wHaAcqM3S3JRQUFijGkIdq8ycB38ZWSVApTmp0IU1B12NBjwPZVlLoQ63XsFXUHHNBkeiDUOK6uCQCWKoqJ7IXMYDiG+e9hfEkkIh81dFfQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB6P18901CA0012.EURP189.PROD.OUTLOOK.COM (2603:10a6:4:16::22) by AS8PR08MB10152.eurprd08.prod.outlook.com (2603:10a6:20b:63e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.28; Fri, 11 Nov 2022 13:50:37 +0000 Received: from DBAEUR03FT003.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:16:cafe::b3) by DB6P18901CA0012.outlook.office365.com (2603:10a6:4:16::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13 via Frontend Transport; Fri, 11 Nov 2022 13:50:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT003.mail.protection.outlook.com (100.127.142.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 13:50:37 +0000 Received: ("Tessian outbound aeae1c7b66fd:v130"); Fri, 11 Nov 2022 13:50:37 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6ec3167a3b9b29de X-CR-MTA-TID: 64aa7808 Received: from 12bd5c436923.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 834F99B2-A3E5-4114-9F59-DBACEBFE7043.1; Fri, 11 Nov 2022 13:50:30 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 12bd5c436923.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 13:50:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nsxwb8rzflw4w6yyc0+dDoELR6Z8tYTYTokBIwWWRTN5uHGq1+asekVmarCCOAHDCrWa+PLax16xZYps4OxpS2BgSwKWctgUwC6nh58yI2dwnvt5DqMlzErvAxzaJR0hmh6CSfMkun2elacnn/N+Lke7a24Nscr2fTQhBK7yRU40JabhyPhQrSm2zc36ZtTs6ng6yNqudWfOXX7DqqWqZOdq6vD/uLg/VdkgptjW12l5Qdu4Uqt9GYMLumgVbvxv/P9d1l02sIJHKTmogx5rj6R4hEiUyo9c8N+t1z6WaRkC/fBoYf14vxcYCNtp+o7pTtjS+Pm9Sy5jWkmZx7zgnA== 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=RqtOi7Gadx7ikaItofBYHINiwWQKpAIm9hIHZ0t1SEg=; b=VHVyQ0kd/pKhkv5o/eL9CAVOf1VmtDMJ0iBI4vkeMyZJazHCZ98SAhAGZjMZJQ5KMPrAMDraRq8rzCIL6dlLgWsT4znppplrIeOHpIJJe/alYHbMP/reopvmUMWAjXfdM8k84KjovahMgTiIAroJF3u2vqdrBPWa8qn3f2FqGpXn/IGlhV5WjG4nJSlrW220FI4+l1eH0nM6mcOY2CnueALXQqvZPLLqhGuyhUC1GUJmFFp9PCmeEcjemOamXpry+kUpevIh/V0mIa3lM453EteZA3gFC4gc9O/5K5hlcsrMnjyryDVESw7C+70YxaqfDGeoe3pTiwBftcMUZY1STQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) by AS4PR08MB7504.eurprd08.prod.outlook.com (2603:10a6:20b:4e8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 13:50:28 +0000 Received: from AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::8256:29ca:bcd8:b754]) by AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::8256:29ca:bcd8:b754%7]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 13:50:28 +0000 Date: Fri, 11 Nov 2022 13:46:25 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/8] middle-end: Remove prototype for number_of_iterations_popcount Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO2P265CA0172.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::16) To AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6678:EE_|AS4PR08MB7504:EE_|DBAEUR03FT003:EE_|AS8PR08MB10152:EE_ X-MS-Office365-Filtering-Correlation-Id: 0fb6786f-40d6-49df-feb9-08dac3ebb67d x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: dNV4xAqjQEJTR3/2vbvSHY2fPgcVrjxdr6lD9+53+k8aMWO+kOOzuet1//FoiotvhQ6ZchZJmUW/vrNOJEQQN6/1Igfgxu0dNP7E0c4bFX2b03HloRskdM3pnpR8L+CnWqqG+4iWIeiojsEAZxoqKI2GADlAkbWq4/oWqJPtPp6RTMp4rE9A6VoTasXtMjMP+0udtqtQt2yNEkMfAEbm6TlEfRe4E6XnMZ/XKqtcDP1uz6Z6nffiR185UKM3GYQjcYvVBTck4mwrjd7VWA4iJ8vV9Cy2jqp5467Hxstip8sFBPohLrenipd+at+zPqTzqI1uAyOziJTTPmcEzHNGa6N0H9yGyx4Vx+AuoXzFoq/rmoThk+O9A2TeXY2U2GkD4ytMlPksCrTOCfGNSLzDcYuK/ww0jZ5cmZhZsmIe5xzetRS20ksLjhcugIUxyCXf9iH9+zEqd8JG+kKMsKA6eHc1zvoXDBwfdUGowEiIFqusrNdECypnnZvbEBJir1ygrAxtrWnQ1H3G+CosfHjIOyAwFOK69/jVGbXpLsgAJLfiwB7QPZjjrNvDovnH3wE09yT4WN3umnTVySPZpzMlhlIyIzkqFD7nqTwn5njzlUNhhFzcJHeqjohhtY3rRD3H5hEtmwO+chuEHrVEowEATYjd0Hd0Bi/Y+4pRF0er36sdg1oHZs2tvj/GWFLoHN/V0TijBmFNXVev8xzb4n/bkw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6678.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(396003)(136003)(366004)(346002)(39860400002)(376002)(451199015)(316002)(6916009)(186003)(66556008)(66476007)(66946007)(6512007)(26005)(6666004)(6506007)(478600001)(2906002)(6486002)(86362001)(8676002)(41300700001)(30864003)(5660300002)(38100700002)(44832011)(8936002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7504 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: dc4d0428-b59e-468c-551d-08dac3ebb137 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iWdbjlggLIda4nQf+SP5CWDqIuHdIsRJiox+0mhozm3UDweG70S6pfwSNTLlOoKYyhxMaGg+Tsw9lLadb+gh+2ujpFPtjMW/iEYNYiDyuMU9SDwijqZUeQX9Ak8j1Bs0g7q5jfqYOxWUAhnoz8U0V2gt0PsS/Jr7IJVMwVlgNCQVFGmzYnzfACRlgpIt5SSrwX2gR5401OK/8sTFUxtBcqFsJlxV81FW4hld6lpJyPV1vhpLu39dqhNw/tvW4vNWA170Gd4N9ED4+xYXdHKOehRGQqQt6vVvoiYBcM78l+/hNPmP6rKn7dKJ8nwrW+nfck6T3zAIjCq2iSlUDmefbT4DxpPqrntq/JW0RQ/4eygbt6ClCe1TbK7Ot/xYvI5yIr/ytUi9wEtolEQfrINp2fVnrj/4FeSka5k4MMOSAgHw2AfMWRK/HPw+qOVuwSYZACs3YlZ7Ygg6le5WtgVYZc44s9IHx8CDIGxZMMKZJkcPI6ygukMGOn0aRSb2hfjEV4SKQ4PG1ddD3aYZRvmFGFDd/08nKtuzQChthPVPJEo7JtkiJRdRLnEq/LW7wJ5H27EWUSwWjgR7pvcTydP0jBWi9PIm6DULb0qzm3mR0MjR2eaU5Mu5/H3rkL/dWmjvlJeW9v9z9P160tSA3bCr1/mFWzEtTDv4VBW3rWU/z7Pld35IBBxWabmPp2wrWUgsPly7wbZTzOpfWGBl1PTCFwNOtn8R6qTluONzrA6IMZYn/oyK+oSqwqoZuHqhOP+A7iOLIZ49Iskg7nyg4u5sCg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(39860400002)(346002)(396003)(451199015)(46966006)(40470700004)(36840700001)(336012)(36860700001)(6512007)(44832011)(81166007)(478600001)(47076005)(6506007)(82740400003)(6916009)(83380400001)(2906002)(186003)(41300700001)(356005)(26005)(8676002)(40460700003)(316002)(40480700001)(82310400005)(30864003)(70206006)(86362001)(6666004)(8936002)(6486002)(5660300002)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 13:50:37.2787 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0fb6786f-40d6-49df-feb9-08dac3ebb67d X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10152 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * tree-ssa-loop-niter.c (ssa_defined_by_minus_one_stmt_p): Move (number_of_iterations_popcount): Move, and remove separate prototype. diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index cdbb924216243ebcabe6c695698a4aee71882c49..c23643fd9dd8b27ff11549e1f28f585534e84cd3 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -63,11 +63,6 @@ struct bounds mpz_t below, up; }; -static bool number_of_iterations_popcount (loop_p loop, edge exit, - enum tree_code code, - class tree_niter_desc *niter); - - /* Splits expression EXPR to a variable part VAR and constant OFFSET. */ static void @@ -2031,6 +2026,200 @@ number_of_iterations_cond (class loop *loop, return ret; } +/* Utility function to check if OP is defined by a stmt + that is a val - 1. */ + +static bool +ssa_defined_by_minus_one_stmt_p (tree op, tree val) +{ + gimple *stmt; + return (TREE_CODE (op) == SSA_NAME + && (stmt = SSA_NAME_DEF_STMT (op)) + && is_gimple_assign (stmt) + && (gimple_assign_rhs_code (stmt) == PLUS_EXPR) + && val == gimple_assign_rhs1 (stmt) + && integer_minus_onep (gimple_assign_rhs2 (stmt))); +} + +/* See if LOOP is a popcout implementation, determine NITER for the loop + + We match: + + goto + + + _1 = b_11 + -1 + b_6 = _1 & b_11 + + + b_11 = PHI + + exit block + if (b_11 != 0) + goto + else + goto + + OR we match copy-header version: + if (b_5 != 0) + goto + else + goto + + + b_11 = PHI + _1 = b_11 + -1 + b_6 = _1 & b_11 + + exit block + if (b_6 != 0) + goto + else + goto + + If popcount pattern, update NITER accordingly. + i.e., set NITER to __builtin_popcount (b) + return true if we did, false otherwise. + + */ + +static bool +number_of_iterations_popcount (loop_p loop, edge exit, + enum tree_code code, + class tree_niter_desc *niter) +{ + bool adjust = true; + tree iter; + HOST_WIDE_INT max; + adjust = true; + tree fn = NULL_TREE; + + /* Check loop terminating branch is like + if (b != 0). */ + gimple *stmt = last_stmt (exit->src); + if (!stmt + || gimple_code (stmt) != GIMPLE_COND + || code != NE_EXPR + || !integer_zerop (gimple_cond_rhs (stmt)) + || TREE_CODE (gimple_cond_lhs (stmt)) != SSA_NAME) + return false; + + gimple *and_stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (stmt)); + + /* Depending on copy-header is performed, feeding PHI stmts might be in + the loop header or loop latch, handle this. */ + if (gimple_code (and_stmt) == GIMPLE_PHI + && gimple_bb (and_stmt) == loop->header + && gimple_phi_num_args (and_stmt) == 2 + && (TREE_CODE (gimple_phi_arg_def (and_stmt, + loop_latch_edge (loop)->dest_idx)) + == SSA_NAME)) + { + /* SSA used in exit condition is defined by PHI stmt + b_11 = PHI + from the PHI stmt, get the and_stmt + b_6 = _1 & b_11. */ + tree t = gimple_phi_arg_def (and_stmt, loop_latch_edge (loop)->dest_idx); + and_stmt = SSA_NAME_DEF_STMT (t); + adjust = false; + } + + /* Make sure it is indeed an and stmt (b_6 = _1 & b_11). */ + if (!is_gimple_assign (and_stmt) + || gimple_assign_rhs_code (and_stmt) != BIT_AND_EXPR) + return false; + + tree b_11 = gimple_assign_rhs1 (and_stmt); + tree _1 = gimple_assign_rhs2 (and_stmt); + + /* Check that _1 is defined by _b11 + -1 (_1 = b_11 + -1). + Also make sure that b_11 is the same in and_stmt and _1 defining stmt. + Also canonicalize if _1 and _b11 are revrsed. */ + if (ssa_defined_by_minus_one_stmt_p (b_11, _1)) + std::swap (b_11, _1); + else if (ssa_defined_by_minus_one_stmt_p (_1, b_11)) + ; + else + return false; + /* Check the recurrence: + ... = PHI . */ + gimple *phi = SSA_NAME_DEF_STMT (b_11); + if (gimple_code (phi) != GIMPLE_PHI + || (gimple_bb (phi) != loop_latch_edge (loop)->dest) + || (gimple_assign_lhs (and_stmt) + != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx))) + return false; + + /* We found a match. Get the corresponding popcount builtin. */ + tree src = gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx); + if (TYPE_PRECISION (TREE_TYPE (src)) <= TYPE_PRECISION (integer_type_node)) + fn = builtin_decl_implicit (BUILT_IN_POPCOUNT); + else if (TYPE_PRECISION (TREE_TYPE (src)) + == TYPE_PRECISION (long_integer_type_node)) + fn = builtin_decl_implicit (BUILT_IN_POPCOUNTL); + else if (TYPE_PRECISION (TREE_TYPE (src)) + == TYPE_PRECISION (long_long_integer_type_node) + || (TYPE_PRECISION (TREE_TYPE (src)) + == 2 * TYPE_PRECISION (long_long_integer_type_node))) + fn = builtin_decl_implicit (BUILT_IN_POPCOUNTLL); + + if (!fn) + return false; + + /* Update NITER params accordingly */ + tree utype = unsigned_type_for (TREE_TYPE (src)); + src = fold_convert (utype, src); + if (TYPE_PRECISION (TREE_TYPE (src)) < TYPE_PRECISION (integer_type_node)) + src = fold_convert (unsigned_type_node, src); + tree call; + if (TYPE_PRECISION (TREE_TYPE (src)) + == 2 * TYPE_PRECISION (long_long_integer_type_node)) + { + int prec = TYPE_PRECISION (long_long_integer_type_node); + tree src1 = fold_convert (long_long_unsigned_type_node, + fold_build2 (RSHIFT_EXPR, TREE_TYPE (src), + unshare_expr (src), + build_int_cst (integer_type_node, + prec))); + tree src2 = fold_convert (long_long_unsigned_type_node, src); + call = build_call_expr (fn, 1, src1); + call = fold_build2 (PLUS_EXPR, TREE_TYPE (call), call, + build_call_expr (fn, 1, src2)); + call = fold_convert (utype, call); + } + else + call = fold_convert (utype, build_call_expr (fn, 1, src)); + if (adjust) + iter = fold_build2 (MINUS_EXPR, utype, call, build_int_cst (utype, 1)); + else + iter = call; + + if (TREE_CODE (call) == INTEGER_CST) + max = tree_to_uhwi (call); + else + max = TYPE_PRECISION (TREE_TYPE (src)); + if (adjust) + max = max - 1; + + niter->niter = iter; + niter->assumptions = boolean_true_node; + + if (adjust) + { + tree may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src, + build_zero_cst (TREE_TYPE (src))); + niter->may_be_zero + = simplify_using_initial_conditions (loop, may_be_zero); + } + else + niter->may_be_zero = boolean_false_node; + + niter->max = max; + niter->bound = NULL_TREE; + niter->cmp = ERROR_MARK; + return true; +} + /* Substitute NEW_TREE for OLD in EXPR and fold the result. If VALUEIZE is non-NULL then OLD and NEW_TREE are ignored and instead all SSA names are replaced with the result of calling the VALUEIZE @@ -2648,203 +2837,6 @@ number_of_iterations_exit_assumptions (class loop *loop, edge exit, return (!integer_zerop (niter->assumptions)); } - -/* Utility function to check if OP is defined by a stmt - that is a val - 1. */ - -static bool -ssa_defined_by_minus_one_stmt_p (tree op, tree val) -{ - gimple *stmt; - return (TREE_CODE (op) == SSA_NAME - && (stmt = SSA_NAME_DEF_STMT (op)) - && is_gimple_assign (stmt) - && (gimple_assign_rhs_code (stmt) == PLUS_EXPR) - && val == gimple_assign_rhs1 (stmt) - && integer_minus_onep (gimple_assign_rhs2 (stmt))); -} - - -/* See if LOOP is a popcout implementation, determine NITER for the loop - - We match: - - goto - - - _1 = b_11 + -1 - b_6 = _1 & b_11 - - - b_11 = PHI - - exit block - if (b_11 != 0) - goto - else - goto - - OR we match copy-header version: - if (b_5 != 0) - goto - else - goto - - - b_11 = PHI - _1 = b_11 + -1 - b_6 = _1 & b_11 - - exit block - if (b_6 != 0) - goto - else - goto - - If popcount pattern, update NITER accordingly. - i.e., set NITER to __builtin_popcount (b) - return true if we did, false otherwise. - - */ - -static bool -number_of_iterations_popcount (loop_p loop, edge exit, - enum tree_code code, - class tree_niter_desc *niter) -{ - bool adjust = true; - tree iter; - HOST_WIDE_INT max; - adjust = true; - tree fn = NULL_TREE; - - /* Check loop terminating branch is like - if (b != 0). */ - gimple *stmt = last_stmt (exit->src); - if (!stmt - || gimple_code (stmt) != GIMPLE_COND - || code != NE_EXPR - || !integer_zerop (gimple_cond_rhs (stmt)) - || TREE_CODE (gimple_cond_lhs (stmt)) != SSA_NAME) - return false; - - gimple *and_stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (stmt)); - - /* Depending on copy-header is performed, feeding PHI stmts might be in - the loop header or loop latch, handle this. */ - if (gimple_code (and_stmt) == GIMPLE_PHI - && gimple_bb (and_stmt) == loop->header - && gimple_phi_num_args (and_stmt) == 2 - && (TREE_CODE (gimple_phi_arg_def (and_stmt, - loop_latch_edge (loop)->dest_idx)) - == SSA_NAME)) - { - /* SSA used in exit condition is defined by PHI stmt - b_11 = PHI - from the PHI stmt, get the and_stmt - b_6 = _1 & b_11. */ - tree t = gimple_phi_arg_def (and_stmt, loop_latch_edge (loop)->dest_idx); - and_stmt = SSA_NAME_DEF_STMT (t); - adjust = false; - } - - /* Make sure it is indeed an and stmt (b_6 = _1 & b_11). */ - if (!is_gimple_assign (and_stmt) - || gimple_assign_rhs_code (and_stmt) != BIT_AND_EXPR) - return false; - - tree b_11 = gimple_assign_rhs1 (and_stmt); - tree _1 = gimple_assign_rhs2 (and_stmt); - - /* Check that _1 is defined by _b11 + -1 (_1 = b_11 + -1). - Also make sure that b_11 is the same in and_stmt and _1 defining stmt. - Also canonicalize if _1 and _b11 are revrsed. */ - if (ssa_defined_by_minus_one_stmt_p (b_11, _1)) - std::swap (b_11, _1); - else if (ssa_defined_by_minus_one_stmt_p (_1, b_11)) - ; - else - return false; - /* Check the recurrence: - ... = PHI . */ - gimple *phi = SSA_NAME_DEF_STMT (b_11); - if (gimple_code (phi) != GIMPLE_PHI - || (gimple_bb (phi) != loop_latch_edge (loop)->dest) - || (gimple_assign_lhs (and_stmt) - != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx))) - return false; - - /* We found a match. Get the corresponding popcount builtin. */ - tree src = gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx); - if (TYPE_PRECISION (TREE_TYPE (src)) <= TYPE_PRECISION (integer_type_node)) - fn = builtin_decl_implicit (BUILT_IN_POPCOUNT); - else if (TYPE_PRECISION (TREE_TYPE (src)) - == TYPE_PRECISION (long_integer_type_node)) - fn = builtin_decl_implicit (BUILT_IN_POPCOUNTL); - else if (TYPE_PRECISION (TREE_TYPE (src)) - == TYPE_PRECISION (long_long_integer_type_node) - || (TYPE_PRECISION (TREE_TYPE (src)) - == 2 * TYPE_PRECISION (long_long_integer_type_node))) - fn = builtin_decl_implicit (BUILT_IN_POPCOUNTLL); - - if (!fn) - return false; - - /* Update NITER params accordingly */ - tree utype = unsigned_type_for (TREE_TYPE (src)); - src = fold_convert (utype, src); - if (TYPE_PRECISION (TREE_TYPE (src)) < TYPE_PRECISION (integer_type_node)) - src = fold_convert (unsigned_type_node, src); - tree call; - if (TYPE_PRECISION (TREE_TYPE (src)) - == 2 * TYPE_PRECISION (long_long_integer_type_node)) - { - int prec = TYPE_PRECISION (long_long_integer_type_node); - tree src1 = fold_convert (long_long_unsigned_type_node, - fold_build2 (RSHIFT_EXPR, TREE_TYPE (src), - unshare_expr (src), - build_int_cst (integer_type_node, - prec))); - tree src2 = fold_convert (long_long_unsigned_type_node, src); - call = build_call_expr (fn, 1, src1); - call = fold_build2 (PLUS_EXPR, TREE_TYPE (call), call, - build_call_expr (fn, 1, src2)); - call = fold_convert (utype, call); - } - else - call = fold_convert (utype, build_call_expr (fn, 1, src)); - if (adjust) - iter = fold_build2 (MINUS_EXPR, utype, call, build_int_cst (utype, 1)); - else - iter = call; - - if (TREE_CODE (call) == INTEGER_CST) - max = tree_to_uhwi (call); - else - max = TYPE_PRECISION (TREE_TYPE (src)); - if (adjust) - max = max - 1; - - niter->niter = iter; - niter->assumptions = boolean_true_node; - - if (adjust) - { - tree may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src, - build_zero_cst (TREE_TYPE (src))); - niter->may_be_zero - = simplify_using_initial_conditions (loop, may_be_zero); - } - else - niter->may_be_zero = boolean_false_node; - - niter->max = max; - niter->bound = NULL_TREE; - niter->cmp = ERROR_MARK; - return true; -} - - /* Like number_of_iterations_exit_assumptions, but return TRUE only if the niter information holds unconditionally. */ From patchwork Fri Nov 11 13:52:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702696 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=QddV0xSN; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N80fZ4RL9z20KC for ; Sat, 12 Nov 2022 00:58:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B9203858C36 for ; Fri, 11 Nov 2022 13:58:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B9203858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668175108; bh=GpoXgxFfjoaRAHB+7M637qxyQz9D0KN9c/lXMn2unCc=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QddV0xSNUE3/m/aHdaRyl2O+J4k0nym1nKpm5QMlF4hnJjfihGSIidDhzFw3n196+ 7snUeDpDgRKjxGWjCwqVz2XSBEjso7tdh3c7ctyRKp716OwVl/w3LRUjcIDThiIkp2 AxuaoRtyck2VW47xG9/a/wM4c1zEGtyArJ3UpGAM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70048.outbound.protection.outlook.com [40.107.7.48]) by sourceware.org (Postfix) with ESMTPS id 6DD063858D20 for ; Fri, 11 Nov 2022 13:57:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6DD063858D20 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=T6FAusD7oBxnI3wY66uLflGnJAzUJiiwHH7hvcX8VjZvmQoya2jTPzOLEHu7njVgQmwbvSJPVUJ/6Cxu7GC1McrQSBduvEC/Id2QSD2AoTCQla2gJ+yfRpgZCBs1xBo03sECiEGtLXmVRZX+fL+6tvtuoFBjEVcqYl+jeSia6yu7nzg3KSIdE2OdPFRVM8nSmCPltagDFjsNKhDgkZGxfiwYXUrZHfdfRGerelpvWvVa7cAdZEoZP1unigTDct7Cb1qda74l1FFP10qGjoIDEV822p0xnXvYudaVDBy9veCv2UlWHdf9zwXG8s5DmOEQWnCRn5Smb+WTvtw8Tkj2Bw== ARC-Message-Signature: i=2; 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=GpoXgxFfjoaRAHB+7M637qxyQz9D0KN9c/lXMn2unCc=; b=VXIU607ieeEq/R9r1d9N8qTZhc1qlbyMWU5hUTnSBqpc9JbXL/pde2eNWfz/qGvZere8QvG783pgbYVSKm4gne8EiFs9nwm/EvcT5e+gv+lSqAOxrZxGmrcwZGiIJc/oRfPCTNt+pu8hzHNyjJQAshzq7ujfafV+WpZgVLUVbrAzxAqvcySBDa+ProGHLjcjSvMKvhiG9V9CXzs3NT1VrSQ/VfFkFlohbCpyufAQbFvjhwoDWYRHL8471L7DXeRR/EiM2ItB01pB7HR34yolhYNjbP3ktP27ChFMIZlKfWxWgPmUZignuEn1UH2UfaeTFaR6HzkvKijdJhXF8vCzsw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB8PR06CA0039.eurprd06.prod.outlook.com (2603:10a6:10:120::13) by GV1PR08MB8260.eurprd08.prod.outlook.com (2603:10a6:150:a1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.11; Fri, 11 Nov 2022 13:56:54 +0000 Received: from DBAEUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:120:cafe::b0) by DB8PR06CA0039.outlook.office365.com (2603:10a6:10:120::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Fri, 11 Nov 2022 13:56:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT027.mail.protection.outlook.com (100.127.142.237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 13:56:54 +0000 Received: ("Tessian outbound 0800d254cb3b:v130"); Fri, 11 Nov 2022 13:56:54 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: da308a74766085d0 X-CR-MTA-TID: 64aa7808 Received: from d180db94546b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C46E1B44-E4DE-4D69-95BB-D1048975A3AE.1; Fri, 11 Nov 2022 13:56:47 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d180db94546b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 13:56:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NYP+mpTcaUtWcFSJeZYJZxUNXdAkvX0fTVrn5+x6ywspRJkYifzbgzzgqQYb7I3dCkfWnQLXRoUeZzHnfeVoV877WikBEMg7H+yhzuLIdUNho75Lrgcx1kgdsPQakbW6D+uXnaB/yA+gG6I/+8TjVwp/WYe8P2Mf1mzmCqYLejZ1265BjFpDe/kmm33ka2XR8nApMdgH9d6KdqYmJFwTx9nuEMZIuJKnADNceZiox6jszIBBCWsztFfQFqWbgRnUQLEQvmfvYU43Bctfpc5TSwKs3R23nQIR7d2gArUPSGlAwUq4N3Oq+47cluW48SJHQmrSQ2EQl9jQpzcpKC8Gtw== 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=GpoXgxFfjoaRAHB+7M637qxyQz9D0KN9c/lXMn2unCc=; b=AqYrSr/Xyq6jEEJ9sSfPVsi1qqam4maKifnOnGyrtWFvW0NWE6SN/6BgvIqJSxZ71XuZThACTpDjWNnz6oc2v2v4NlqOF/8dJ245+VV1P8cNiYlrfMf63oiP5+8jXMXrH2/Z7B84qQjp+9q9P9QYhSyTtoXt4d7x7SYTV/TYKs3qOvUQIiJ/zNNSuFD3L9eoXr5j0Q+CwHIg8TDFboUEsTvKFSBefco3sw0Mcls5RA1WxtM9f809qGvo9F9sphVWbzZlS85OTJMsItnV70heIPnh7DSImKorE5YIWUjn3yv9rW+7hQlObSmHuU4b2Qq2ySgrZro4FqvzEwpT+fUZDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) by DBBPR08MB6106.eurprd08.prod.outlook.com (2603:10a6:10:202::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 13:56:44 +0000 Received: from AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::8256:29ca:bcd8:b754]) by AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::8256:29ca:bcd8:b754%7]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 13:56:44 +0000 Date: Fri, 11 Nov 2022 13:52:40 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/8] middle-end: Refactor number_of_iterations_popcount Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO6P123CA0002.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:338::6) To AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6678:EE_|DBBPR08MB6106:EE_|DBAEUR03FT027:EE_|GV1PR08MB8260:EE_ X-MS-Office365-Filtering-Correlation-Id: c31ad061-c98d-4d7a-8dc9-08dac3ec9717 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Fii8/UVOKgBmc48Hu8tqiYE0J2Uxt5ci3V+TTet6KlJ3x3nEJTguKAx9hU7CXhFjlPoUNNJ3+avPefvqj5TWicLR81IMAWwOz2Y9jBh4Wa6dqi2IGd2A0nW7MkBSQi0kPmKTIvlwrZKXeraP3mJ2sTEMskZT1QrHvoS5h4+NNJH4SJe8oGc05/dofvUPBSvT6EDhAzCrDvAf+nQXTJogGgzMJO3DIyApfWzbuynxy0qKCW0NB5Gm3dIViY5wh6TuWWaU/43Sk5Z+UzMJIxkZRsGANO3f98ULpg1XaP5F3SBe7JqawEEZ6m/xWPlO5mvHxJrYLt6QNhxauN1b2p1Kq1tYA1bCqIpiiA30moQVQ4WlSo4x/7JJCBLmQPZfwR9y8GeB9k0k+IlVnwGig7YjJyl3xW8gjMs9QqHQmxdKPKEzCaiM/MRXhPywNpMgxKuK8JH7j+LNZ5tP0fJ98TvPDPDDPwfHlUV2WEQ3uPhtA5PyfAkz5S5Ut78I9mTHGY+CTdSE7gFuqA6RdUoUpzuSclSj5QodF+Z/OdVhleNEPdATlN4oKtrAPudaF9wQSasru0pZJMUaMxJdZujyPkttAkINz4GoPvJ1BtF6v8y4WuUsRJrvA5SoWsnr3wHI0xX2OI1dwfN5j1bO/CHVf4U9UQ6gQrcd0tjMtCgDqn7hDKfFDV4f6BixwsvP35VBIh937fPPTrRlpT1htzNWCu4ePkBzuj4vyuPL8gufns7k7fY= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6678.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(346002)(396003)(366004)(376002)(136003)(451199015)(8936002)(5660300002)(83380400001)(41300700001)(26005)(66946007)(66476007)(8676002)(316002)(6512007)(6916009)(66556008)(6506007)(86362001)(2906002)(44832011)(30864003)(186003)(38100700002)(84970400001)(6486002)(6666004)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB6106 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d8175f79-60f0-4e86-1b4e-08dac3ec9057 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LIp0iC/onMBEhqaP636z5kdXHPnUOV3JnaIWHQobCZU+sLbutO0rgrLYkRm6QaubSmej/fUHnXAz7siFy363jesD70p/XnR8aAgo+DOkOnlw2SrEREG2xTHgwTp+88FGA8ERcC8g/Zr8FtDguY1wKXVcRtsopNopphT6+OdimyrBzLU4nroECy+Z+4t4SJdGvQ/PbeGbatoNqGh6txnAxYcnxsxGa88n8zuQA2BEcrDP2PU+JLCKL1278Cl2to1H8ICY+bEFyKEo1AVwMIXMgYsGi1w3FhYKpNW7VdBT4+D0M3R3IHWjw3UjDgZR2cQmMYAhX9YZim2YIemmECZGPo7Va6jpjBhzbSH5MDHIQQp4HXSOepDgKac7IJVu/a/8DS0YU28yaYJ20MXy2kJ/Fb3KylaA+hHAerv5fuDlXhY/vg2CQeOM5QEmFE68JPMfIr8CG7mq5LJ64cLv0HJC1y9EGDGubq9R8KG5viuOePXMbge3zp5BzBx29FyeF2oFwGAGPEPh+HSHOpQ5TaQn7pea+3UpyvYTsplGiZjmjsV5hUGdBSpjDtCd8IsDUyOOmtmkng4jG//C4UbcakdUyW7Xkv4WL5k5HRXvLuv7Y+EMFfb2lqmEBc/XByIKXVGPvYESWkYjgboBbgYzbktOd4r4rIvb4UYv8MD7/Gjk9TKu1a+O6VFg6B8cttBPhu9euKb+pfZrsfR7SaLLefdGz7M0lX8iBVy3lZ67708WDZ+tSIEFm5qxK1QIWFOD9pSRSL51dhR9WOsVSk3iMDyDQfqPiCmeli7LTuejecq5yIU= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(396003)(376002)(346002)(136003)(451199015)(40470700004)(46966006)(36840700001)(8936002)(44832011)(6916009)(186003)(30864003)(40460700003)(6506007)(47076005)(5660300002)(316002)(41300700001)(2906002)(70586007)(6512007)(83380400001)(70206006)(26005)(6666004)(8676002)(336012)(81166007)(6486002)(478600001)(356005)(82310400005)(40480700001)(84970400001)(36860700001)(86362001)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 13:56:54.0947 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c31ad061-c98d-4d7a-8dc9-08dac3ec9717 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT027.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB8260 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This includes various changes to improve clarity, and to enable the code to be more similar to the clz and ctz idiom recognition added in subsequent patches. We create new number_of_iterations_bitcount function, which will be used to call the other bit-counting recognition functions added in subsequent patches, as well as a generic comment describing the loop structures that are common to each idiom. Some of the variables in number_of_iterations_popcount are given more descriptive names, and the popcount expression builder is extracted into a separate function. As part of the refactoring, we also fix a bug where the max loop count for modes shorter than an integer would be incorrectly computed as if the input mode were actually an integer. We also ensure that niter->max takes into account the final value for niter->niter (after any folding and simplifying), since if the latter is a constant, then record_estimate mandates that the two values are equivalent. gcc/ChangeLog: * tree-ssa-loop-niter.cc (number_of_iterations_exit_assumptions): Modify to call... (number_of_iterations_bitcount): ...this new function. (number_of_iterations_popcount): Now called by the above. Refactor, and extract popcount expression builder to... (build_popcount_expr): this new function. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/popcount-max.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount-max.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount-max.c new file mode 100644 index 0000000000000000000000000000000000000000..ca7204cbc3cea636183408e24d7dd36d702ffdb2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount-max.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-loop-optimize -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int count1 (unsigned char b) { + int c = 0; + + while (b) { + b &= b - 1; + c++; + } + if (c <= PREC) + return 0; + else + return 34567; +} + +int count2 (unsigned char b) { + int c = 0; + + while (b) { + b &= b - 1; + c++; + } + if (c <= PREC - 1) + return 0; + else + return 76543; +} + +/* { dg-final { scan-tree-dump-times "34567" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "76543" 1 "optimized" } } */ diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 0af34e46580bb9a6f9b40e09c9f29b8454a4aaf6..fece876099c1687569d6351e7d2416ea6acae5b5 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2026,6 +2026,48 @@ number_of_iterations_cond (class loop *loop, return ret; } +/* Return an expression that computes the popcount of src. */ + +static tree +build_popcount_expr (tree src) +{ + tree fn; + int prec = TYPE_PRECISION (TREE_TYPE (src)); + int i_prec = TYPE_PRECISION (integer_type_node); + int li_prec = TYPE_PRECISION (long_integer_type_node); + int lli_prec = TYPE_PRECISION (long_long_integer_type_node); + if (prec <= i_prec) + fn = builtin_decl_implicit (BUILT_IN_POPCOUNT); + else if (prec == li_prec) + fn = builtin_decl_implicit (BUILT_IN_POPCOUNTL); + else if (prec == lli_prec || prec == 2 * lli_prec) + fn = builtin_decl_implicit (BUILT_IN_POPCOUNTLL); + else + return NULL_TREE; + + tree utype = unsigned_type_for (TREE_TYPE (src)); + src = fold_convert (utype, src); + if (prec < i_prec) + src = fold_convert (unsigned_type_node, src); + tree call; + if (prec == 2 * lli_prec) + { + tree src1 = fold_convert (long_long_unsigned_type_node, + fold_build2 (RSHIFT_EXPR, TREE_TYPE (src), + unshare_expr (src), + build_int_cst (integer_type_node, + lli_prec))); + tree src2 = fold_convert (long_long_unsigned_type_node, src); + tree call1 = build_call_expr (fn, 1, src1); + tree call2 = build_call_expr (fn, 1, src2); + call = fold_build2 (PLUS_EXPR, integer_type_node, call1, call2); + } + else + call = build_call_expr (fn, 1, src); + + return call; +} + /* Utility function to check if OP is defined by a stmt that is a val - 1. */ @@ -2041,45 +2083,18 @@ ssa_defined_by_minus_one_stmt_p (tree op, tree val) && integer_minus_onep (gimple_assign_rhs2 (stmt))); } -/* See if LOOP is a popcout implementation, determine NITER for the loop +/* See comment below for number_of_iterations_bitcount. + For popcount, we have: - We match: - - goto + modify: + _1 = iv_1 + -1 + iv_2 = iv_1 & _1 - - _1 = b_11 + -1 - b_6 = _1 & b_11 - - - b_11 = PHI + test: + if (iv != 0) - exit block - if (b_11 != 0) - goto - else - goto - - OR we match copy-header version: - if (b_5 != 0) - goto - else - goto - - - b_11 = PHI - _1 = b_11 + -1 - b_6 = _1 & b_11 - - exit block - if (b_6 != 0) - goto - else - goto - - If popcount pattern, update NITER accordingly. - i.e., set NITER to __builtin_popcount (b) - return true if we did, false otherwise. + modification count: + popcount (src) */ @@ -2088,138 +2103,150 @@ number_of_iterations_popcount (loop_p loop, edge exit, enum tree_code code, class tree_niter_desc *niter) { - bool adjust = true; - tree iter; + bool modify_before_test = true; HOST_WIDE_INT max; - adjust = true; - tree fn = NULL_TREE; - - /* Check loop terminating branch is like - if (b != 0). */ - gimple *stmt = last_stmt (exit->src); - if (!stmt - || gimple_code (stmt) != GIMPLE_COND + + /* Check that condition for staying inside the loop is like + if (iv != 0). */ + gimple *cond_stmt = last_stmt (exit->src); + if (!cond_stmt + || gimple_code (cond_stmt) != GIMPLE_COND || code != NE_EXPR - || !integer_zerop (gimple_cond_rhs (stmt)) - || TREE_CODE (gimple_cond_lhs (stmt)) != SSA_NAME) + || !integer_zerop (gimple_cond_rhs (cond_stmt)) + || TREE_CODE (gimple_cond_lhs (cond_stmt)) != SSA_NAME) return false; - gimple *and_stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (stmt)); + tree iv_2 = gimple_cond_lhs (cond_stmt); + gimple *iv_2_stmt = SSA_NAME_DEF_STMT (iv_2); - /* Depending on copy-header is performed, feeding PHI stmts might be in - the loop header or loop latch, handle this. */ - if (gimple_code (and_stmt) == GIMPLE_PHI - && gimple_bb (and_stmt) == loop->header - && gimple_phi_num_args (and_stmt) == 2 - && (TREE_CODE (gimple_phi_arg_def (and_stmt, + /* If the test comes before the iv modification, then these will actually be + iv_1 and a phi node. */ + if (gimple_code (iv_2_stmt) == GIMPLE_PHI + && gimple_bb (iv_2_stmt) == loop->header + && gimple_phi_num_args (iv_2_stmt) == 2 + && (TREE_CODE (gimple_phi_arg_def (iv_2_stmt, loop_latch_edge (loop)->dest_idx)) == SSA_NAME)) { - /* SSA used in exit condition is defined by PHI stmt - b_11 = PHI - from the PHI stmt, get the and_stmt - b_6 = _1 & b_11. */ - tree t = gimple_phi_arg_def (and_stmt, loop_latch_edge (loop)->dest_idx); - and_stmt = SSA_NAME_DEF_STMT (t); - adjust = false; + /* iv_2 is actually one of the inputs to the phi. */ + iv_2 = gimple_phi_arg_def (iv_2_stmt, loop_latch_edge (loop)->dest_idx); + iv_2_stmt = SSA_NAME_DEF_STMT (iv_2); + modify_before_test = false; } - /* Make sure it is indeed an and stmt (b_6 = _1 & b_11). */ - if (!is_gimple_assign (and_stmt) - || gimple_assign_rhs_code (and_stmt) != BIT_AND_EXPR) + /* Make sure iv_2_stmt is an and stmt (iv_2 = _1 & iv_1). */ + if (!is_gimple_assign (iv_2_stmt) + || gimple_assign_rhs_code (iv_2_stmt) != BIT_AND_EXPR) return false; - tree b_11 = gimple_assign_rhs1 (and_stmt); - tree _1 = gimple_assign_rhs2 (and_stmt); + tree iv_1 = gimple_assign_rhs1 (iv_2_stmt); + tree _1 = gimple_assign_rhs2 (iv_2_stmt); - /* Check that _1 is defined by _b11 + -1 (_1 = b_11 + -1). - Also make sure that b_11 is the same in and_stmt and _1 defining stmt. + /* Check that _1 is defined by (_1 = iv_1 + -1). + Also make sure that _1 is the same in and_stmt and _1 defining stmt. Also canonicalize if _1 and _b11 are revrsed. */ - if (ssa_defined_by_minus_one_stmt_p (b_11, _1)) - std::swap (b_11, _1); - else if (ssa_defined_by_minus_one_stmt_p (_1, b_11)) + if (ssa_defined_by_minus_one_stmt_p (iv_1, _1)) + std::swap (iv_1, _1); + else if (ssa_defined_by_minus_one_stmt_p (_1, iv_1)) ; else return false; - /* Check the recurrence: - ... = PHI . */ - gimple *phi = SSA_NAME_DEF_STMT (b_11); + + /* Check the recurrence. */ + gimple *phi = SSA_NAME_DEF_STMT (iv_1); if (gimple_code (phi) != GIMPLE_PHI || (gimple_bb (phi) != loop_latch_edge (loop)->dest) - || (gimple_assign_lhs (and_stmt) - != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx))) + || (iv_2 != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx))) return false; - /* We found a match. Get the corresponding popcount builtin. */ + /* We found a match. */ tree src = gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx); - if (TYPE_PRECISION (TREE_TYPE (src)) <= TYPE_PRECISION (integer_type_node)) - fn = builtin_decl_implicit (BUILT_IN_POPCOUNT); - else if (TYPE_PRECISION (TREE_TYPE (src)) - == TYPE_PRECISION (long_integer_type_node)) - fn = builtin_decl_implicit (BUILT_IN_POPCOUNTL); - else if (TYPE_PRECISION (TREE_TYPE (src)) - == TYPE_PRECISION (long_long_integer_type_node) - || (TYPE_PRECISION (TREE_TYPE (src)) - == 2 * TYPE_PRECISION (long_long_integer_type_node))) - fn = builtin_decl_implicit (BUILT_IN_POPCOUNTLL); + int src_precision = TYPE_PRECISION (TREE_TYPE (src)); - if (!fn) + /* Get the corresponding popcount builtin. */ + tree expr = build_popcount_expr (src); + + if (!expr) return false; - /* Update NITER params accordingly */ - tree utype = unsigned_type_for (TREE_TYPE (src)); - src = fold_convert (utype, src); - if (TYPE_PRECISION (TREE_TYPE (src)) < TYPE_PRECISION (integer_type_node)) - src = fold_convert (unsigned_type_node, src); - tree call; - if (TYPE_PRECISION (TREE_TYPE (src)) - == 2 * TYPE_PRECISION (long_long_integer_type_node)) + max = src_precision; + + tree may_be_zero = boolean_false_node; + + if (modify_before_test) { - int prec = TYPE_PRECISION (long_long_integer_type_node); - tree src1 = fold_convert (long_long_unsigned_type_node, - fold_build2 (RSHIFT_EXPR, TREE_TYPE (src), - unshare_expr (src), - build_int_cst (integer_type_node, - prec))); - tree src2 = fold_convert (long_long_unsigned_type_node, src); - call = build_call_expr (fn, 1, src1); - call = fold_build2 (PLUS_EXPR, TREE_TYPE (call), call, - build_call_expr (fn, 1, src2)); - call = fold_convert (utype, call); + expr = fold_build2 (MINUS_EXPR, integer_type_node, expr, + integer_one_node); + max = max - 1; + may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src, + build_zero_cst (TREE_TYPE (src))); } - else - call = fold_convert (utype, build_call_expr (fn, 1, src)); - if (adjust) - iter = fold_build2 (MINUS_EXPR, utype, call, build_int_cst (utype, 1)); - else - iter = call; - if (TREE_CODE (call) == INTEGER_CST) - max = tree_to_uhwi (call); - else - max = TYPE_PRECISION (TREE_TYPE (src)); - if (adjust) - max = max - 1; + expr = fold_convert (unsigned_type_node, expr); - niter->niter = iter; niter->assumptions = boolean_true_node; + niter->may_be_zero = simplify_using_initial_conditions (loop, may_be_zero); + niter->niter = simplify_using_initial_conditions(loop, expr); - if (adjust) - { - tree may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src, - build_zero_cst (TREE_TYPE (src))); - niter->may_be_zero - = simplify_using_initial_conditions (loop, may_be_zero); - } + if (TREE_CODE (niter->niter) == INTEGER_CST) + niter->max = tree_to_uhwi (niter->niter); else - niter->may_be_zero = boolean_false_node; + niter->max = max; - niter->max = max; niter->bound = NULL_TREE; niter->cmp = ERROR_MARK; return true; } +/* See if LOOP contains a bit counting idiom. The idiom consists of two parts: + 1. A modification to the induction variabler;. + 2. A test to determine whether or not to exit the loop. + + These can come in either order - i.e.: + + + iv_1 = PHI + if (test (iv_1)) + goto + else + goto + + + iv_2 = modify (iv_1) + goto + + OR + + + iv_1 = PHI + iv_2 = modify (iv_1) + + + if (test (iv_2)) + goto + else + goto + + The second form can be generated by copying the loop header out of the loop. + + In the first case, the number of latch executions will be equal to the + number of induction variable modifications required before the test fails. + + In the second case (modify_before_test), if we assume that the number of + modifications required before the test fails is nonzero, then the number of + latch executions will be one less than this number. + + If we recognise the pattern, then we update niter accordingly, and return + true. */ + +static bool +number_of_iterations_bitcount (loop_p loop, edge exit, + enum tree_code code, + class tree_niter_desc *niter) +{ + return number_of_iterations_popcount (loop, exit, code, niter); +} + /* Substitute NEW_TREE for OLD in EXPR and fold the result. If VALUEIZE is non-NULL then OLD and NEW_TREE are ignored and instead all SSA names are replaced with the result of calling the VALUEIZE @@ -2758,7 +2785,7 @@ number_of_iterations_exit_assumptions (class loop *loop, edge exit, tree iv0_niters = NULL_TREE; if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt), op0, &iv0, safe ? &iv0_niters : NULL, false)) - return number_of_iterations_popcount (loop, exit, code, niter); + return number_of_iterations_bitcount (loop, exit, code, niter); tree iv1_niters = NULL_TREE; if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt), op1, &iv1, safe ? &iv1_niters : NULL, false)) From patchwork Fri Nov 11 18:43:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tr23hPXQ; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N874M38dMz23lT for ; Sat, 12 Nov 2022 05:47:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F389F385840C for ; Fri, 11 Nov 2022 18:47:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F389F385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668192461; bh=YAwbpvjW87sJ8EyZ/o7MWu8cEcmCpGmPUH6K2oyaR3s=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=tr23hPXQRXC+6M7QTVQlxJDYHIRcsbYWY+F3zl0feuHJ929AUprSBW95UUXiUXcn3 8/GseNt9oOzfJFVTsaPXwdOpAXuEIKwPi6CUuXxi4j9MVIeg10tcs1JOVUmj3dZfCr Pc7DzxVQEtu7TyZWLN+bJQg+bTslzo1e+YkGnlQI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130059.outbound.protection.outlook.com [40.107.13.59]) by sourceware.org (Postfix) with ESMTPS id 37DED3858CDA for ; Fri, 11 Nov 2022 18:47:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 37DED3858CDA ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Omm1LdUUN7CqwwymNskZEg92NTNFTZLpsr10lyqKRvfVAOdJqvAn988sdbwIzTO5ic+OXs104WibwH5Ldoc9trFpiLQndJkpJkKHzxQ9Tq6KYZNdGf0GojX7jhT3lVuluGqfqbtagzPir1JMDP8ntBpvBakFd1WDAKkmOG3BFiUW9jEQg8FUClJngw0otsGJjnhyIotgjMISCQ7A0O1olbglt5V33zMJtmkPD+rR45GGsLcafz5NPLq4dY+fJ26CY6o8sgBTwFlswhYRF5Nx2UEtJHMTPQN6cx5IJxp5eG9340D8REYOf1/MGkAtMHe7d5/8kmsXoxX2D+gVeaAmew== ARC-Message-Signature: i=2; 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=YAwbpvjW87sJ8EyZ/o7MWu8cEcmCpGmPUH6K2oyaR3s=; b=j/p+vTE3FNoF/YGFaZesEC/tuPSYWN2QC6+d/43A3X3bO/RyE92E8FFxTnJBpzkQ12YvMzJN7+XPM+ow01/yf7hOmB2jcxHhK8S/VVI5qnfw3wzewfiO3DdbhYlR0TG4rYVxglY+4VWGiBBmkhZCa8KSoCltsWSLtwI2w7oBzMrlsLAYSW3ual2udjEYe7jzLkMO6PUIE5hp7C45jLLMhhpSByteFUDurGA75T/9HgCzz5EExEKCNiESq0W3iJOvZ9zru3rF/ao2P/65FBeaZQyLZUpDN8naCy6A3J2S2xL9NKZcSicVL48hwaJItR8m+gul0J3qQ32NwrCC8OB5VQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DU2PR04CA0191.eurprd04.prod.outlook.com (2603:10a6:10:28d::16) by GVXPR08MB8234.eurprd08.prod.outlook.com (2603:10a6:150:17::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 18:47:16 +0000 Received: from DBAEUR03FT056.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28d:cafe::ad) by DU2PR04CA0191.outlook.office365.com (2603:10a6:10:28d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 18:47:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT056.mail.protection.outlook.com (100.127.142.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 18:47:16 +0000 Received: ("Tessian outbound aeae1c7b66fd:v130"); Fri, 11 Nov 2022 18:47:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e653bd8eac3c551b X-CR-MTA-TID: 64aa7808 Received: from 9ed865d1f907.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3549BABA-1B68-4816-893E-9C59834CDC6B.1; Fri, 11 Nov 2022 18:47:08 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9ed865d1f907.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 18:47:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kPnBQvD4LgtXAyCK4Bc/UCgGXXoyLi3n0QEN+0s6zs9rHlPLOYFbDck2ZO6oj5pUQ03zDgxzhhnFiw/2wC0McsyLwP/zBsO5winOOkEFQWhcVwR4AugPH4o/KWuBPNT6AzHOcr70neYxyKzqFbtEHUr5gTEEpIsadncF3MSAZ0sv+4XNVyGLfAMAoaK0iqN56E9PQsYcVtzp8f14rjcmFmGIZfIQVEWEfLjtHtyLtaY69/rcPgHit5si0dxpLJm26ACVgHnTTEE9pz8Q+GxO6SmKQ07YsEg+44KSd6vRdiy+QfNShLguRESzpIYNTvgQ51GZibi1cSkRk1OHVLnhOw== 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=YAwbpvjW87sJ8EyZ/o7MWu8cEcmCpGmPUH6K2oyaR3s=; b=i4afNATRAwHZlrSTQvpLi40EniNMQVC1Y58rVOrMGXsAFlqBN4eqRm7OxCGfVz7MAq4UrvCodt95t3fTPO0awCyiXRMdQHHpkzTcClTYyVg5qexrLsgYpK+1hLtWUKcn1wSHSZI4ahsGbJtnv4ZdwMLMO+wqb5KHaaCdBiBvKNyjRh7cZj88k78cOQ9PaKjpZ4vD6woTu/aSr9wIz4xUk3qcZRwDs+K1g6xJaAILy9ak1YxuNYqV9WkopSlDGFjWtfMDyUjgv4fRPxQmI1vesr6fX0LX7EVWXaXlxGdm3hePucLTlJ/AVKKRlbEb4vD3HjV3ij0QKChLig2Vsg7GDA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) by DB9PR08MB7511.eurprd08.prod.outlook.com (2603:10a6:10:302::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12; Fri, 11 Nov 2022 18:47:06 +0000 Received: from PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701]) by PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 18:47:06 +0000 Date: Fri, 11 Nov 2022 18:43:05 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 4/8] Modify test, to prevent the next patch breaking it Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO4P123CA0046.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:152::15) To PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAXPR08MB6686:EE_|DB9PR08MB7511:EE_|DBAEUR03FT056:EE_|GVXPR08MB8234:EE_ X-MS-Office365-Filtering-Correlation-Id: e87a7734-daa4-4e57-75cc-08dac4152780 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: vYzhfhOgNf54gtEsgEiAUxlc59+lkd8EAV0jjGlbCEAZeQxKospPmPH9gKe0f3ODTQrY/lF1i8o+VlGA7BEX289CZjQxAE3i2IvG0Pkix47gbpbcfvfiMvPAbRbGvLyxznpo4wiJ/NSxoL9G8pUwwaAUgHpfdWYAD7kY9LVPvV7mSJ9QKHwDQFHjLsbmY9bq7T1sP2wl01w9KOZUuXlp53n6zFhHghfWtECN+7G3h/Zs45prVHIWITuhIpr5qinaV8D/LqZ5ys39SagbM2sFY+feV/HireF1N03QwbPdfAW9H97T9nH98pZ5WGb1JBVbwcl8mIjFZ31N5ydw3vbrUrYmAzyDSscF6t5vdpD32IWzlVZfZNL+PN58v8KnRddRsa2P5g8FD8iHYzIQoRectLik5Nn/gS6pbJC9nyAz0aIDC5k6C+B39bAM1NAl5bqJhAkJw4j7w4r0uqLDq6Aq9ZFwPrKNxZTkviflfcDaXhW6MqsSz2ja4ao5NxJ90Rn/9BxIq+cNSjewfArTVTWbwALCvVJ/SQnO7pEPdubNL7a1zp5BvczJiGC/210e6wdJ+g3D5ne1jYxCED35FB5vC3ABoEmcwL7bflCA/a0LzuNvxGtv33+bc/TadSjBbnhCU8UNAGbuAXS93fpcPaH3xM0lhHvxs6V5Nn/w4czyTd8nCu0jMhXlaCHLIrjKGtF71ueiKwUcE1dx9DYpDBk5psnd4skchKblnFXh4e8Aamc= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB6686.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(396003)(346002)(376002)(39860400002)(136003)(451199015)(66476007)(66946007)(66556008)(6916009)(84970400001)(8676002)(186003)(316002)(478600001)(2906002)(44832011)(8936002)(41300700001)(5660300002)(6486002)(86362001)(26005)(6512007)(6506007)(83380400001)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB7511 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: deddd64e-75fd-4847-fae8-08dac4152193 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2Um25vd5oqk7n4eE2X2RjQUpWd2dvwsYXwezKcmTuTHIug6crR4igBo6ZOWLb7SCkIZ3UdIjDfHYRpHNjLNv/tY8LorLVMeSwJMAybLvCWpnvY40Kzo0/MbZUGDyc2IXwhuq8Ojlgv70x/PtiHe+xiZncEff5l7AtSIZtN6Llqcr4HXRyqaTrfY1RMYWlLJGq4K5ca481DpWiF8reJm+JZfny54EiKQ3zCSZ0wq95X+fLk4Fg7Y80e0FMVEk/vKGkurPlsfmxQH5UjXbQpVe0fUmj//G+97WwRZNp6UVnIiHC2FoO9h/chcT0FadLBUjBiqr445gWDi7JUGvnukcPZpvaeigncjQyaAv26b0ZnHPkftbCj1inb/ExogXva8tfIIncpF4vAAOEcCQV52uSNDgHd81TvMk1G1gq+d9z5p0b039vDIPI/EfoskXSad1H2p2xeqYqlwL2eEv41uv2/6/r0Rz7OjaPirGtX/atLNZ8xqa3DXNYL++Cm2JsHa8nSWBobyvCKeHgUgnpa0HU1po8nVofkcIRn64Lnvb6h6dEixbNfKyAnbV3YARpVfEE4+e0np4T1E4pXCD5nI+HJ8ETEP6If/nh5/hamC/ZV54Oz4HIlZ4/NurKbJBkLZzuSKieS9mlngpJ/CULMH84eKTetxHolUje3fCRF9V7z831/mtCMISPC0xXTUdV9qTQ5A0Ih6WH8QJKRR5afR6I/dWUwMr0zruYYRwaifdxCEZYl/1e80a0+mkgWX8RGZBlE2w/VrypmPaVciAFxkv/OKDw1lC2Z++P/8bw/arcB0= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(346002)(136003)(376002)(396003)(451199015)(46966006)(36840700001)(40470700004)(44832011)(356005)(8936002)(8676002)(70206006)(70586007)(84970400001)(41300700001)(5660300002)(316002)(40460700003)(82740400003)(36860700001)(2906002)(26005)(86362001)(40480700001)(81166007)(6486002)(6512007)(6506007)(83380400001)(478600001)(82310400005)(47076005)(6916009)(186003)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 18:47:16.2433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e87a7734-daa4-4e57-75cc-08dac4152780 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT056.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR08MB8234 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The upcoming c[lt]z idiom recognition patch eliminates the need for a brute force computation of the iteration count of these loops. The test is intended to verify that ivcanon can determine the loop count when the condition is given by a chain of constant computations. We replace the constant operations with a more complicated chain that should resist future idiom recognition. gcc/testsuite/ChangeLog: * gcc.dg/pr77975.c: Make tests more robust. diff --git a/gcc/testsuite/gcc.dg/pr77975.c b/gcc/testsuite/gcc.dg/pr77975.c index 148cebdded964da7fce148abdf2a430c55650513..a187ce2b50c2821841e71b5b6cb243a37a66fb57 100644 --- a/gcc/testsuite/gcc.dg/pr77975.c +++ b/gcc/testsuite/gcc.dg/pr77975.c @@ -7,10 +7,11 @@ unsigned int foo (unsigned int *b) { - unsigned int a = 3; + unsigned int a = 8; while (a) { - a >>= 1; + a += 5; + a &= 44; *b += a; } return a; @@ -21,10 +22,11 @@ foo (unsigned int *b) unsigned int bar (unsigned int *b) { - unsigned int a = 7; + unsigned int a = 3; while (a) { - a >>= 1; + a += 5; + a &= 44; *b += a; } return a; From patchwork Fri Nov 11 18:50:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ATYhEm8V; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N87BR4rZ0z23lq for ; Sat, 12 Nov 2022 05:53:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D62E33839C5A for ; Fri, 11 Nov 2022 18:52:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D62E33839C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668192774; bh=5lHc1j/m/cNgoh1jXOVIkMk1fiMZn5ulABWhAbgRTus=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ATYhEm8VBQmjTnO4EvehMqTiWMOe2eLS+B45l+7s6HMW2B0HDI9GO+SxHWA5oqWrx jJVrbBdKEXMNBPkkeJP7/pPAi+Wgu7AapvQ2VKIBmplN4eZLpJ36ipTiU+uEEKESHl O7SgWJNBkrbzy07R51WwlTN3Dc9zK85SNbkNBWQc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2082.outbound.protection.outlook.com [40.107.21.82]) by sourceware.org (Postfix) with ESMTPS id 54B343858C2B for ; Fri, 11 Nov 2022 18:52:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 54B343858C2B ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=BL6VQtaRhuLiInHJfHMQOON/AaEdus/s9w7cXNUOx/1vtMDLR7Y2v+gk74xEpFua61HJU/KlcIfpJa8M3ti1ei2d+CqCam3Hvq/HjlxUuuF9b5RF+VPZPMN200m/gpZMyvQuBNyOR22ZmNmhbRMf4L/Xm5qeC9ijarHfJ9JBza/6FkUR3xaldGvOLkj8PNjlejdxWSORGWiRJ0ASCrAvUaSWSEFKxy4LNQRFJpsuygsTfKOCouw5wEsgnx9OTAi5Oo4+/UGX+0lcdNSyou69FtzHS1HKCeyKGD8b38MSlY9g4hak1DWmxmguiTHKSvNyNidFHDhLZfGmUdbVNf2Cnw== ARC-Message-Signature: i=2; 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=5lHc1j/m/cNgoh1jXOVIkMk1fiMZn5ulABWhAbgRTus=; b=C4z/jTGL3BUEWFKalHQlG0fqMpt7xV27SMProkoqHDXNcQwqe7zePaqRfSt6TMuUdLxSO2kZFKl+3XSpIvhBsScImL2qsFlYmNJEiWEBWlKoDpBjyW0TzmNFBeUdebRh6uL8W7rWPJDxs5+40CitViOwZ3HRYOJZPY/kOa4h6UXi9a7k9YMLQOaVKC4+k6VNfGqQYfQVTjE3FvlEYmNerCFLFvDNT+xmt07ozvzRsthWjUN8g8ka1/bHjWE/JC7MLcOafFSuznbwa4wTq+2IkWMqO0YovCyNLUjgtaAZYTVDFVoZBjVTZDqFwTano5TKBpoNiAHIBi9tK338J0uThw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AS9PR07CA0010.eurprd07.prod.outlook.com (2603:10a6:20b:46c::32) by AS2PR08MB10083.eurprd08.prod.outlook.com (2603:10a6:20b:647::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 18:52:24 +0000 Received: from AM7EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46c:cafe::df) by AS9PR07CA0010.outlook.office365.com (2603:10a6:20b:46c::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.15 via Frontend Transport; Fri, 11 Nov 2022 18:52:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT031.mail.protection.outlook.com (100.127.140.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 18:52:24 +0000 Received: ("Tessian outbound f394866f3f2b:v130"); Fri, 11 Nov 2022 18:52:24 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 28f3ed8f92b646f9 X-CR-MTA-TID: 64aa7808 Received: from ba9e08d33d68.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 935EF38C-63E2-4771-AA9A-497F5612BE61.1; Fri, 11 Nov 2022 18:52:17 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ba9e08d33d68.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 18:52:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kBoPzKlsphhZJZOvh4iNuFCu3GOFLadhYB8x7rpN/kJgW4TFfqgHCEUVigFS0nku1P9VwRBAsWSgk7FjoJAC1L6MPEBJg93iKDlByhf5pB4cgWZTNpqKDRH0bbSHN+1KKPi/Ev3hGHnb7YgHIKFfSm0oD3vjVMg3rQHXmi9543r+weG/gMcJy7CtsNeeFVdiJSp4S6gO57Ma8om8PfeBB+7ZE4NVjdNG4EaUzgPD0wZEQr+h8Gt/E67iEeQaL7w9gRv4XQgWTfGorAFtOMTRJ6BeZ/X5Lbow7IfbgBt1PR4puAJDCNGWr5b6GIyQQhjGMExkyWeDcjPQRa8p2DX8Xw== 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=5lHc1j/m/cNgoh1jXOVIkMk1fiMZn5ulABWhAbgRTus=; b=cXn8eFowk3J0tgGLi1RdSFbXR3roUMKwnlJf3VEkcJpVho2Ar7bdx8qIwDerdmNkomOUAyz1cB8YGUN7THckYGEPqrexc/sKOa8RIYWPCNQ1L7uu7sZjN1y1yWHso07D8fnS0V15WIqW7kfWih2kuLFyHXgEbv15zb7bde6V+RY5lAe2q7pIhZQlK50A5C1xwwiDYqDXLWItVQ4yIGw/Bmzl22BvwlgGX9fTruOumQeywW4+0fEPBYE4nYidesZeMyEfpwL4reiztLrWKPZgJ5kaUC8lKPAK9n9VaZwGK22Ih/G9+zX305xhZ1XZgv/JDFwfMJc4lsht4QD10ckPXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) by AS8PR08MB7790.eurprd08.prod.outlook.com (2603:10a6:20b:527::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12; Fri, 11 Nov 2022 18:52:14 +0000 Received: from PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701]) by PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 18:52:14 +0000 Date: Fri, 11 Nov 2022 18:50:12 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 5/8] middle-end: Add cltz_complement idiom recognition Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LNXP265CA0070.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::34) To PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAXPR08MB6686:EE_|AS8PR08MB7790:EE_|AM7EUR03FT031:EE_|AS2PR08MB10083:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e28c3ec-a588-4066-5db7-08dac415df7b x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: k/mSE8JWpMDG92H4u6gDes/o7UsWbWnuEOY06/Xw23Po3dSOvbwq7RUcrGwbfm29NRSi/joo5Yfk7QtYvlwGp/e3+bxMF/hOghS6AyJzeVpCE6B0m8swW+A/4qyhKdiDzTuo9p7adOx3quI8Gp+zvRs+IT6WCRFo+tF3rHtuwhzBPeKhgwQNvirzZ2ZH2U6sUR978k/EfWlXP0LfJrAyCXrwLsDiQoEODzpykJfmFuupABn+3lxqHEbxIyUDSx351jDPBXo0eq3+WcjntdGSAwtC+dI33C02L7dn4cdKjun3wm01iZo8oevlBJ2gnWfBqgWNEfJcoFLX0SYEIne3m8wztMbcst5FBVSmQ9oZF8gC9GJrvzIhFIpnc7jIYNjHGpI3fAUX1iN6RM1y8Z6yiZlvobo6KKwjec32wiGnVGWi14PWIfL47Lwl+Ltp5qI9LzcuDPNjfGvMP48TcbceR0vD9AkX0/DBfgdz8jbBEC88rgAZd6SNyulea80rgNMJzqmcjLpZaNZ9+dZSKS3iRidXX4h8YIkJeTu/ADB5s/CjQ7s1ePAvgUJi6++13ZGJ2w9SI8UOQHDTdcWT0jgFghUmh/RYlIffhmo9ksvaCg3o9risxtcjMCAQNCqiKE/3xC5RTDAPtV+70hni16PtTCkXjWH04sYfrGbZDQqtP9u/ox7RsjoUiZ+jga8GfQgd0LSKemxRrKFkqk2JqF+5OrjUrwnoYJ/UUrMUGDDe/bW0ur6iEi8YVwenHniTHqmbbpx2an6/+Vh2seC+e4RgqA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB6686.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(396003)(39860400002)(346002)(366004)(451199015)(8936002)(84970400001)(6916009)(30864003)(316002)(44832011)(41300700001)(478600001)(83380400001)(5660300002)(6486002)(66476007)(66946007)(8676002)(2906002)(66556008)(6512007)(86362001)(26005)(186003)(6506007)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7790 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 07bcd8fd-5215-47aa-7ac8-08dac415d930 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vAr6JU4bCs1/cvZlZCoqyhY9TiZpeQlpRTaC39XduJhd5+789cFz7YeICBhafh63VtQMDPYa9Nf+H16Ox3yT0OCe4V8Zukox65tVpJWVJw7ZqeHcvqoS3hHbQFVxTfDoxnc8wwYu+zIireYG14g2liBTXADRoR5GrhgIsm54svTI//Fmq6HKircFdcWwxQWa0Olpgcy2qIbT5UytKWov9prCijRAjHc6mG4ryK3WV72KiFYe+lBic8KK/ugMc+cUi/Z99N42Ze/yrYLpLfSbjwUeRW/yRZv32X1xN97h+vAsQAU5pVHBjtygWqDlB49iVad5ch5folM8OD6GWLAr8HO4KmgOGn4LI80QG9HbDtBzqpJNJap7rHOIB+Ju4xvveYPVOr4hqkMFtgfPyAao0RYQCpeUo2dDyOD+Q1I3VwbFAEV16O+c+PExROt7THcYfIeAkI6Usm2+NLCQ3U83QGqtbsUW7lUEDtbShrD+0dwxg30vb88o6vNK2QmV9yPXDWHkSl1MKGTJZmlaBn+9e7B1QlY5uGMk1L9shiglLyOiQHdlsU25203kD1bAPo4R6NcktbSA0Zlagt2aFExyoMLiwhOrbMqcIxWsfwTK0tcxdj7wScaFD4czHvUGxZ86r8KqlKo/uezzMmb84pHDMhlWDNekJotZ+SHdp+NU11KQQ8Xko4hqzGqiwYYc9WE2vs/4liYEZ9w4nNMscKAq0c9h7YHO2RTBXN5NpuBp6Y/5jfPckXZoJINsUt6jbNxRD8od7+gq8XKJ4JnvRxzJVE1gQCebjExS8I6qWyHYSPkVl1x7EjIXNTdDZxNv+fF1gvEP1Ux1ANUEjWGLS4o7/Q== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(396003)(346002)(376002)(136003)(451199015)(40470700004)(46966006)(36840700001)(82740400003)(40480700001)(40460700003)(86362001)(6916009)(316002)(70586007)(81166007)(70206006)(6486002)(356005)(30864003)(5660300002)(44832011)(83380400001)(8676002)(41300700001)(47076005)(2906002)(8936002)(478600001)(6512007)(6506007)(26005)(36860700001)(186003)(82310400005)(336012)(84970400001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 18:52:24.8326 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e28c3ec-a588-4066-5db7-08dac415df7b X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10083 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This recognises patterns of the form: while (n) { n >>= 1 } This patch results in improved (but still suboptimal) codegen: foo (unsigned int b) { int c = 0; while (b) { b >>= 1; c++; } return c; } foo: .LFB11: .cfi_startproc cbz w0, .L3 clz w1, w0 tst x0, 1 mov w0, 32 sub w0, w0, w1 csel w0, w0, wzr, ne ret The conditional is unnecessary. phiopt could recognise a redundant csel (using cond_removal_in_builtin_zero_pattern) when one of the inputs is a clz call, but it cannot recognise the redunancy when the input is (e.g.) (32 - clz). I could perhaps extend this function to recognise this pattern in a later patch, if this is a good place to recognise more patterns. gcc/ChangeLog: * tree-scalar-evolution.cc (expression_expensive_p): Add checks for c[lt]z optabs. * tree-ssa-loop-niter.cc (build_cltz_expr): New. (number_of_iterations_cltz_complement): New. (number_of_iterations_bitcount): Add call to the above. gcc/testsuite/ChangeLog: * lib/target-supports.exp (check_effective_target_clz) (check_effective_target_clzl, check_effective_target_clzll) (check_effective_target_ctz, check_effective_target_clzl) (check_effective_target_ctzll): New. * gcc.dg/tree-ssa/cltz-complement-max.c: New test. * gcc.dg/tree-ssa/clz-complement-char.c: New test. * gcc.dg/tree-ssa/clz-complement-int.c: New test. * gcc.dg/tree-ssa/clz-complement-long-long.c: New test. * gcc.dg/tree-ssa/clz-complement-long.c: New test. * gcc.dg/tree-ssa/ctz-complement-char.c: New test. * gcc.dg/tree-ssa/ctz-complement-int.c: New test. * gcc.dg/tree-ssa/ctz-complement-long-long.c: New test. * gcc.dg/tree-ssa/ctz-complement-long.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cltz-complement-max.c b/gcc/testsuite/gcc.dg/tree-ssa/cltz-complement-max.c new file mode 100644 index 0000000000000000000000000000000000000000..1a29ca52e42e50822e4e3213b2cb008b766d0318 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cltz-complement-max.c @@ -0,0 +1,60 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-loop-optimize -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int clz_complement_count1 (unsigned char b) { + int c = 0; + + while (b) { + b >>= 1; + c++; + } + if (c <= PREC) + return 0; + else + return 34567; +} + +int clz_complement_count2 (unsigned char b) { + int c = 0; + + while (b) { + b >>= 1; + c++; + } + if (c <= PREC - 1) + return 0; + else + return 76543; +} + +int ctz_complement_count1 (unsigned char b) { + int c = 0; + + while (b) { + b <<= 1; + c++; + } + if (c <= PREC) + return 0; + else + return 23456; +} + +int ctz_complement_count2 (unsigned char b) { + int c = 0; + + while (b) { + b <<= 1; + c++; + } + if (c <= PREC - 1) + return 0; + else + return 65432; +} +/* { dg-final { scan-tree-dump-times "34567" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "76543" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "23456" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "65432" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-char.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-char.c new file mode 100644 index 0000000000000000000000000000000000000000..2ebe8fabcaf0ce88f3a6a46e9ba4ba79b7d3672e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-char.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clz } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned char b) { + int c = 0; + + while (b) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(5) != 3) + __builtin_abort (); + if (foo(255) != 8) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-int.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-int.c new file mode 100644 index 0000000000000000000000000000000000000000..f2c5c23f6a7d84ecb637c6961698b0fc30d7426b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-int.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clz } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_INT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned int b) { + int c = 0; + + while (b) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(5) != 3) + __builtin_abort (); + if (foo(1 << (PREC - 1)) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-long-long.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-long-long.c new file mode 100644 index 0000000000000000000000000000000000000000..7f7793f0efac1f0d793e6e99b84988e5cc5221c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-long-long.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clzll } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long long b) { + int c = 0; + + while (b) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(5) != 3) + __builtin_abort (); + if (foo(1LL << (PREC - 1)) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-long.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-long.c new file mode 100644 index 0000000000000000000000000000000000000000..97161bb7a74260bea20e325ebab64acb33a2b696 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-complement-long.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clzl } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long b) { + int c = 0; + + while (b) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(5) != 3) + __builtin_abort (); + if (foo(1L << (PREC - 1)) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c new file mode 100644 index 0000000000000000000000000000000000000000..b9afe8852d8ffbc7ee9a0760cf04b8f98af293a2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-char.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctz } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned char b) { + int c = 0; + + while (b) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(96) != PREC - 5) + __builtin_abort (); + if (foo(35) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c new file mode 100644 index 0000000000000000000000000000000000000000..d2702a65daf34db66550d2255395db68a29a4797 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-int.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctz } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_INT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned int b) { + int c = 0; + + while (b) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(96) != PREC - 5) + __builtin_abort (); + if (foo(35) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c new file mode 100644 index 0000000000000000000000000000000000000000..1ea0d5d7d9f8be1824c4177c33edd91e66b4ddab --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long-long.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctzll } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long long b) { + int c = 0; + + while (b) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(96) != PREC - 5) + __builtin_abort (); + if (foo(35) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c new file mode 100644 index 0000000000000000000000000000000000000000..80fb02dcfa68bc022ae69b26fb189323e01fc6fc --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-complement-long.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctzl } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long b) { + int c = 0; + + while (b) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != 0) + __builtin_abort (); + if (foo(96) != PREC - 5) + __builtin_abort (); + if (foo(35) != PREC) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index c7f583d6d1498401a7c106ed3f539dcd04f95451..325f12d62324793d6b2cf55b074ef6cc9cf4dd4d 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -8687,6 +8687,72 @@ proc check_effective_target_popcount { } { } "" ] } +# Return 1 if the target supports clz on int. + +proc check_effective_target_clz { } { + return [check_no_messages_and_pattern clz "!\\(call" rtl-expand { + int foo (int b) + { + return __builtin_clz (b); + } + } "" ] +} + +# Return 1 if the target supports clz on long. + +proc check_effective_target_clzl { } { + return [check_no_messages_and_pattern clzl "!\\(call" rtl-expand { + int foo (long b) + { + return __builtin_clzl (b); + } + } "" ] +} + +# Return 1 if the target supports clz on long long. + +proc check_effective_target_clzll { } { + return [check_no_messages_and_pattern clzll "!\\(call" rtl-expand { + int foo (long long b) + { + return __builtin_clzll (b); + } + } "" ] +} + +# Return 1 if the target supports ctz on int. + +proc check_effective_target_ctz { } { + return [check_no_messages_and_pattern ctz "!\\(call" rtl-expand { + int foo (int b) + { + return __builtin_ctz (b); + } + } "" ] +} + +# Return 1 if the target supports ctz on long. + +proc check_effective_target_ctzl { } { + return [check_no_messages_and_pattern ctzl "!\\(call" rtl-expand { + int foo (long b) + { + return __builtin_ctzl (b); + } + } "" ] +} + +# Return 1 if the target supports ctz on long long. + +proc check_effective_target_ctzll { } { + return [check_no_messages_and_pattern ctzll "!\\(call" rtl-expand { + int foo (long long b) + { + return __builtin_ctzll (b); + } + } "" ] +} + # Return 1 if the target supports atomic operations on "long long" # and can execute them. # diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 7e2a3e986619de87e4ae9daf16198be1f13b917c..1ac9526c69b5fe80c26022f2fa1176d222e2dfb9 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3406,12 +3406,21 @@ expression_expensive_p (tree expr, hash_map &cache, library call for popcount when backend does not have an instruction to do so. We consider this to be expensive and generate __builtin_popcount only when backend defines it. */ + optab optab; combined_fn cfn = get_call_combined_fn (expr); switch (cfn) { CASE_CFN_POPCOUNT: + optab = popcount_optab; + goto bitcount_call; + CASE_CFN_CLZ: + optab = clz_optab; + goto bitcount_call; + CASE_CFN_CTZ: + optab = ctz_optab; +bitcount_call: /* Check if opcode for popcount is available in the mode required. */ - if (optab_handler (popcount_optab, + if (optab_handler (optab, TYPE_MODE (TREE_TYPE (CALL_EXPR_ARG (expr, 0)))) == CODE_FOR_nothing) { @@ -3424,7 +3433,7 @@ expression_expensive_p (tree expr, hash_map &cache, instructions. */ if (is_a (mode, &int_mode) && GET_MODE_SIZE (int_mode) == 2 * UNITS_PER_WORD - && (optab_handler (popcount_optab, word_mode) + && (optab_handler (optab, word_mode) != CODE_FOR_nothing)) break; return true; diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index fece876099c1687569d6351e7d2416ea6acae5b5..16e8e25919d808cea27adbd72f0be01ae2f0e547 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2198,6 +2198,195 @@ number_of_iterations_popcount (loop_p loop, edge exit, return true; } +/* Return an expression that counts the leading/trailing zeroes of src. */ + +static tree +build_cltz_expr (tree src, bool leading, bool defined_at_zero) +{ + tree fn; + int prec = TYPE_PRECISION (TREE_TYPE (src)); + int i_prec = TYPE_PRECISION (integer_type_node); + int li_prec = TYPE_PRECISION (long_integer_type_node); + int lli_prec = TYPE_PRECISION (long_long_integer_type_node); + if (prec <= i_prec) + fn = leading ? builtin_decl_implicit (BUILT_IN_CLZ) + : builtin_decl_implicit (BUILT_IN_CTZ); + else if (prec == li_prec) + fn = leading ? builtin_decl_implicit (BUILT_IN_CLZL) + : builtin_decl_implicit (BUILT_IN_CTZL); + else if (prec == lli_prec || prec == 2 * lli_prec) + fn = leading ? builtin_decl_implicit (BUILT_IN_CLZLL) + : builtin_decl_implicit (BUILT_IN_CTZLL); + else + return NULL_TREE; + + tree utype = unsigned_type_for (TREE_TYPE (src)); + src = fold_convert (utype, src); + if (prec < i_prec) + src = fold_convert (unsigned_type_node, src); + + tree call; + if (prec == 2 * lli_prec) + { + tree src1 = fold_convert (long_long_unsigned_type_node, + fold_build2 (RSHIFT_EXPR, TREE_TYPE (src), + unshare_expr (src), + build_int_cst (integer_type_node, + lli_prec))); + tree src2 = fold_convert (long_long_unsigned_type_node, src); + /* We count the zeroes in src1, and add the number in src2 when src1 + is 0. */ + if (!leading) + std::swap(src1, src2); + tree call1 = build_call_expr (fn, 1, src1); + tree call2 = build_call_expr (fn, 1, src2); + if (defined_at_zero) + { + tree is_zero2 = fold_build2 (NE_EXPR, boolean_type_node, src2, + build_zero_cst (TREE_TYPE (src2))); + call2 = fold_build3(COND_EXPR, integer_type_node, is_zero2, call2, + build_int_cst (integer_type_node, lli_prec)); + } + tree is_zero1 = fold_build2 (NE_EXPR, boolean_type_node, src1, + build_zero_cst (TREE_TYPE (src1))); + call = fold_build3(COND_EXPR, integer_type_node, is_zero1, call1, + fold_build2 (PLUS_EXPR, integer_type_node, call2, + build_int_cst (integer_type_node, + lli_prec))); + } + else + { + call = build_call_expr (fn, 1, src); + if (defined_at_zero) + { + tree is_zero = fold_build2 (NE_EXPR, boolean_type_node, src, + build_zero_cst (TREE_TYPE (src))); + call = fold_build3(COND_EXPR, integer_type_node, is_zero, call, + build_int_cst (integer_type_node, prec)); + } + } + + if (leading && prec < i_prec) + call = fold_build2(MINUS_EXPR, integer_type_node, call, + build_int_cst (integer_type_node, + i_prec - prec)); + + return call; +} + +/* See comment below for number_of_iterations_bitcount. + For c[lt]z complement, we have: + + modify: + iv_2 = iv_1 >> 1 OR iv_1 << 1 + + test: + if (iv != 0) + + modification count: + src precision - c[lt]z (src) + + */ + +static bool +number_of_iterations_cltz_complement (loop_p loop, edge exit, + enum tree_code code, + class tree_niter_desc *niter) +{ + bool modify_before_test = true; + HOST_WIDE_INT max; + + /* Check that condition for staying inside the loop is like + if (iv != 0). */ + gimple *cond_stmt = last_stmt (exit->src); + if (!cond_stmt + || gimple_code (cond_stmt) != GIMPLE_COND + || code != NE_EXPR + || !integer_zerop (gimple_cond_rhs (cond_stmt)) + || TREE_CODE (gimple_cond_lhs (cond_stmt)) != SSA_NAME) + return false; + + tree iv_2 = gimple_cond_lhs (cond_stmt); + gimple *iv_2_stmt = SSA_NAME_DEF_STMT (iv_2); + + /* If the test comes before the iv modification, then these will actually be + iv_1 and a phi node. */ + if (gimple_code (iv_2_stmt) == GIMPLE_PHI + && gimple_bb (iv_2_stmt) == loop->header + && gimple_phi_num_args (iv_2_stmt) == 2 + && (TREE_CODE (gimple_phi_arg_def (iv_2_stmt, + loop_latch_edge (loop)->dest_idx)) + == SSA_NAME)) + { + /* iv_2 is actually one of the inputs to the phi. */ + iv_2 = gimple_phi_arg_def (iv_2_stmt, loop_latch_edge (loop)->dest_idx); + iv_2_stmt = SSA_NAME_DEF_STMT (iv_2); + modify_before_test = false; + } + + /* Make sure iv_2_stmt is a logical shift by one stmt: + iv_2 = iv_1 {>>|<<} 1 */ + if (!is_gimple_assign (iv_2_stmt) + || (gimple_assign_rhs_code (iv_2_stmt) != LSHIFT_EXPR + && (gimple_assign_rhs_code (iv_2_stmt) != RSHIFT_EXPR + || !TYPE_UNSIGNED (TREE_TYPE (gimple_assign_lhs (iv_2_stmt))))) + || !integer_onep (gimple_assign_rhs2 (iv_2_stmt))) + return false; + + bool left_shift = (gimple_assign_rhs_code (iv_2_stmt) == LSHIFT_EXPR); + + tree iv_1 = gimple_assign_rhs1 (iv_2_stmt); + + /* Check the recurrence. */ + gimple *phi = SSA_NAME_DEF_STMT (iv_1); + if (gimple_code (phi) != GIMPLE_PHI + || (gimple_bb (phi) != loop_latch_edge (loop)->dest) + || (iv_2 != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx))) + return false; + + /* We found a match. */ + tree src = gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx); + int src_precision = TYPE_PRECISION (TREE_TYPE (src)); + + /* Get the corresponding c[lt]z builtin. */ + tree expr = build_cltz_expr (src, !left_shift, true); + + if (!expr) + return false; + + expr = fold_build2 (MINUS_EXPR, integer_type_node, + build_int_cst (integer_type_node, src_precision), + expr); + + max = src_precision; + + tree may_be_zero = boolean_false_node; + + if (modify_before_test) + { + expr = fold_build2 (MINUS_EXPR, integer_type_node, expr, + integer_one_node); + max = max - 1; + may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src, + build_zero_cst (TREE_TYPE (src))); + } + + expr = fold_convert (unsigned_type_node, expr); + + niter->assumptions = boolean_true_node; + niter->may_be_zero = simplify_using_initial_conditions (loop, may_be_zero); + niter->niter = simplify_using_initial_conditions (loop, expr); + + if (TREE_CODE (niter->niter) == INTEGER_CST) + niter->max = tree_to_uhwi (niter->niter); + else + niter->max = max; + + niter->bound = NULL_TREE; + niter->cmp = ERROR_MARK; + return true; +} + /* See if LOOP contains a bit counting idiom. The idiom consists of two parts: 1. A modification to the induction variabler;. 2. A test to determine whether or not to exit the loop. @@ -2244,7 +2433,8 @@ number_of_iterations_bitcount (loop_p loop, edge exit, enum tree_code code, class tree_niter_desc *niter) { - return number_of_iterations_popcount (loop, exit, code, niter); + return (number_of_iterations_popcount (loop, exit, code, niter) + || number_of_iterations_cltz_complement (loop, exit, code, niter)); } /* Substitute NEW_TREE for OLD in EXPR and fold the result. From patchwork Fri Nov 11 18:54:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LTobQvlZ; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N87K54kb8z23mY for ; Sat, 12 Nov 2022 05:58:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B27E3858D38 for ; Fri, 11 Nov 2022 18:58:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B27E3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668193126; bh=ALk/upi8XL48G69ZmhDTEUIqQVLFMtHnXGlyH22dfPE=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LTobQvlZz1hpgSOIO0J2A1MMBlnv5eadeiaARmBwy4oyRQnKpV4ZnchfJSnwXnSLs JGjvxd12WRUu95Pqre2aNIh0F947qd3Kuvcki8qxeYEzMm4smJhGKOmCuKXVPfJlY+ PuN+C36dbMplKjHaHO1XB54UMv/n2DCXGDTYZaiU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70081.outbound.protection.outlook.com [40.107.7.81]) by sourceware.org (Postfix) with ESMTPS id 6100F3858D20 for ; Fri, 11 Nov 2022 18:58:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6100F3858D20 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=SV+SeXehhee3Ar78PNTyPx4HaMQr4gkAxwHHEMN1tLj7d5xGheSc7R5eDY+FqZAuzxdsPCjTFpeyL9TsjKNUpGt3nev4vuB1OJfxl7MdO3HEc5PZHpxqpkqeXCG6FRVAP86ogBX3UIKEYDWQ4H4wH96GlARM1tr62Uc6FpVl5zGDCW9NscRYNerVSRVvDAMXHHZMlxPFlJ5vjhe+7ysQikqusmC9l2UN5omICypZIv4Y6EW+Ua2twpzgwzIR65HI0YNbg9YsBwDWiSRsZOwjfpApANiOATGMW7KzWS0bcPY+kaFlhL9Z8+99aNlFCVsdKaLfhOA9VzlOu+jALiPP8w== ARC-Message-Signature: i=2; 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=ALk/upi8XL48G69ZmhDTEUIqQVLFMtHnXGlyH22dfPE=; b=Bs0UUJiUUnRzinjrUVxzXEv9w0av4vaHYMsFsZ20DhlxIWPB0wC84zpub5M34lFvdTcLcsluOIBWM4xRNGg3iUNQc0QxuAUCLyZl970QlXbqEh83qfv+HsS6A7NXgnjb4MPm5UzwWqPTLwapFalLV7ZEA9smNITTwIW84XRwC6Sn/2iXW3w1+25Rl1gVEtx1sLR2USOxBXyI3U2qH6zbdUX0Gi4iWzJnUTshBz+4sg1EpY37ceB8vlQt5bQ7YU4L4MC30+0KRx2z9Kg5umn7m7VkD9JxHQuMdgkIcriQd1CI8RK+IR7QALSoWSrSNZKuJie3sv6GgXllVn1Ppkx3jw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB9PR06CA0015.eurprd06.prod.outlook.com (2603:10a6:10:1db::20) by DB9PR08MB8577.eurprd08.prod.outlook.com (2603:10a6:10:3d6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.11; Fri, 11 Nov 2022 18:58:21 +0000 Received: from DBAEUR03FT034.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1db:cafe::b0) by DB9PR06CA0015.outlook.office365.com (2603:10a6:10:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.14 via Frontend Transport; Fri, 11 Nov 2022 18:58:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT034.mail.protection.outlook.com (100.127.142.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 18:58:21 +0000 Received: ("Tessian outbound 58faf9791229:v130"); Fri, 11 Nov 2022 18:58:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a81871a1489b4bee X-CR-MTA-TID: 64aa7808 Received: from f7596ce60a2e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 298E966C-0327-4453-8943-BF4781A3DF64.1; Fri, 11 Nov 2022 18:58:15 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f7596ce60a2e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 18:58:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RQ+j8bSf+l1EMg4hHsMmRqdbZpiNdwP6zJpM2jxGRyu12MPJDzBRTaz+1bCrMaBnEdSZLFky04OI+R2F28DiXwZFoK/fp40uLE3D0hzhS4yTfvH/4Cf/HyJ17DVsSd4mZUWPnLsQax3p9oiT4p664UGcI89CnLlP3yz46/jhDp6Vi0/AO+eB1na7uRIVd689gneFWKFqbTS50Wau956lT5nFGbJOVT30NEqEWYp9ivsEyG8LE9Eulx76/AohutbXmpYjlQExHERa/qjj6TmmauJXYL/tocdQFKL4zvIFv2XGHvER9g3Cv1iehSla2vKwsNzaP87C9tH6oaZF47qsoA== 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=ALk/upi8XL48G69ZmhDTEUIqQVLFMtHnXGlyH22dfPE=; b=DaKqv9MB5GVvObZGYtlWwr/of5NSrFHGbENfqv8CQ6+BquHynPnh9gnzc4bqpYDVboqyShUYHwDg9iaCtM+kvLyijCyB9LulCTtclSPck4+R/W4BQUeiPgtshA7wxrVH3+pq0Y3JtQJ6O70cGkgz+xuEamL46DhQGYTTmXbhIsaaZCkDWnPqRuRnIPN0RH/WsiEXidLFvWnuN1J/Mp8qQ4cDTgcRopST1EjbTv4seK92ncg/2xnknZJ1/lCneH/FBqzuq91AkVntqroKUmX9Nd+s80OhlJpZsKoE7dzsP9haciXimMt5Bobk3iN07wfCF2KK8VDIdbfDoGckHE6w5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) by DU0PR08MB8561.eurprd08.prod.outlook.com (2603:10a6:10:406::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.11; Fri, 11 Nov 2022 18:58:13 +0000 Received: from PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701]) by PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 18:58:13 +0000 Date: Fri, 11 Nov 2022 18:54:06 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 6/8] docs: Add popcount, clz and ctz target attributes Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: SA0PR11CA0008.namprd11.prod.outlook.com (2603:10b6:806:d3::13) To PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAXPR08MB6686:EE_|DU0PR08MB8561:EE_|DBAEUR03FT034:EE_|DB9PR08MB8577:EE_ X-MS-Office365-Filtering-Correlation-Id: 4d09b6d2-0b5a-487e-1d93-08dac416b423 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: iHwGTeFauVKZ/5iCfOWKtmGMlfYNlcsrVlrl+nZIkETmMAPJERyEOtX7tVUEpxNp8Nk+nJLMtcD89B4rczSyWmYU3fUJGaE6pxjwXac9DQu8VY/jvtQ6GkiXKGs+EBWwm6hjhPEEHua0ZA9UmETMcvm9l8sofO4VgyVvAgM3it5Tl7K26zdeuKfjRtftsJmznSm9fcuNPfrxf9wM1Z2XG/c6Lp2e6O8TBbCa9lQDd7C2YWKjL9mD6mJorVjnlpjzWbxjes15o6TKN8g7F1p4YFGN0E6fJXJ6v+IZSMloUkHuGInehcVm4jiSknTMBcTs36sZR5yJPto44iUttmleXYzSy5PhKRIuDtJiSRUtZOm9KxnsDp4S7LimO/rADWgvsucLpwM+r9DtXA6yTbN4C2bEqj7Vlyx9gW8asVdcHG+SCRL8trQySg4FplZ/AJosCsUueSJ6d/AURPxbjB/NHfZGOnDHSgd7BPclBMg05W0ENeewHUqCwFKk04s4p/mfX+7d311wFWc7J2Ye9iR/rCGBvSP4XRL4l5bYbnaqb3wMtjEK1Q1YYbl6REHalv7fgu52x2cg/jSwj8FEitlNikunaBzLZb5cyoBqqce7oM7mgOCC0aIdoWUCSZRd72Nhw7+0K3nb0v2w19q8mSAAjUsc+dqxu4f+8rF9XBNUvsEs79YvV+pkaArXOBPA88RHsrUWb5y7nA4x+3xJInYhDA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB6686.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(39860400002)(396003)(376002)(136003)(346002)(451199015)(66556008)(86362001)(8676002)(6916009)(316002)(66946007)(6506007)(66476007)(41300700001)(6666004)(6512007)(26005)(478600001)(6486002)(38100700002)(2906002)(8936002)(186003)(5660300002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8561 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT034.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 6e12d18f-218b-44fa-15a4-08dac416af30 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z/8j9Y0wKym5wOrZdmCAmHBSAjMAyLL7UOryKVQkrKzU7sqgTn187dlSXeSjJjBK6OnQH/UsfNkGkmz4/neh5/8EayNUNQkmUawwwe2FKpZPH5f9ZHvzssPnK99yFMNXew2nPYJQuNTBffrmxwY68NhIcCZiER6V+/mfuFsY2MBQRKR1AC1dIR9vZVGQSXXe83YM9K1cv+9Pd3w+DPZDgwjRi0znJPhDrTxuzOKdaHvW0DzAekyx06PTPbe76GIrEXbA3tkKwshPl+wW2TRVeTx6KMMTYjOj9DqHP6CKml/aMvQzQ2T7oEGZT/DWGvB7s0SJTZSuICK3liE7d+G1jwxPBa8zVmA5P+N5cCfbYhCUGmITIskcTEmAC9JehnKGozbPtyhbGqtYHL4I3AWhetnjH/EzB8YYwtO+eKMyiz56iy7TefL2WngYiQ/3zziWZ0ZTaXcF6jbCnZyVTVorYcxq2vhKQ/B28B7kazIhR8dfz8Y4juMjWcs7AIuA9zan9oiT6rvunRWvLTgO9AlPs3qhRye8MNuXDVdpopR23lN53gKtKDmTYz75qUOnY4pHtcJWDfCWzxvpy067WJng2AfJl0Z4ejIXHPaqr3XYRu5nkzHhdhX2eI/V2Qt9rUJLtbxTIyd71hwtWdtLgcBIeL8svwmaej35c8ZPh0lK4OmDhjLeJ4w7ERYu7hTY3gvWc2ay1nyxL5autOW+OOm6WbBpEY2cRY7QtvtmfakivPpGhf593wAP6WxxvjQUfA6sYdR1P0e18REbq3DQzekkJA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(39860400002)(396003)(376002)(136003)(346002)(451199015)(40470700004)(46966006)(36840700001)(82310400005)(70586007)(86362001)(8676002)(47076005)(6916009)(70206006)(316002)(40480700001)(6506007)(336012)(40460700003)(82740400003)(41300700001)(6666004)(6512007)(26005)(478600001)(6486002)(356005)(81166007)(2906002)(8936002)(36860700001)(186003)(5660300002)(44832011); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 18:58:21.6871 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d09b6d2-0b5a-487e-1d93-08dac416b423 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT034.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8577 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * doc/gccint/testsuites/directives-used-within-dejagnu-tests/keywords-describing-target-attributes.rst: Add missing target attributes. diff --git a/gcc/doc/gccint/testsuites/directives-used-within-dejagnu-tests/keywords-describing-target-attributes.rst b/gcc/doc/gccint/testsuites/directives-used-within-dejagnu-tests/keywords-describing-target-attributes.rst index 709e4ea2b903cfad4faed40899020b29bc9b5811..8410c40d38fceb83ea8c6ba3bbf0fba5db7929e5 100644 --- a/gcc/doc/gccint/testsuites/directives-used-within-dejagnu-tests/keywords-describing-target-attributes.rst +++ b/gcc/doc/gccint/testsuites/directives-used-within-dejagnu-tests/keywords-describing-target-attributes.rst @@ -1075,6 +1075,24 @@ Other hardware attributes ``cell_hw`` Test system can execute AltiVec and Cell PPU instructions. +``clz`` + Target supports a clz optab on int. + +``clzl`` + Target supports a clz optab on long. + +``clzll`` + Target supports a clz optab on long long. + +``ctz`` + Target supports a ctz optab on int. + +``ctzl`` + Target supports a ctz optab on long. + +``ctzll`` + Target supports a ctz optab on long long. + ``cmpccxadd`` Target supports the execution of ``cmpccxadd`` instructions. @@ -1096,6 +1114,15 @@ Other hardware attributes ``pie_copyreloc`` The x86-64 target linker supports PIE with copy reloc. +``popcount`` + Target supports a popcount optab on int. + +``popcountl`` + Target supports a popcount optab on long. + +``popcountll`` + Target supports a popcount optab on long long. + ``prefetchi`` Target supports the execution of ``prefetchi`` instructions. From patchwork Fri Nov 11 19:01:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=HIeHM+nV; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N87TN29xNz23lq for ; Sat, 12 Nov 2022 06:05:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B68293858404 for ; Fri, 11 Nov 2022 19:05:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B68293858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668193555; bh=lS1+rFqSJCAXjTDxVAJDqxa3H/yOyEoTMjh1KIkTGQI=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HIeHM+nVVtNJQPXEv4UHfjGFYHyzlnhbeQORXj+FHueMCQXvJM0RictoAwBPwxHKH +xXI2CtH03E3cdh/sjOGLKU7cYqA0PdS3Je/jB2UIqwdwbvfANpLFh5ExEPcoHc5ST v3YVVkGVRhp06wT2olWHbr5pnySN9DxusArzJyWM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80057.outbound.protection.outlook.com [40.107.8.57]) by sourceware.org (Postfix) with ESMTPS id 2EF923858D1E for ; Fri, 11 Nov 2022 19:05:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2EF923858D1E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=XqJJar3ficrPHObNluZ2j1mzDoezKDmk3u42AuW9DFMKT8Xdl30wdo5AF8suovkGEheYLEsHPYWgDrcAkKnCuVgxHNMOQMuEKXd3/GW8EgFPabcOFnh3R6xoYGOs20NSMN7skvyOduV81bL7+LXtQPSH2GdBzUZiFCA3xODgNwFoo7gUvP88uTsTokrU+QtIjt9qnAolPue91rPKNLRCGkH94J0vBmJ79TVsgTXZOrMf54ll1q/F+FjQsL82YB02Kj7nBV3Tonu9IcRmIK2ml5Oy80CJ6nFpzwEZgXFhq/xfpeLexaqXrPrE9IJocmAqj7knihvX4nvyiZrXrihxwQ== ARC-Message-Signature: i=2; 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=lS1+rFqSJCAXjTDxVAJDqxa3H/yOyEoTMjh1KIkTGQI=; b=Tuc+JQocA/G6I0KXZyRr8+DjJbsFxEH1Qs+hloI+xxutGwpSloE6gn53L/PdUC/+d0UYcpVsUZ8g1T/FjNNlkxPr1OKtXeC9JG5trcs7AdZa6n5V5ADs98Vdei/VsbDpku5xl0sCiUbu1LOXoVjnL84QxY2xtte45HiP3tOMuWnuGin5juQofj6Sv+0foS000ZjI6v/vIBFd5FMbFjZujVouPXmgm/9YKMIVVwuq5H2kHL6MUFXa9KywTxesD/L6+RE5WLlrb5Q0isg087HVEoLNoDK3HqByQWFmIGk4dF6zBJHeuBMtH+iyyugT7l8jrPsuP1W5/D6RLHHxMUTUdQ== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AM6P191CA0078.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8a::19) by VI1PR08MB5358.eurprd08.prod.outlook.com (2603:10a6:803:13c::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 19:05:25 +0000 Received: from VI1EUR03FT049.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8a:cafe::d7) by AM6P191CA0078.outlook.office365.com (2603:10a6:209:8a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.27 via Frontend Transport; Fri, 11 Nov 2022 19:05:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT049.mail.protection.outlook.com (100.127.144.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 19:05:24 +0000 Received: ("Tessian outbound b4aebcc5bc64:v130"); Fri, 11 Nov 2022 19:05:24 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ddae8e65732d6958 X-CR-MTA-TID: 64aa7808 Received: from 9edbbafed9fb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id EC0836C1-B6CB-46B9-8AE8-0C36166596A7.1; Fri, 11 Nov 2022 19:05:17 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9edbbafed9fb.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 19:05:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DggiMHnPyApE4P8f2SUahzOKcWcWbLFidYxUm9XP9sgzLZXQuo4dcd+u14raoHZonFsOmWD/2b+dWgMp0dnlzlAC2l4sjoH96ZzLDSVgn7cDBhxBShYdaY9FCaCR+Mi6YYp9ucHGFj5Y+BuUrC8tCsy06Ed0tXiRb8+986+S1b5euF1o29Pv7QJ3PXnt7D0BeRr2sRKqPI2EVwUWrViYrE0J5mBnZ/CtcdxGk9jsIX/Y6bjAvgP4yahQlk7qsKAEMvJg/V507t1dv6aurV8of/sEJD3KVcng3VfaNyJf1f/NcUcagLKsujHDHgXmPQAOpaTRa38lrlbWIetzWp6Qgw== 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=lS1+rFqSJCAXjTDxVAJDqxa3H/yOyEoTMjh1KIkTGQI=; b=e+REEyfviBb+B+dRohvvDTPwSfHHruZcD8tUj/hZPCo6USqYjItUB+55rgAeaKayxORrzh5jkz+fp1sHcI1FuVHcf6tFHHkuUK2Tu4Jp0BDRXr7GfUOzZ5znZiqH6ctJAcHHe6SMGCrFFsEv4JnDMuhzwlnAXW34jv8XrxIHs891G4/2jEDlGUbixzffv9k89hUsotxdkkcIvBD7Erqps6RN3lQJ5SbkT6liSecxqKYtamR+FlVXPA0XOcOnkh1ktgUQne6hJVOuNM3SaxqEcHifs0Dlb9MfcqQwfCmsq6ygf2roGJVTm0O5kow4kRJYTduiS8lNOzmZkF+6B6K+xQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) by VI1PR08MB5311.eurprd08.prod.outlook.com (2603:10a6:803:13a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 19:05:14 +0000 Received: from PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701]) by PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 19:05:14 +0000 Date: Fri, 11 Nov 2022 19:01:10 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 7/8] middle-end: Add c[lt]z idiom recognition Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO2P265CA0495.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13a::20) To PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAXPR08MB6686:EE_|VI1PR08MB5311:EE_|VI1EUR03FT049:EE_|VI1PR08MB5358:EE_ X-MS-Office365-Filtering-Correlation-Id: b4bff7da-9eb9-4662-16bf-08dac417b054 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: +AmX+qT2itEojFLFpgP7BW/3fVW8P6wNF8NpoPBY+rzOAo+BKkwjuNGjNrG5EQyVZc+FB2Hhc3FXYiXsDQwPNi7Gp/Zk2DYoucX/id07SDuKxcnRUy1kyvbU8y/+OwETB+IJaffNsutuVxclz2AfV04CVAgJcJKuRMYn9AXdLdUQ4bEyRm6fM3jK0Y6MlXBINpyIsYv4VUVfKCKFcCxTdoc4p5XR96hXzhHGrMHo3qp3PW8rwhCWxkkjo2v51YllAWWJ+YR6VQ1TGIvlUcAAsrT5v9mmZdicD28Hu1bvtBdkb8OsZmrjSVdF61L7GChP8FJqSRq/9AKkmfHpR9r6pZn5urPIqXw9EIO1GacOHWVnrnUOLAP9X/wGcI5PxWRJrZ4LB2R9Kb5MKOeS39RNasY5C/Xhk+zKW3StH3cr2R9+U4j3J/4x4nCc0Arv/2UrJ1A+Ji8AdYmrS5o+FrVjAcFQHbhZz/wGxUR3Bim7Ee95kE73DQi0Gtx47WcMnKHqH6Baye0euJGxTQzrVA8foXD/oCOFQsBDni5VTzljUTZzy77Yal8eElOWhu3HSUxzlFFsI+pEEzGHSy7kei7TO1j8vp1HMldb9lmWHPU7t1YHf7yzz9MqDEYDrLRIWFOXEaTZmizxRrRgLNHyiXn1XdwfjTfAio9yBDL4QxqCQXPIqwzXuANC6k9m0NgddNo0sqC21WabdOMsrn+jcfAXJfTundrvsJVdTupL8B/rXQIOhjhwS28rm8gsG9X7wK+hq3ThG6XPpUR8ukvWpL92nQzlWPRgoHcKTAoaNVeDVTZWWhqc33KgVP71++JTlSVI7Se5t+qVSol7IUA6awpRcA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB6686.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(346002)(39860400002)(396003)(136003)(366004)(376002)(451199015)(84970400001)(5660300002)(316002)(66946007)(66556008)(66476007)(6916009)(86362001)(8936002)(8676002)(38100700002)(41300700001)(6512007)(478600001)(6486002)(6506007)(26005)(6666004)(44832011)(30864003)(2906002)(186003)(67856001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5311 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: cb5dd558-2847-40e0-7213-08dac417a8cf X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DEWp0EOCwS1lqFTzFeRERaqg8/61Io4losOkPw+Sr++OmgwXUhU5FTTfWmIAB1jtaaVKj/1C+JALSNJcYPUtWxZpgE/LvfRLJ5eYvZb47vZaxP/tKQUtHWIo9kWBg0AgDyr8R969l3+5cvhBYVtroRYlTJ60Z1JdX/L9oO591VJW3X8FPmu9Tsgihs5Zoc1B0Vy2/4CZ5euHLYujyxM+g0G5rzxLYNm+Lp0MgsKnr+/LomPxvby1wGqtmqGCTAB5RZ+ZVOpCr9e1USW2ekAmiBljG2DL6KByjcshPyy+HKwxT+WW4WpsusVxZ7RwRgDz753IAVazzJld/ONN18B3UQeV1uEdN6xKvkPRQHByxCurU4/8ihMKZfouUcJIOtuABKk/7J1WB2oEC/Q19ddupkQYYBKJz2utMplbh0UzvcNo5dnx/RxC6xT7tsl6LFkWl9tI15Yvo/H7SqmDqidxFqgRohR7EhgvQ5b8e4UkKiDIPRooOTEh7TsGpdFacMjIJW7FItXD/dcgIQ0cwM4bJs7RhmCe8Drre7qA2q79e4ZZheAabifW+HQj7lhfiHfpSqzc6iN0yrgZsvbhvy5xiYo1fBpeHN92tVwrK9JKsXyLnL3802MCue/WblU/0mYTdeKaa0m+eVdOHQ/v4GUG29iIcU/GI89D+AI340NNRPsIAuitDj37hN25atbIB0Wdgg7/yt+lXcZT1P0CFYaZTvwsPnN5cr3EYciTXNyGxWx0UCx21f8scS/9pGK6tASNqxbr9f2pQAYqJPv0/CtmtWjBXkYCYF+tAvBV6MufOeU40hAeOWSW4M91y7zhk0vXVuv7NOY/Ohn3CQkFYYxBAhMIAXAh9GaBQ4wW5/xML4qySgh3Bjlpi9xYfzKGbEe4 X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(396003)(39860400002)(136003)(346002)(376002)(451199015)(40470700004)(46966006)(36840700001)(84970400001)(44832011)(2906002)(70586007)(70206006)(8936002)(30864003)(5660300002)(8676002)(41300700001)(316002)(40480700001)(356005)(81166007)(6486002)(478600001)(6512007)(26005)(82310400005)(6666004)(6506007)(186003)(36860700001)(82740400003)(86362001)(40460700003)(336012)(6916009)(47076005)(67856001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 19:05:24.6533 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4bff7da-9eb9-4662-16bf-08dac417b054 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VI1EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5358 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This recognises the patterns of the form: while (n & 1) { n >>= 1 } Unfortunately there are currently two issues relating to this patch. Firstly, simplify_using_initial_conditions does not recognise that (n != 0) and ((n & 1) == 0) implies that ((n >> 1) != 0). This preconditions arise following the loop copy-header pass, and the assumptions returned by number_of_iterations_exit_assumptions then prevent final value replacement from using the niter result. I'm not sure what is the best way to fix this - one approach could be to modify simplify_using_initial_conditions to handle this sort of case, but it seems that it basically wants the information that ranger could give anway, so would something like that be a better option? The second issue arises in the vectoriser, which is able to determine that the niter->assumptions are always true. When building with -march=armv8.4-a+sve -S -O3, we get this codegen: foo (unsigned int b) { int c = 0; if (b == 0) return PREC; while (!(b & (1 << (PREC - 1)))) { b <<= 1; c++; } return c; } foo: .LFB0: .cfi_startproc cmp w0, 0 cbz w0, .L6 blt .L7 lsl w1, w0, 1 clz w2, w1 cmp w2, 14 bls .L8 mov x0, 0 cntw x3 add w1, w2, 1 index z1.s, #0, #1 whilelo p0.s, wzr, w1 .L4: add x0, x0, x3 mov p1.b, p0.b mov z0.d, z1.d whilelo p0.s, w0, w1 incw z1.s b.any .L4 add z0.s, z0.s, #1 lastb w0, p1, z0.s ret .p2align 2,,3 .L8: mov w0, 0 b .L3 .p2align 2,,3 .L13: lsl w1, w1, 1 .L3: add w0, w0, 1 tbz w1, #31, .L13 ret .p2align 2,,3 .L6: mov w0, 32 ret .p2align 2,,3 .L7: mov w0, 0 ret .cfi_endproc In essence, the vectoriser uses the niter information to determine exactly how many iterations of the loop it needs to run. It then uses SVE whilelo instructions to run this number of iterations. The original loop counter is also vectorised, despite only being used in the final iteration, and then the final value of this counter is used as the return value (which is the same as the number of iterations it computed in the first place). This vectorisation is obviously bad, and I think it exposes a latent bug in the vectoriser, rather than being an issue caused by this specific patch. gcc/ChangeLog: * tree-ssa-loop-niter.cc (number_of_iterations_cltz): New. (number_of_iterations_bitcount): Add call to the above. (number_of_iterations_exit_assumptions): Add EQ_EXPR case for c[lt]z idiom recognition. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/cltz-max.c: New test. * gcc.dg/tree-ssa/clz-char.c: New test. * gcc.dg/tree-ssa/clz-int.c: New test. * gcc.dg/tree-ssa/clz-long-long.c: New test. * gcc.dg/tree-ssa/clz-long.c: New test. * gcc.dg/tree-ssa/ctz-char.c: New test. * gcc.dg/tree-ssa/ctz-int.c: New test. * gcc.dg/tree-ssa/ctz-long-long.c: New test. * gcc.dg/tree-ssa/ctz-long.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cltz-max.c b/gcc/testsuite/gcc.dg/tree-ssa/cltz-max.c new file mode 100644 index 0000000000000000000000000000000000000000..a6bea3d338940efee2e7e1c95a5941525945af9e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cltz-max.c @@ -0,0 +1,72 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-loop-optimize -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int clz_count1 (unsigned char b) { + int c = 0; + + if (b == 0) + return 0; + + while (!(b & (1 << (PREC - 1)))) { + b <<= 1; + c++; + } + if (c <= PREC - 1) + return 0; + else + return 34567; +} + +int clz_count2 (unsigned char b) { + int c = 0; + + if (b == 0) + return 0; + + while (!(b & (1 << PREC - 1))) { + b <<= 1; + c++; + } + if (c <= PREC - 2) + return 0; + else + return 76543; +} + +int ctz_count1 (unsigned char b) { + int c = 0; + + if (b == 0) + return 0; + + while (!(b & 1)) { + b >>= 1; + c++; + } + if (c <= PREC - 1) + return 0; + else + return 23456; +} + +int ctz_count2 (unsigned char b) { + int c = 0; + + if (b == 0) + return 0; + + while (!(b & 1)) { + b >>= 1; + c++; + } + if (c <= PREC - 2) + return 0; + else + return 65432; +} +/* { dg-final { scan-tree-dump-times "34567" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "76543" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "23456" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "65432" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-char.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-char.c new file mode 100644 index 0000000000000000000000000000000000000000..4a122db95bbb576b4ade706bd3b1ca809d2f1e3b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-char.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clzl } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned char b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & (1 << (PREC - 1)))) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1 << (PREC - 1)) != 0) + __builtin_abort (); + if (foo(35) != PREC - 6) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-int.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-int.c new file mode 100644 index 0000000000000000000000000000000000000000..96646f8e19cd5b2342acb88949b3ef6e3e2abd5a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-int.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clzl } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_INT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned int b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & (1 << (PREC - 1)))) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1 << (PREC - 1)) != 0) + __builtin_abort (); + if (foo(35) != PREC - 6) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-long-long.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-long-long.c new file mode 100644 index 0000000000000000000000000000000000000000..80d3edc1dab2e74fc3271ba9d97640839b3a3786 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-long-long.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clzll } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long long b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & (1LL << (PREC - 1)))) { + b <<= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1LL << (PREC - 1)) != 0) + __builtin_abort (); + if (foo(35) != PREC - 6) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/clz-long.c b/gcc/testsuite/gcc.dg/tree-ssa/clz-long.c new file mode 100644 index 0000000000000000000000000000000000000000..1c8037f93b9c9d42f580a172267c65723a46ef8b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/clz-long.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-require-effective-target clzl } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & (1L << (PREC - 1)))) { + b <<= 1; + c++; +} + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1L << (PREC - 1)) != 0) + __builtin_abort (); + if (foo(35) != PREC - 6) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_clz|\\.CLZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c new file mode 100644 index 0000000000000000000000000000000000000000..3cd166acbd4670e175d79a2403de2d5a4fd38665 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-char.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctz } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned char b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & 1)) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(128) != 7) + __builtin_abort (); + if (foo(96) != 5) + __builtin_abort (); + if (foo(35) != 0) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c new file mode 100644 index 0000000000000000000000000000000000000000..7f63493eb7389a18516f8f126c3c55dc80f0bde6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-int.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctz } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_INT__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned int b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & 1)) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1 << (PREC - 1)) != PREC - 1) + __builtin_abort (); + if (foo(96) != 5) + __builtin_abort (); + if (foo(35) != 0) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c new file mode 100644 index 0000000000000000000000000000000000000000..924f61b76f01c77a40b9fff64af3b629ab1418c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long-long.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctzll } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long long b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & 1)) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1LL << (PREC - 1)) != PREC - 1) + __builtin_abort (); + if (foo(96) != 5) + __builtin_abort (); + if (foo(35) != 0) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c new file mode 100644 index 0000000000000000000000000000000000000000..178945daa8a2697989f1a1a0804ce33d768dcc55 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ctz-long.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* { dg-require-effective-target ctzl } */ +/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */ + +#define PREC (__CHAR_BIT__ * __SIZEOF_LONG__) + +int +__attribute__ ((noinline, noclone)) +foo (unsigned long b) { + int c = 0; + + if (b == 0) + return PREC; + + while (!(b & 1)) { + b >>= 1; + c++; + } + + return c; +} + +int main() +{ + if (foo(0) != PREC) + __builtin_abort (); + if (foo(1L << (PREC - 1)) != PREC - 1) + __builtin_abort (); + if (foo(96) != 5) + __builtin_abort (); + if (foo(35) != 0) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */ diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 16e8e25919d808cea27adbd72f0be01ae2f0e547..87e6fe81d68fc3352e450688ef79e6fc68854d8a 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2274,6 +2274,167 @@ build_cltz_expr (tree src, bool leading, bool defined_at_zero) return call; } +/* See comment below for number_of_iterations_bitcount. + For c[lt]z, we have: + + modify: + iv_2 = iv_1 << 1 OR iv_1 >> 1 + + test: + if (iv & 1 << (prec-1)) OR (iv & 1) + + modification count: + src precision - c[lt]z (src) + + */ + +static bool +number_of_iterations_cltz (loop_p loop, edge exit, + enum tree_code code, + class tree_niter_desc *niter) +{ + bool modify_before_test = true; + HOST_WIDE_INT max; + int checked_bit; + tree iv_2; + + /* Check that condition for staying inside the loop is like + if (iv == 0). */ + gimple *cond_stmt = last_stmt (exit->src); + if (!cond_stmt + || gimple_code (cond_stmt) != GIMPLE_COND + || (code != EQ_EXPR && code != GE_EXPR) + || !integer_zerop (gimple_cond_rhs (cond_stmt)) + || TREE_CODE (gimple_cond_lhs (cond_stmt)) != SSA_NAME) + return false; + + if (code == EQ_EXPR) + { + /* Make sure we check a bitwise and with a suitable constant */ + gimple *and_stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (cond_stmt)); + if (!is_gimple_assign (and_stmt) + || gimple_assign_rhs_code (and_stmt) != BIT_AND_EXPR + || !integer_pow2p (gimple_assign_rhs2 (and_stmt))) + return false; + + checked_bit = tree_log2 (gimple_assign_rhs2 (and_stmt)); + + iv_2 = gimple_assign_rhs1 (and_stmt); + } + else + { + /* We have a GE_EXPR - a signed comparison with zero is equivalent to + testing the leading bit, so check for this pattern too. */ + + iv_2 = gimple_cond_lhs (cond_stmt); + tree test_value_type = TREE_TYPE (iv_2); + + if (TYPE_UNSIGNED (test_value_type)) + return false; + + gimple *test_value_stmt = SSA_NAME_DEF_STMT (iv_2); + + if (is_gimple_assign (test_value_stmt) + && gimple_assign_rhs_code (test_value_stmt) == NOP_EXPR) + { + /* If the test value comes from a NOP_EXPR, then we need to unwrap + this. We conservatively require that both types have the same + precision. */ + iv_2 = gimple_assign_rhs1 (test_value_stmt); + tree rhs_type = TREE_TYPE (iv_2); + if (TREE_CODE (rhs_type) != INTEGER_TYPE + || (TYPE_PRECISION (rhs_type) + != TYPE_PRECISION (test_value_type))) + return false; + } + + checked_bit = TYPE_PRECISION (test_value_type) - 1; + } + + gimple *iv_2_stmt = SSA_NAME_DEF_STMT (iv_2); + + /* If the test comes before the iv modification, then these will actually be + iv_1 and a phi node. */ + if (gimple_code (iv_2_stmt) == GIMPLE_PHI + && gimple_bb (iv_2_stmt) == loop->header + && gimple_phi_num_args (iv_2_stmt) == 2 + && (TREE_CODE (gimple_phi_arg_def (iv_2_stmt, + loop_latch_edge (loop)->dest_idx)) + == SSA_NAME)) + { + /* iv_2 is actually one of the inputs to the phi. */ + iv_2 = gimple_phi_arg_def (iv_2_stmt, loop_latch_edge (loop)->dest_idx); + iv_2_stmt = SSA_NAME_DEF_STMT (iv_2); + modify_before_test = false; + } + + /* Make sure iv_2_stmt is a logical shift by one stmt: + iv_2 = iv_1 {<<|>>} 1 */ + if (!is_gimple_assign (iv_2_stmt) + || (gimple_assign_rhs_code (iv_2_stmt) != LSHIFT_EXPR + && (gimple_assign_rhs_code (iv_2_stmt) != RSHIFT_EXPR + || !TYPE_UNSIGNED (TREE_TYPE (gimple_assign_lhs (iv_2_stmt))))) + || !integer_onep (gimple_assign_rhs2 (iv_2_stmt))) + return false; + + bool left_shift = (gimple_assign_rhs_code (iv_2_stmt) == LSHIFT_EXPR); + + tree iv_1 = gimple_assign_rhs1 (iv_2_stmt); + + /* Check the recurrence. */ + gimple *phi = SSA_NAME_DEF_STMT (iv_1); + if (gimple_code (phi) != GIMPLE_PHI + || (gimple_bb (phi) != loop_latch_edge (loop)->dest) + || (iv_2 != gimple_phi_arg_def (phi, loop_latch_edge (loop)->dest_idx))) + return false; + + /* We found a match. */ + tree src = gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx); + int src_precision = TYPE_PRECISION (TREE_TYPE (src)); + + /* Apply any needed preprocessing to src. */ + int num_ignored_bits; + if (left_shift) + num_ignored_bits = src_precision - checked_bit - 1; + else + num_ignored_bits = checked_bit; + + if (modify_before_test) + num_ignored_bits++; + + if (num_ignored_bits != 0) + src = fold_build2 (left_shift ? LSHIFT_EXPR : RSHIFT_EXPR, + TREE_TYPE (src), src, + build_int_cst (integer_type_node, num_ignored_bits)); + + /* Get the corresponding c[lt]z builtin. */ + tree expr = build_cltz_expr (src, left_shift, false); + + if (!expr) + return false; + + max = src_precision - num_ignored_bits - 1; + + expr = fold_convert (unsigned_type_node, expr); + + tree assumptions = fold_build2 (NE_EXPR, boolean_type_node, src, + build_zero_cst (TREE_TYPE (src))); + + niter->assumptions = simplify_using_initial_conditions (loop, assumptions); + niter->may_be_zero = boolean_false_node; + niter->niter = simplify_using_initial_conditions (loop, expr); + + if (TREE_CODE (niter->niter) == INTEGER_CST) + niter->max = tree_to_uhwi (niter->niter); + else + niter->max = max; + + niter->bound = NULL_TREE; + niter->cmp = ERROR_MARK; + + return true; +} + /* See comment below for number_of_iterations_bitcount. For c[lt]z complement, we have: @@ -2434,6 +2595,7 @@ number_of_iterations_bitcount (loop_p loop, edge exit, class tree_niter_desc *niter) { return (number_of_iterations_popcount (loop, exit, code, niter) + || number_of_iterations_cltz (loop, exit, code, niter) || number_of_iterations_cltz_complement (loop, exit, code, niter)); } @@ -2960,6 +3122,9 @@ number_of_iterations_exit_assumptions (class loop *loop, edge exit, case NE_EXPR: break; + case EQ_EXPR: + return number_of_iterations_cltz (loop, exit, code, niter); + default: return false; } From patchwork Fri Nov 11 19:07:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1702974 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=l6MhviFT; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N87cQ639yz23mY for ; Sat, 12 Nov 2022 06:12:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C2BE3858436 for ; Fri, 11 Nov 2022 19:12:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C2BE3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668193920; bh=oZRYZAn2E/addXOuMJK7ZCKdq1CBg9Rrgx5CEKmmmYE=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=l6MhviFTh1Cd8/gVWooEnqpo9pjIWXaS309cSvSPLwk0jRAtFFq9Edoa1WWINGvBj DmFCfFHvbodIia187bbjg9+Bm8tsn+PjUqm8/fBCpL1xH/MGxEWl5KKGA6loCt6DMK J+GqHPjEbrcBmh0UtcCgDm6cNYljt6ci4zMGL8/M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60056.outbound.protection.outlook.com [40.107.6.56]) by sourceware.org (Postfix) with ESMTPS id DC3C43858D1E for ; Fri, 11 Nov 2022 19:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC3C43858D1E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=g/KdDs4ebMWg1C80XsR5qRgyRgth80sZ0RgTLdLs3KnZHmza+NhBEA9JvFN18+GJJzXyrAQvG9VUEzR8okf+XyAetNtfKX/uDRo8w9tw6NIvY0x+i01+B4PCLzhqt0GmeYXOZZrdaSrjSeyi0beqXcf/YMDe9AkkbCTr3u1tvAcZhDl7xdM0oT93F7I9MWmb2slk+rczXztx20MczpQRxQy32szEYh1y7NLqguILNtFlAdXxJ9z50TogLKhqMI8OA4a/Ozg7j7KmoqXOTDKsvh9WZblFy9Hc0TMGjAUiKS1DqtKZhgAeebmjiXN1d1YWKfT7p+8G3JzNfgxHF6KXZQ== ARC-Message-Signature: i=2; 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=oZRYZAn2E/addXOuMJK7ZCKdq1CBg9Rrgx5CEKmmmYE=; b=QuddBLu/ce0QmmGfQ6vbqUwKKi6R2ZQqBQcMW79IBNm4XUZLCdZgt9yufOd1zMS8lc41XDwpjS0tADGzd3JJlnlr0U+NKnFxHA9ktcpqwLGk8SN1vqowgfIq49XPMzbhZ2pBN2RxFs6jVQ3vNl68ly/gLKKYIBjQaGUVzr+mn3Fkroy1kYQEb1UE5Zq6KVJJC408vGEPQTUNX3UNuByoB6SGWTaqrIdH3L6/ZlvjDD5I16wFH/EwMgO25FgRC3/YgL1ULyvbqU/Sq1AVAc/X+iZ2eF+YEQQQYsL7ij7DHUBhwQbUhkB0yfig0tPwm0mTSFLueVUGG2G1EvF/MSyfMw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AM5PR0602CA0024.eurprd06.prod.outlook.com (2603:10a6:203:a3::34) by AS8PR08MB9978.eurprd08.prod.outlook.com (2603:10a6:20b:631::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 19:11:29 +0000 Received: from VI1EUR03FT017.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:a3:cafe::f3) by AM5PR0602CA0024.outlook.office365.com (2603:10a6:203:a3::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13 via Frontend Transport; Fri, 11 Nov 2022 19:11:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT017.mail.protection.outlook.com (100.127.145.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.12 via Frontend Transport; Fri, 11 Nov 2022 19:11:29 +0000 Received: ("Tessian outbound b4aebcc5bc64:v130"); Fri, 11 Nov 2022 19:11:28 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d7b9b55187779f7f X-CR-MTA-TID: 64aa7808 Received: from d01ef7655075.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2E54723C-21A4-4C9A-881A-ACCF1AD6955C.1; Fri, 11 Nov 2022 19:11:21 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d01ef7655075.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 11 Nov 2022 19:11:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NfjLcgP7HEsNnvGFS65hVT8k0KEgb13Eu+SiaOZPbnv47qfLkxGVFqBRQzaNeJGWbaQIsEz5uBE/128/lO1I99+A1mFUl6/z9glXIxjNQO7qvDI9t7lT7fwbmYHy2ywAHyIfW79TbK5O7jMSrWuaNClXq6VyJmiq9FAOMbVquxrIQ73Dnh4iFOIndX6L8QeSInaVozxjn82slPXoDYqpuKUzbVbpShmLVO/whN2g8iRAgDNAKiDJnt5KGzUVnizgpuQ1RvWw2zVBoLRphprCpYtau9UZwMVw3ebYfO9o9+5HwiR4swsH7HEQUNP6FVDehuxxY92l7nfWIHhhp7wn5w== 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=oZRYZAn2E/addXOuMJK7ZCKdq1CBg9Rrgx5CEKmmmYE=; b=AVs3NKLwdDcgn2VSi1yKZt9dmAg/BDhk2TZpzU0uj4oD6InHzuB3kzJ4yREM9WVWwy94kMb95BmeGwhqv7SpE9UFxXVnV/v7FlujfYAkwmUzJgSgNxz4JjO1eBNbKFqNT0eJ4hFLPMjcCF6s1aGPO6+I5nEG/HflAkVtz4WsOKDCciwiqe2j3AMDf/EVw//hF9sRIQAujgsMj4BC9JXDz163ScZUsju2e0hwipsdftIort/tSWo1GGOoyYaNFLNAlVlzSXhdH0gsRicJ3LjJ8fq7gLJYYE/6zRWgOR3oPbI8SRYnXUkJUHmcVRXw+m8BKCt5DALNtUcJG9WIJLsZ6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) by GV2PR08MB9349.eurprd08.prod.outlook.com (2603:10a6:150:da::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Fri, 11 Nov 2022 19:11:20 +0000 Received: from PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701]) by PAXPR08MB6686.eurprd08.prod.outlook.com ([fe80::44db:f442:b299:a701%3]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 19:11:20 +0000 Date: Fri, 11 Nov 2022 19:07:18 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 8/8] middle-end: Expand comment for tree_niter_desc.max Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO4P123CA0334.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18c::15) To PAXPR08MB6686.eurprd08.prod.outlook.com (2603:10a6:102:13e::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAXPR08MB6686:EE_|GV2PR08MB9349:EE_|VI1EUR03FT017:EE_|AS8PR08MB9978:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c2c8a90-36f2-4c2d-cfcd-08dac41889b2 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: x9c3fa7sRzcPJrrMw1DuWoheiDdXGLx4giYQ0XCgYqxMtPTHbj1gJPklTqnWoV/EV0wYfeRRV3a5D7op0ua9EZR49WJWMBO8syB5mAhdSZf8umxFaczRw1gQli/fPfZ+X9N8xeNyhg1sv8YLHA41j1NQrC8fxwZRrRUYmQDSVXPL+KAMJfYMGwhaT8kXS9ws/rmJMAlBOiy4lxcFAAc8hAx4YdVSgv1aJ4qGfRDtJOSV3nL/VxJ4xUbDI8rbz9f6/mezJfUdU5GCoxVh0InyceGUM+Zvo1q17oGJLzU7r/XZiFpDyGruYdhHa8iczogb5f9DcuRLN3Q81gwE07z3ZCnVWrfM+iEUaAy8KnTXH4B7ng3On8AUXW22Gt/cULOshWmU7ECXeFaXZvfmzLBzTh9oWFr1Vpx4JZO7avVYw4IyD4o55TWe+Fuvd6qFZYgRJ2Az0SutzCyjqris/4f5vdVqfX3pZqERAC9ElHOHS6KE/3B+ttisOvlg4Tn3hYbzpd0PR5NJyZgTfcpukZCkXySc3RHhqfhuaSdDrjGNXW7jP88jD6dtH2uA8JHuwMU2VGxUiuNEyz1uJMt+TCiLcbSa43GPDBBzQmdvAPXYdror+sR8kd6Cw3Va18Woq1mVpM3UfL6gPdN083ybKbqSfCVSrdJhgyUqSindIhn05ACs7hSM1w4L8I0NKh/t5W4U3LOrNuA8pM15T4YLiM1Cxg== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR08MB6686.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(346002)(136003)(396003)(376002)(366004)(39860400002)(451199015)(316002)(83380400001)(86362001)(41300700001)(66556008)(8676002)(66476007)(66946007)(44832011)(8936002)(4744005)(5660300002)(38100700002)(186003)(6486002)(478600001)(6512007)(26005)(6916009)(6506007)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9349 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1b98cd02-777a-4ce7-7395-08dac4188400 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FcPUVFQiQyO+HVXh+KVWVpAnU2OUf24vhBGPuWvpR0CjoUZ65YrhflVqFDq8sapnI4HTpsjuhYjAgEqjekT8DkZcuUCHmTWkA1ogJVqrdLhWfW2BAdLGp/o7muNEpBXl4dFQ/LmMsfJPxwvbxkG/dJzsF94zlv0atQRY2BvM1kkwUOtsywV2gdyySzZcXP3WFiAJ2oHQpuo2w3Utah8c10bY6SUgziT8iahzGHuWD09ccKdZoNTM8iry1DBI52pghmUQXDD0PrOHOs2CKQjiCDb2SQUkml146XXV7YIjU5pO6e1P4BXdbWmD/4TyHDw/aA9JFmwPo2TpIBDqVfzEfHNFhMqFGKlM1zxxBqq09CQOYv+TfdP8e8g9QJjuFoJc90bK5oc8jtBoT+bzB8qAjfwTUDXMTB/BjQlrO7r7TcNuqj9l5emg5hyKRcJFHpebUBdMoqHr+HjzTCRNyAuoEA0UVOXWU4iSJRRxF6U3ac4LGIs9DmxEzmHZRayfaCRJNluGH8YXdkZ6j8a9XE0AzgMUwIf/PqsErwRzI5Ezp0ONSNCp/t0g4GgXzsAOvUwPIfaNpUZPQgjin3A+DyyNzM2d1KKrA2prgO1IMHLVxJbAAlVrV1YKDK5oCHO+phCno/bzvMungjiRUcWbOCJfeHpbd7UICy4Vfd+FaIi4fgUIcPfe0hY7cY2a2U2NXpf1ryVtkvw0NZrwisXbQd4MxfTYR7zsmK+4nBl8oS8p1JgPJmB5yaNEW7GvEuHwkGJcjEyIEcMQs31Bvm536Ze7LA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(39860400002)(396003)(346002)(451199015)(40470700004)(46966006)(36840700001)(82740400003)(2906002)(4744005)(81166007)(356005)(40460700003)(83380400001)(36860700001)(8936002)(86362001)(316002)(44832011)(6916009)(336012)(186003)(47076005)(6486002)(478600001)(40480700001)(8676002)(70206006)(82310400005)(41300700001)(5660300002)(6512007)(6506007)(26005)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 19:11:29.3709 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c2c8a90-36f2-4c2d-cfcd-08dac41889b2 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VI1EUR03FT017.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9978 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This requirement is enforced by a gcc_checking_assert in record_estimate. gcc/ChangeLog: * tree-ssa-loop.h (tree_niter_desc): Update comment. diff --git a/gcc/tree-ssa-loop.h b/gcc/tree-ssa-loop.h index 6c70f795d171f22b3ed75873fec4920fea75255b..c24215be8822c31a05eaedcf4d3a26db0feab6cf 100644 --- a/gcc/tree-ssa-loop.h +++ b/gcc/tree-ssa-loop.h @@ -52,7 +52,8 @@ public: may_be_zero == false), more precisely the number of executions of the latch of the loop. */ widest_int max; /* The upper bound on the number of iterations of - the loop. */ + the loop. If niter is constant, then these values + must agree. */ /* The simplified shape of the exit condition. This information is used by loop unrolling. If CMP is ERROR_MARK, then the loop cannot be unrolled. From patchwork Thu Dec 22 17:43:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Carlotti X-Patchwork-Id: 1718923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=IwXX820Z; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NdHk05j6rz1ydb for ; Fri, 23 Dec 2022 04:44:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B60D83857C44 for ; Thu, 22 Dec 2022 17:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B60D83857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671731046; bh=8hyc1gYjkQSNUcPHumH3asWSUedWYGBF6sFLzfHw9Rk=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=IwXX820Z0BsMFbHq5hVrLEPrPE0yJC+vpUeXij4z0TOeJFnDKwqL/SY/B6/Ad1aD+ sreXN69WpJpKVRhwLJprkaul7RNTstaqVhO9gjrWt5/iQ8itbcY+GvGuCufVeKHGD8 Wd3moBzNZZ4J0RjrR21WeDU2kxELydt7vcJpZKwk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2054.outbound.protection.outlook.com [40.107.105.54]) by sourceware.org (Postfix) with ESMTPS id 2E64B38555A4 for ; Thu, 22 Dec 2022 17:43:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2E64B38555A4 Received: from DB6PR07CA0058.eurprd07.prod.outlook.com (2603:10a6:6:2a::20) by AS8PR08MB6069.eurprd08.prod.outlook.com (2603:10a6:20b:29c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.6; Thu, 22 Dec 2022 17:43:35 +0000 Received: from DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2a:cafe::76) by DB6PR07CA0058.outlook.office365.com (2603:10a6:6:2a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.10 via Frontend Transport; Thu, 22 Dec 2022 17:43:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT012.mail.protection.outlook.com (100.127.142.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.12 via Frontend Transport; Thu, 22 Dec 2022 17:43:34 +0000 Received: ("Tessian outbound 8038f0863a52:v132"); Thu, 22 Dec 2022 17:43:34 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 138f9340366541eb X-CR-MTA-TID: 64aa7808 Received: from 3e35189a221f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E06B5094-C805-4E87-8D22-D1196EEFB303.1; Thu, 22 Dec 2022 17:43:28 +0000 Received: from EUR02-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3e35189a221f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 22 Dec 2022 17:43:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RnMwy6TwCA+axKI5M1RjmxrkDAQiPZODLFeM9n0oAAlzEv0KSe3btdvUZZhz4wjeKLCNmvHPTQ+29VfQF9MAMSqNksU9wzDU8Q16Ni/iacrF5raMR/BrIExYaLorXD3oV8nilneHNz9g19rnkvsL+lBliGNzINa2qeoJbbWewUw1dzix4CEE4vL1XiAnPjA5bvfpReh1+pPRfG5EyJ+GKHhrGZJHiBqsLOD6pmIT70fUkFyGl28evR29KXbWO1RCYLVWE89oQP5FnpnFcJeXQV88kt8ZU0+j+k3vnz1krRSPuiQbDeT7d3jhN0WW+A5GJ6KPmrZh/M0Ui6/FDym4hw== 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=8hyc1gYjkQSNUcPHumH3asWSUedWYGBF6sFLzfHw9Rk=; b=SNs+VH8ZmK3exX4+DMMHECb3lV6KNu5ByJP6j9Tjb9qKpGC/RpZVcCh9B4ON7Xsz32Se4Gse4Nx26baq4157oLjPehqSt0wCPcrZcEVHC7UJZPaXe9I9S/Ad06rkvsApYAPAozONHiY/TLZtHMC1rLWX3SwEHYfYxk9vMIPiF6Ul2zRTaU/iVycaIyP3suqKb20QtHxxGaGgPfqtkpg5UzUEOsedCaBZKGBiivisSpnAJ9HsviYklMTEO1fM480vwtDrfHj9knxWNdRT78hJfGu92CA+ONkkq2pwlIYsFATB1qWi1s01m8fELQxvW9CU5plT20foQT8hqMONaPQH0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) by AS8PR08MB9954.eurprd08.prod.outlook.com (2603:10a6:20b:638::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.6; Thu, 22 Dec 2022 17:43:26 +0000 Received: from AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::8256:29ca:bcd8:b754]) by AS8PR08MB6678.eurprd08.prod.outlook.com ([fe80::8256:29ca:bcd8:b754%5]) with mapi id 15.20.5944.011; Thu, 22 Dec 2022 17:43:26 +0000 Date: Thu, 22 Dec 2022 17:43:21 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 9/8] middle-end: Allow build_popcount_expr to use an IFN Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: LO4P302CA0044.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:317::10) To AS8PR08MB6678.eurprd08.prod.outlook.com (2603:10a6:20b:398::8) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6678:EE_|AS8PR08MB9954:EE_|DBAEUR03FT012:EE_|AS8PR08MB6069:EE_ X-MS-Office365-Filtering-Correlation-Id: be21a285-f5b0-40ac-0416-08dae4440cab x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Frm0l7gZQU0lr1BcyREWOleU1GdvHIA8NevuqyiQX2Zbjzwf468Wz+7CwmsLd2QH4p2w4hDemhV2sS281y8qvfD2p7g9fFf+d/wpNUFCyQ8JR67mfhUOn4MEVTecEoF384F7pdxUERighPVNIE1ey1l1Ea0UQct5jytufryPJb//REr7HQ+ENIf3VgK7X0KdVWGZRP7Y9wwlLlkM/DUUMXiyPWMgA1FSi3RIMk5kv/r1d9r0jtN9fIomgDemhj23S9rWx295E0SX86XW32fFPUiT7uDN1njKpiNb8haEMHupJ3C24pFdQ5VgTMy11SE6d46jzUXNvu5GL+G/le5Zr6B1BhpYkiEksjXMusSohcr7vQAERbtFVDd92Cob+kO6vhG4g9aOCxfmgj7HQ0tOdv4J3R5+YzvGBKUUuLW9POwUVrPT5nNWiMiQYMR4MttxhzhUrQ7iTWv1fGGHUCjUsFYIwcTnPA/jAVcjgR3HnEUXPsG8M7h7lBXSAa1ZiT7aqIwz5V7bH1EGCK90uSQZLGQZBEjleCczFca7uQhXtiFn4Lu8ogT9MqNO6670Owkh53TCoH7q2aS9gwEM3St9Q9y3BojE2eXjzLp+5SeKc3W3GmvDuqZVZ3i4PPrlfCWSumnQgMRPF/cjn6zuGHcHmV/pWBHIibzFCVP6StVdJ//UrSNorkU76gY6ke7s9XmrIOVArK9aCqNUxEPacWurxQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6678.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(376002)(346002)(366004)(39860400002)(396003)(136003)(451199015)(8676002)(86362001)(66476007)(66556008)(66946007)(6512007)(6486002)(478600001)(186003)(6666004)(6506007)(6916009)(316002)(26005)(38100700002)(2906002)(41300700001)(5660300002)(84970400001)(8936002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9954 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 274a0f43-8089-4666-939b-08dae44406ef X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5VfpzJuA+UngdG5OvTuPH3Fm6qtiEXdvl5ihKNn+afrvi3DSj7BnjbC2NqaQSwtKqzZG5gI6mHeiv8pWLDkrg8vgdnHPMq5cVr5yIiQbqliJRewiX7+9Ap6685nsfgpmUbMbZCHg5DwK9ObBh8sGZslLMlDUv1wlETVtnPVwK69CWI2i+WfQeiaWFgJr1etimJO4wYIuMcVNZbfMmEDchVBtmqJk8eGpkLnIpO30i363QJYXfae1i+PcVM70IaGEOnB6GO8ga72962b2XfsyqwWUR12OwblgUII/IMTL24gGPaikE/J40j4oNTPgVyuDqORWFfD64N7yq3C512xcnDN8ivwFgOBx+kTzslnWKKUb0GvtK/qkBT0wpzxFKOx180830J9CsMVdwm3gsBI5gF+VcpfxHZbW8z+AzM0avFpBSSI1nxQlo17jA6N+8iYfSUAkXw+7BzybM0T76q/R94EbE5UbcO98r8cfQ96CE5MrQQcXJvU8NFAyu3j6dMTD0dQeMj+qtFPT55WcTcP2LTk7I6l+/guQRT1HmuvqE3KcPdikC76agP8Xp/NMe3ZM4lyPFOEywnGe/8aaEeZU5mhRxzcQ7dJIAw4Hr3ZL7VY5AQCBnQkqSvpovCoIgX0Z5k8lP0iITrXH2Xlvo7p9Ecgh8B0tqXKtjEUdO2RV/90492cnrOhzYsFirayqHf5DbliV76RvA+tgVOIfZLjiSp+b+sS0dPRWdJwQksynKV1dsQzuv8BLl/dAJg++7A0tPp3Eeu3N1rkZ9nwzwPTktA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(39860400002)(136003)(396003)(346002)(451199015)(40470700004)(46966006)(36840700001)(40480700001)(336012)(86362001)(40460700003)(81166007)(41300700001)(70586007)(44832011)(5660300002)(8936002)(8676002)(6506007)(478600001)(6486002)(6666004)(6916009)(82310400005)(26005)(316002)(82740400003)(70206006)(186003)(356005)(6512007)(47076005)(2906002)(36860700001)(84970400001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2022 17:43:34.7789 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be21a285-f5b0-40ac-0416-08dae4440cab X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6069 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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 Carlotti via Gcc-patches From: Andrew Carlotti Reply-To: Andrew Carlotti Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Bootstrapped and regression tested on aarch64-unknown-linux-gnu and x86_64-pc-linux-gnu - ok to merge? gcc/ChangeLog: * tree-ssa-loop-niter.cc (build_popcount_expr): Add IFN support. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/pr86544.C: Add .POPCOUNT to tree scan regex. * gcc.dg/tree-ssa/popcount.c: Likewise. * gcc.dg/tree-ssa/popcount2.c: Likewise. * gcc.dg/tree-ssa/popcount3.c: Likewise. * gcc.target/aarch64/popcount4.c: Likewise. * gcc.target/i386/pr95771.c: Likewise, and... * gcc.target/i386/pr95771-2.c: ...split int128 test from above, since this would emit just a single IFN if a TI optab is added. diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr86544.C b/gcc/testsuite/g++.dg/tree-ssa/pr86544.C index ef438916a8019320564f444ace08e2f4b4190684..50befb36bac75de1cfa282e38358278b3288bd1c 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr86544.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr86544.C @@ -12,5 +12,5 @@ int PopCount (long b) { return c; } -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "if" 0 "phiopt4" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount.c index b4694109411a4631697463519acbe7d9df65bf6e..efd906a0f5447f0beb3752eded3756999b02e6e6 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount.c @@ -39,4 +39,4 @@ void PopCount3 (long b1) { } } -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 3 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 3 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c index ef73e345573de721833e98e89c252640a55f7c60..ae38a329bd4d868a762300d3218d68864c0fc4be 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount2.c @@ -26,4 +26,4 @@ int main() return 0; } -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c index ef438916a8019320564f444ace08e2f4b4190684..50befb36bac75de1cfa282e38358278b3288bd1c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount3.c @@ -12,5 +12,5 @@ int PopCount (long b) { return c; } -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 1 "optimized" } } */ /* { dg-final { scan-tree-dump-times "if" 0 "phiopt4" } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/popcount4.c b/gcc/testsuite/gcc.target/aarch64/popcount4.c index ee55b2e335223053ca024e95b7a13aa4af32550e..8aa15ff018d4b5fc6bb59e52af20d5c33cea2ee0 100644 --- a/gcc/testsuite/gcc.target/aarch64/popcount4.c +++ b/gcc/testsuite/gcc.target/aarch64/popcount4.c @@ -11,4 +11,4 @@ int PopCount (long b) { return c; } -/* { dg-final { scan-tree-dump-times "__builtin_popcount" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_popcount|\\.POPCOUNT" 0 "optimized" } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr95771-2.c b/gcc/testsuite/gcc.target/i386/pr95771-2.c new file mode 100644 index 0000000000000000000000000000000000000000..1db9dc94d0b66477667624012221d6844c141a26 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr95771-2.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/95771 */ +/* { dg-do compile } */ +/* { dg-require-effective-target int128 } */ +/* { dg-options "-O2 -mpopcnt -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump " = __builtin_popcount| = \\.POPCOUNT" "optimized" } } */ + +int +corge (unsigned __int128 x) +{ + int i = 0; + while (x) + { + x &= x - 1; + ++i; + } + return i; +} diff --git a/gcc/testsuite/gcc.target/i386/pr95771.c b/gcc/testsuite/gcc.target/i386/pr95771.c index d7b67017800b705b9854f561916c20901ea76803..d41be445f4a68613a082b8956fea3ceaf33d7e0f 100644 --- a/gcc/testsuite/gcc.target/i386/pr95771.c +++ b/gcc/testsuite/gcc.target/i386/pr95771.c @@ -1,8 +1,7 @@ /* PR tree-optimization/95771 */ /* { dg-do compile } */ /* { dg-options "-O2 -mpopcnt -fdump-tree-optimized" } */ -/* { dg-final { scan-tree-dump-times " = __builtin_popcount" 6 "optimized" { target int128 } } } */ -/* { dg-final { scan-tree-dump-times " = __builtin_popcount" 4 "optimized" { target { ! int128 } } } } */ +/* { dg-final { scan-tree-dump-times " = __builtin_popcount| = \\.POPCOUNT" 4 "optimized" } } */ int foo (unsigned char x) @@ -51,17 +50,3 @@ qux (unsigned long long x) } return i; } - -#ifdef __SIZEOF_INT128__ -int -corge (unsigned __int128 x) -{ - int i = 0; - while (x) - { - x &= x - 1; - ++i; - } - return i; -} -#endif diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 9c2f9f3d5f6205bb5e7f490257800c660fdd0b8d..cc53b27329f8518bc2cacef1830768a140331b31 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2033,11 +2033,18 @@ static tree build_popcount_expr (tree src) { tree fn; + bool use_ifn = false; int prec = TYPE_PRECISION (TREE_TYPE (src)); int i_prec = TYPE_PRECISION (integer_type_node); int li_prec = TYPE_PRECISION (long_integer_type_node); int lli_prec = TYPE_PRECISION (long_long_integer_type_node); - if (prec <= i_prec) + + tree utype = unsigned_type_for (TREE_TYPE (src)); + src = fold_convert (utype, src); + + if (direct_internal_fn_supported_p (IFN_POPCOUNT, utype, OPTIMIZE_FOR_BOTH)) + use_ifn = true; + else if (prec <= i_prec) fn = builtin_decl_implicit (BUILT_IN_POPCOUNT); else if (prec == li_prec) fn = builtin_decl_implicit (BUILT_IN_POPCOUNTL); @@ -2046,12 +2053,11 @@ build_popcount_expr (tree src) else return NULL_TREE; - tree utype = unsigned_type_for (TREE_TYPE (src)); - src = fold_convert (utype, src); - if (prec < i_prec) - src = fold_convert (unsigned_type_node, src); tree call; - if (prec == 2 * lli_prec) + if (use_ifn) + call = build_call_expr_internal_loc (UNKNOWN_LOCATION, IFN_POPCOUNT, + integer_type_node, 1, src); + else if (prec == 2 * lli_prec) { tree src1 = fold_convert (long_long_unsigned_type_node, fold_build2 (RSHIFT_EXPR, TREE_TYPE (src), @@ -2064,7 +2070,12 @@ build_popcount_expr (tree src) call = fold_build2 (PLUS_EXPR, integer_type_node, call1, call2); } else - call = build_call_expr (fn, 1, src); + { + if (prec < i_prec) + src = fold_convert (unsigned_type_node, src); + + call = build_call_expr (fn, 1, src); + } return call; }