From patchwork Sun Dec 11 15:45:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 32196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1818119wrr; Sun, 11 Dec 2022 07:46:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AkDDvdiGWBaMKU5U3HXAJVucuH7pgGg+G3TzpuVxGTFaz1iZ9+pOSscg5sf7QGiOXhlQy X-Received: by 2002:a17:906:710:b0:7c0:f462:575a with SMTP id y16-20020a170906071000b007c0f462575amr11137407ejb.29.1670773578053; Sun, 11 Dec 2022 07:46:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670773578; cv=none; d=google.com; s=arc-20160816; b=vp29RoVAQtxFYQYl/zIZJY5in4lToWTb9xuchHcJxYxsT/nDvaiv3Q+gZSlY/2ouHO 9BW+u9pmqlncpxuTArwt1qQVBcOzCycgLBKx2K6MpFTs41fPvAswk7OD/Tpu/LNd0F3r FNF6jPsgvhR+0ZyYA4rVZYrrydKdtHZs9phd14GEmcRUXDwlddcZO8m78mgKuN64guiO EruOeEudOL/1mQvujQSA12EwsFFj91cO9QtHSANclPWuwCArumq7X1H9v4N50VaJcpPz 0oe5sgtHP+6MwFQ6+iUB5WA0STvYEu/ikizvKmfnN6VEEwS7M58vKnq66llOnGRaIdMY 3B+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=LCdyhGS5j/uls0fowH3ozUOxNlAPMzs4MqgPAYodPNU=; b=f4n8r0PVLL9xHtU7S/QEpsoUQkfYOrkcQTSqf4WGi2FSr0Jpt9C6wRFUy3N8pdhMVY FHQSVuPtpIKLvPg0mbYuQ6i8AP+eEkQ/uDypXlOvYYKJo0pvTKOSGg4QxQ+GCtPn02Pu ZIPhxWq71+v0hiE6sIkeEDgwv+qs9Mx3ex3nJT95MTX3LkWjZpBRXwe9ERy5MMyMwSRs vJTlTueugqj6DpPXJTqT7GMrOvQ2QbB9WooBH6+I7u/NQc493rimCZaJt2bEfwPTWjyC 9vPF7aNkjCWLeu986B2idN9n6JdoRgubxptvFRture7YI+5I0etqT74fPSUO8Z44E9Q+ 0tJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p4eCBQhh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dt18-20020a170907729200b0077eca9fa444si3810068ejc.187.2022.12.11.07.46.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 07:46:18 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=p4eCBQhh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B803D384D6FE for ; Sun, 11 Dec 2022 15:46:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B803D384D6FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670773576; bh=LCdyhGS5j/uls0fowH3ozUOxNlAPMzs4MqgPAYodPNU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=p4eCBQhharr0Wj1XzdXV4wuIK4UclCzgbF6ylvxL6Hr+78yFQbpXEMO6S9bfpqhr5 I7Z3MGq1YO5C2Hlk7Wp0ONr3Qz958M/9ZHL4kFFr911V3fQg//wEGEjt7Wk173l4Db kwF1t1XYXQy+VuoIap0IOaYMTNqCDxNuyusPfigg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by sourceware.org (Postfix) with ESMTPS id 74C023864A05 for ; Sun, 11 Dec 2022 15:45:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74C023864A05 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4NVTc63fbcz9sPp; Sun, 11 Dec 2022 16:45:26 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Expand bsr intrinsic as `clz(arg) ^ (argsize - 1)' Date: Sun, 11 Dec 2022 16:45:19 +0100 Message-Id: <20221211154519.2681701-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4NVTc63fbcz9sPp X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751933075118819999?= X-GMAIL-MSGID: =?utf-8?q?1751933075118819999?= Hi, This patch tweaks the code expansion of the D intrinsic bsr() function. As well as removing unnecessary casts, this results in less temporaries being generated during the initial gimple lowering pass. Otherwise the code generated is identical to the former intrinsic expansion. Bootstrapped and regression tested on x86_64-linux-gnu/-m32. Committed to mainline. Regards, Iain. --- gcc/d/ChangeLog: * intrinsics.cc (expand_intrinsic_bsf): Fix comment. (expand_intrinsic_bsr): Use BIT_XOR_EXPR instead of MINUS_EXPR. --- gcc/d/intrinsics.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/gcc/d/intrinsics.cc b/gcc/d/intrinsics.cc index 6d9f74a6d7a..46380e512c4 100644 --- a/gcc/d/intrinsics.cc +++ b/gcc/d/intrinsics.cc @@ -525,7 +525,7 @@ call_builtin_fn (tree callexp, built_in_function code, int n, ...) static tree expand_intrinsic_bsf (tree callexp) { - /* The bsr() intrinsic gets turned into __builtin_ctz(arg). + /* The bsf() intrinsic gets turned into __builtin_ctz(arg). The return value is supposed to be undefined if arg is zero. */ tree arg = CALL_EXPR_ARG (callexp, 0); int argsize = TYPE_PRECISION (TREE_TYPE (arg)); @@ -554,11 +554,11 @@ expand_intrinsic_bsf (tree callexp) static tree expand_intrinsic_bsr (tree callexp) { - /* The bsr() intrinsic gets turned into (size - 1) - __builtin_clz(arg). + /* The bsr() intrinsic gets turned into __builtin_clz(arg) ^ (size - 1). The return value is supposed to be undefined if arg is zero. */ tree arg = CALL_EXPR_ARG (callexp, 0); - tree type = TREE_TYPE (arg); - int argsize = TYPE_PRECISION (type); + tree type = TREE_TYPE (callexp); + int argsize = TYPE_PRECISION (TREE_TYPE (arg)); /* Which variant of __builtin_clz* should we call? */ built_in_function code = (argsize <= INT_TYPE_SIZE) ? BUILT_IN_CLZ @@ -570,13 +570,8 @@ expand_intrinsic_bsr (tree callexp) tree result = call_builtin_fn (callexp, code, 1, arg); - /* Handle int -> long conversions. */ - if (TREE_TYPE (result) != type) - result = fold_convert (type, result); - - result = fold_build2 (MINUS_EXPR, type, - build_integer_cst (argsize - 1, type), result); - return fold_convert (TREE_TYPE (callexp), result); + return fold_build2 (BIT_XOR_EXPR, type, result, + build_integer_cst (argsize - 1, type)); } /* Expand a front-end intrinsic call to INTRINSIC, which is either a call to