From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 4C587385E45F; Tue, 29 Mar 2022 05:53:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C587385E45F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9722] match.pd: Further complex simplification fixes [PR104675] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: b59d29392774b115bea0066b4ad1eb2b959a3a2b X-Git-Newrev: 1a2772a3fe41bc0c33c4620540dae0103dcf7289 Message-Id: <20220329055337.4C587385E45F@sourceware.org> Date: Tue, 29 Mar 2022 05:53:37 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2022 05:53:37 -0000 https://gcc.gnu.org/g:1a2772a3fe41bc0c33c4620540dae0103dcf7289 commit r11-9722-g1a2772a3fe41bc0c33c4620540dae0103dcf7289 Author: Jakub Jelinek Date: Fri Feb 25 21:25:12 2022 +0100 match.pd: Further complex simplification fixes [PR104675] Mark mentioned in the PR further 2 simplifications that also ICE with complex types. For these, eventually (but IMO GCC 13 materials) we could support it for vector types if it would be uniform vector constants. Currently integer_pow2p is true only for INTEGER_CSTs and COMPLEX_CSTs and we can't use bit_and etc. for complex type. 2022-02-25 Jakub Jelinek Marc Glisse PR tree-optimization/104675 * match.pd (t * 2U / 2 -> t & (~0 / 2), t / 2U * 2 -> t & ~1): Restrict simplifications to INTEGRAL_TYPE_P. * gcc.dg/pr104675-3.c : New test. (cherry picked from commit f62115c9b770a66c5378f78a2d5866243d560573) Diff: --- gcc/match.pd | 4 ++-- gcc/testsuite/gcc.dg/pr104675-3.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index c7d13ae39f2..e89601c0c14 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -643,7 +643,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF. */ (simplify (trunc_div (mult @0 integer_pow2p@1) @1) - (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0))) (bit_and @0 { wide_int_to_tree (type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (wi::to_wide (@1)), @@ -652,7 +652,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */ (simplify (mult (trunc_div @0 integer_pow2p@1) @1) - (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && TYPE_UNSIGNED (TREE_TYPE (@0))) (bit_and @0 (negate @1)))) /* Simplify (t * 2) / 2) -> t. */ diff --git a/gcc/testsuite/gcc.dg/pr104675-3.c b/gcc/testsuite/gcc.dg/pr104675-3.c new file mode 100644 index 00000000000..3b2eb649403 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104675-3.c @@ -0,0 +1,29 @@ +/* PR tree-optimization/104675 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +_Complex unsigned int +foo (_Complex unsigned int x) +{ + return (x / 2) * 2; +} + +_Complex unsigned int +bar (_Complex unsigned int x) +{ + return (x * 2) / 2; +} + +_Complex unsigned int +baz (_Complex unsigned int x) +{ + _Complex unsigned int y = x / 2; + return y * 2; +} + +_Complex unsigned int +qux (_Complex unsigned int x) +{ + _Complex unsigned int y = x * 2; + return y / 2; +}