From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id CC9033858D35; Fri, 16 Jun 2023 17:48:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC9033858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686937735; bh=0ypbVUaXhGkSflk7yv0YaXd8MlumPtyPp1Tn6PW4S6I=; h=From:To:Subject:Date:From; b=GQ0GrG0lpeGI1tJLw0M7bgy4oX8QrDj2fb9VkjKaEOj/yVQ4olHvQUiuTdpggGi8l I6aKXasJSEP74+cUwNwqu0EBIv7JeIG8tLvhVZwo+/TK3+bYrpSyyajn0U2C/+rfmb wxwVO7LGiVF0jpCyFt4yOeduqpyO3pmUtwaeYpuI= 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 r14-1895] tree-ssa-math-opts: Fix up uaddc/usubc pattern matching [PR110271] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: ea1cd66f2200839d46a8b4dc140d18c00b849c82 X-Git-Newrev: 5b67116a85298bbe358b036d34ad23119cebbdac Message-Id: <20230616174855.CC9033858D35@sourceware.org> Date: Fri, 16 Jun 2023 17:48:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5b67116a85298bbe358b036d34ad23119cebbdac commit r14-1895-g5b67116a85298bbe358b036d34ad23119cebbdac Author: Jakub Jelinek Date: Fri Jun 16 19:46:36 2023 +0200 tree-ssa-math-opts: Fix up uaddc/usubc pattern matching [PR110271] The following testcase ICEs, because I misremembered what the return value from match_arith_overflow is. It isn't true if __builtin_*_overflow was matched, but it is true only in the BIT_NOT_EXPR case if stmt was removed. So, if match_arith_overflow matches something, gsi_stmt (gsi) will not be stmt and match_uaddc_usubc will be confused and can ICE. The following patch fixes it by checking if gsi_stmt (gsi) == stmt, in that case we know it is still a PLUS_EXPR/MINUS_EXPR and we can try to pattern match it further as UADDC/USUBC. 2023-06-16 Jakub Jelinek PR tree-optimization/110271 * tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children) : Ignore return value from match_arith_overflow, instead call match_uaddc_usubc only if gsi_stmt (gsi) is still stmt. * gcc.c-torture/compile/pr110271.c: New test. Diff: --- gcc/testsuite/gcc.c-torture/compile/pr110271.c | 24 ++++++++++++++++++++++++ gcc/tree-ssa-math-opts.cc | 9 ++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110271.c b/gcc/testsuite/gcc.c-torture/compile/pr110271.c new file mode 100644 index 00000000000..0cb91beaaea --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr110271.c @@ -0,0 +1,24 @@ +/* PR tree-optimization/110271 */ + +unsigned a, b, c, d, e; + +void +foo (unsigned *x, int y, unsigned int *z) +{ + for (int i = 0; i < y; i++) + { + b += d; + a += b < d; + a += c = (__PTRDIFF_TYPE__) x > 3; + d = z[1] + (a < c); + a += e; + d += a < e; + } +} + +void +bar (unsigned int *z) +{ + unsigned *x = x; + foo (x, 9, z); +} diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index b2764d4bfc1..d2b71295f96 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -5558,9 +5558,12 @@ math_opts_dom_walker::after_dom_children (basic_block bb) case PLUS_EXPR: case MINUS_EXPR: - if (!convert_plusminus_to_widen (&gsi, stmt, code) - && !match_arith_overflow (&gsi, stmt, code, m_cfg_changed_p)) - match_uaddc_usubc (&gsi, stmt, code); + if (!convert_plusminus_to_widen (&gsi, stmt, code)) + { + match_arith_overflow (&gsi, stmt, code, m_cfg_changed_p); + if (gsi_stmt (gsi) == stmt) + match_uaddc_usubc (&gsi, stmt, code); + } break; case BIT_NOT_EXPR: