From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id C503E3887B05; Sun, 11 Dec 2022 15:44:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C503E3887B05 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670773483; bh=TlQx6Tn+vE9doCukWsEm8l1uiKy7tFWnXgPtUqkgl7s=; h=From:To:Subject:Date:From; b=T1fAgoCXtKGxo1sxhSaaEurNFb2EEtc29kBJuKBfiI6MnXZHbmSgidSy810i4FOdL DUAnRFdBwsbexTd0X78CaeyqEfLoFYI1ugJhE9sr6CtaZFP1QJTIBY2+Z7AZl3O3I3 dtfXM9s3n7RkSXM1Vj4HETEm5Dpao/4Fr7yu2Jds= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4601] d: Expand bsr intrinsic as `clz(arg) ^ (argsize - 1)' X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/master X-Git-Oldrev: d13b86f932ff7b9d8f41483fd869c637b67d4dec X-Git-Newrev: cc7f509d3c0b3ab63891cf7ca2def0fdfb3642c4 Message-Id: <20221211154443.C503E3887B05@sourceware.org> Date: Sun, 11 Dec 2022 15:44:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cc7f509d3c0b3ab63891cf7ca2def0fdfb3642c4 commit r13-4601-gcc7f509d3c0b3ab63891cf7ca2def0fdfb3642c4 Author: Iain Buclaw Date: Sat Dec 10 17:17:35 2022 +0100 d: Expand bsr intrinsic as `clz(arg) ^ (argsize - 1)' 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. gcc/d/ChangeLog: * intrinsics.cc (expand_intrinsic_bsf): Fix comment. (expand_intrinsic_bsr): Use BIT_XOR_EXPR instead of MINUS_EXPR. Diff: --- 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