From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 5FF79385AC31; Wed, 17 Nov 2021 23:40:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FF79385AC31 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 r12-5358] Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type is a nop convert X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 0e4a8656e818b669129a670057cbc21e5b723c18 X-Git-Newrev: 32221357007666124409ec3ee0d3a1cf263ebc9e Message-Id: <20211117234013.5FF79385AC31@sourceware.org> Date: Wed, 17 Nov 2021 23:40:13 +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: Wed, 17 Nov 2021 23:40:13 -0000 https://gcc.gnu.org/g:32221357007666124409ec3ee0d3a1cf263ebc9e commit r12-5358-g32221357007666124409ec3ee0d3a1cf263ebc9e Author: Andrew Pinski Date: Mon Nov 15 09:31:20 2021 +0000 Fix PR tree-optimization/103228 and 103228: folding of (type) X op CST where type is a nop convert Currently we fold (type) X op CST into (type) (X op ((type-x) CST)) when the conversion widens but not when the conversion is a nop. For the same reason why we move the widening conversion (the possibility of removing an extra conversion), we should do the same if the conversion is a nop. Committed as approved with the comment change. PR tree-optimization/103228 PR tree-optimization/55177 gcc/ChangeLog: * match.pd ((type) X bitop CST): Also do this transformation for nop conversions. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr103228-1.c: New test. * gcc.dg/tree-ssa/pr55177-1.c: New test. Diff: --- gcc/match.pd | 6 ++++-- gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c | 11 +++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 89df7b2a174..77d848d631e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1616,8 +1616,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) Restrict it to GIMPLE to avoid endless recursions. */ && (bitop != BIT_AND_EXPR || GIMPLE) && (/* That's a good idea if the conversion widens the operand, thus - after hoisting the conversion the operation will be narrower. */ - TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type) + after hoisting the conversion the operation will be narrower. + It is also a good if the conversion is a nop as moves the + conversion to one side; allowing for combining of the conversions. */ + TYPE_PRECISION (TREE_TYPE (@0)) <= TYPE_PRECISION (type) /* It's also a good idea if the conversion is to a non-integer mode. */ || GET_MODE_CLASS (TYPE_MODE (type)) != MODE_INT diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c new file mode 100644 index 00000000000..a7539819cf2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103228-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +int f(int a, int b) +{ + b|=1u; + b|=2; + return b; +} +/* { dg-final { scan-tree-dump-times "\\\| 3" 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "\\\| 1" 0 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "\\\| 2" 0 "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c new file mode 100644 index 00000000000..de1a264345c --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr55177-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +extern int x; + +void foo(void) +{ + int a = __builtin_bswap32(x); + a &= 0x5a5b5c5d; + x = __builtin_bswap32(a); +} + +/* { dg-final { scan-tree-dump-times "__builtin_bswap32" 0 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "& 1566333786" 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times "& 1515936861" 0 "optimized"} } */