From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 9BD0B3858C39; Fri, 19 Nov 2021 12:07:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BD0B3858C39 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-5400] Fix tree-optimization/103314 : Limit folding of (type) X op CST where type is a nop convert to gimpl X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 74a4ece02df1b1b6f396fd0e24dbbf8b0897858a X-Git-Newrev: ea2954df43d4162af23a20c84f4c5485463977ac Message-Id: <20211119120715.9BD0B3858C39@sourceware.org> Date: Fri, 19 Nov 2021 12:07:15 +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: Fri, 19 Nov 2021 12:07:15 -0000 https://gcc.gnu.org/g:ea2954df43d4162af23a20c84f4c5485463977ac commit r12-5400-gea2954df43d4162af23a20c84f4c5485463977ac Author: Andrew Pinski Date: Fri Nov 19 01:42:41 2021 +0000 Fix tree-optimization/103314 : Limit folding of (type) X op CST where type is a nop convert to gimple There is some re-association code in fold_binary which conflicts with this optimization due keeping around some "constants" which are not INTEGER_CST (1 << -1) so we end up in an infinite loop because of that. So we need to limit this case to GIMPLE level only. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/103314 gcc/ChangeLog: * match.pd ((type) X op CST): Restrict the equal TYPE_PRECISION case to GIMPLE only. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr103314-1.c: New test. Diff: --- gcc/match.pd | 6 +++++- gcc/testsuite/gcc.c-torture/compile/pr103314-1.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 4042b535b85..e5985defe6f 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1619,7 +1619,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) 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) + TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type) + /* The conversion check for being a nop can only be done at the gimple + level as fold_binary has some re-association code which can conflict + with this if there is a "constant" which is not a full INTEGER_CST. */ + || (GIMPLE && 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.c-torture/compile/pr103314-1.c b/gcc/testsuite/gcc.c-torture/compile/pr103314-1.c new file mode 100644 index 00000000000..f4a63130421 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr103314-1.c @@ -0,0 +1,6 @@ +/* { dg-options "" } */ +int main() { + int t = 1; + unsigned c = 0, d1 = t ? 1 ^ c ^ 1 >> (-1) : 0; /* { dg-warning "is negative" } */ + return d1; +}