From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id BF11A393BA41; Sat, 17 Sep 2022 06:19:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF11A393BA41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663395588; bh=hwayc5RrjE2fVmGRhjBbpxiCr9WjBoQA/BDG3sxvG+I=; h=From:To:Subject:Date:From; b=w1eSqNrDcw30u9ZIJ1Og0MQ6hExTEJBpwbLwo0+8SGg/kotfENO5kZ+O7r4xzFJT8 YvfE26qfwUUEZvm/mfl48Wmt3iUOnuYyBdj8FtT4Ax0VlWqyic1kDCAVHsCqDCZo9h kVFH+1h9UvEOsbfHB6qGeFNiwfobKrrpWo6E3U9o= 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 r13-2709] reassoc: Fix up recent regression in optimize_range_tests_cmp_bitwise [PR106958] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 7ee0fa100f0f28d7b88237d520131e07b7b49f0a X-Git-Newrev: 9ac9fde961f76879f0379ff3b2494a2f9ac915f7 Message-Id: <20220917061948.BF11A393BA41@sourceware.org> Date: Sat, 17 Sep 2022 06:19:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9ac9fde961f76879f0379ff3b2494a2f9ac915f7 commit r13-2709-g9ac9fde961f76879f0379ff3b2494a2f9ac915f7 Author: Jakub Jelinek Date: Sat Sep 17 08:18:24 2022 +0200 reassoc: Fix up recent regression in optimize_range_tests_cmp_bitwise [PR106958] As the following testcase reduced from glibc fmtmsg.c shows (it doesn't ICE on x86_64/i686 unfortunately, but does on various other arches), my last optimize_range_tests_cmp_bitwise change wasn't fully correct. The intent was to let all pointer operands be cast to pointer_sized_int_node first in addition to the other casts (to type1) which are done for id >= l cases. But one spot I've touched used always cast to type1 (note, the (b % 4) == 3 case is impossible for pointer operands because that is for !TYPE_UNSIGNED operands and pointers are TYPE_UNSIGNED) and in the other spot the cast would be done only for id >= l if not useless, but for pointers we need to cast it always. 2022-09-17 Jakub Jelinek PR tree-optimization/106958 * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): If id >= l, cast op to type1, otherwise to pointer_sized_int_node. If type has pointer type, cast exp to pointer_sized_int_node even when id < l. * gcc.c-torture/compile/pr106958.c: New test. Diff: --- gcc/testsuite/gcc.c-torture/compile/pr106958.c | 13 +++++++++++++ gcc/tree-ssa-reassoc.cc | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106958.c b/gcc/testsuite/gcc.c-torture/compile/pr106958.c new file mode 100644 index 00000000000..98e6554c736 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106958.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/106958 */ + +int a; +void bar (int); + +void +foo (char *x, char *y) +{ + int b = a != 0; + int c = x != 0; + int d = y != 0; + bar (b | c | d); +} diff --git a/gcc/tree-ssa-reassoc.cc b/gcc/tree-ssa-reassoc.cc index f45e552a8cc..c5c8b680c99 100644 --- a/gcc/tree-ssa-reassoc.cc +++ b/gcc/tree-ssa-reassoc.cc @@ -3680,15 +3680,18 @@ optimize_range_tests_cmp_bitwise (enum tree_code opcode, int first, int length, if (id == l || POINTER_TYPE_P (TREE_TYPE (op))) { code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR; - g = gimple_build_assign (make_ssa_name (type1), code, op); + tree type3 = id >= l ? type1 : pointer_sized_int_node; + g = gimple_build_assign (make_ssa_name (type3), code, op); gimple_seq_add_stmt_without_update (&seq, g); op = gimple_assign_lhs (g); } tree type = TREE_TYPE (r->exp); tree exp = r->exp; - if (id >= l && !useless_type_conversion_p (type1, type)) + if (POINTER_TYPE_P (type) + || (id >= l && !useless_type_conversion_p (type1, type))) { - g = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, exp); + tree type3 = id >= l ? type1 : pointer_sized_int_node; + g = gimple_build_assign (make_ssa_name (type3), NOP_EXPR, exp); gimple_seq_add_stmt_without_update (&seq, g); exp = gimple_assign_lhs (g); }