From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id D4DDA3858D35; Sun, 30 Apr 2023 20:45:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4DDA3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682887537; bh=C7GtteFXLWDre5RqCVhTu6geCcFd/W3NoRha0Ax+q5o=; h=From:To:Subject:Date:From; b=HRt68W5k8Y9L8byaHPyYkcCboaBCM+iKTMMZeC1XeaBZhhKVwi4aqKF+IzV3ACSEP Zs7ug3hdirVsdxTzKAYa6nYX4IIUB5TjjaWFQFmUyJmfzvjjAtemvMlwz0+hi0r/9y k4umCVjHJKUx5yVljvBPbUbIco3mvn0ydK45uor4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-361] PHIOPT: Allow moving of some builtin calls X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 84e7d62c3bccb5e5ff9c37353b026f48e1148450 X-Git-Newrev: 55b708895149ac5e108f50150e12a3c5ba00e83d Message-Id: <20230430204537.D4DDA3858D35@sourceware.org> Date: Sun, 30 Apr 2023 20:45:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:55b708895149ac5e108f50150e12a3c5ba00e83d commit r14-361-g55b708895149ac5e108f50150e12a3c5ba00e83d Author: Andrew Pinski Date: Sun Apr 9 00:20:30 2023 +0000 PHIOPT: Allow moving of some builtin calls While moving working on moving cond_removal_in_builtin_zero_pattern to match, I noticed that functions were not allowed to move as we reject all non-assignments. This changes to allowing a few calls which are known not to throw/trap. Right now it is restricted to ones which cond_removal_in_builtin_zero_pattern handles but adding more is just adding it to the switch statement. gcc/ChangeLog: * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): Allow some builtin/internal function calls which are known not to trap/throw. (phiopt_worker::match_simplify_replacement): Use name instead of getting the lhs again. Diff: --- gcc/tree-ssa-phiopt.cc | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 4b43f1abdbc..024a4362093 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -548,6 +548,7 @@ empty_bb_or_one_feeding_into_p (basic_block bb, { stmt = nullptr; gimple *stmt_to_move = nullptr; + tree lhs; if (empty_block_p (bb)) return true; @@ -592,17 +593,43 @@ empty_bb_or_one_feeding_into_p (basic_block bb, if (gimple_uses_undefined_value_p (stmt_to_move)) return false; - /* Allow assignments and not no calls. + /* Allow assignments but allow some builtin/internal calls. As const calls don't match any of the above, yet they could still have some side-effects - they could contain gimple_could_trap_p statements, like floating point exceptions or integer division by zero. See PR70586. FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p - should handle this. */ + should handle this. + Allow some known builtin/internal calls that are known not to + trap: logical functions (e.g. bswap and bit counting). */ if (!is_gimple_assign (stmt_to_move)) - return false; + { + if (!is_gimple_call (stmt_to_move)) + return false; + combined_fn cfn = gimple_call_combined_fn (stmt_to_move); + switch (cfn) + { + default: + return false; + case CFN_BUILT_IN_BSWAP16: + case CFN_BUILT_IN_BSWAP32: + case CFN_BUILT_IN_BSWAP64: + case CFN_BUILT_IN_BSWAP128: + CASE_CFN_FFS: + CASE_CFN_PARITY: + CASE_CFN_POPCOUNT: + CASE_CFN_CLZ: + CASE_CFN_CTZ: + case CFN_BUILT_IN_CLRSB: + case CFN_BUILT_IN_CLRSBL: + case CFN_BUILT_IN_CLRSBLL: + lhs = gimple_call_lhs (stmt_to_move); + break; + } + } + else + lhs = gimple_assign_lhs (stmt_to_move); - tree lhs = gimple_assign_lhs (stmt_to_move); gimple *use_stmt; use_operand_p use_p;