From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2028) id BD9883858D35; Fri, 15 Sep 2023 13:47:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD9883858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694785640; bh=qnRhCiELcDLARLBMlnC2i9Z7LsynokP6WVAF1faCDmk=; h=From:To:Subject:Date:From; b=JcvVgaXw5Yazo2051J3115MViqKea4GGmVwgb0EtmaKF0WWGousEBw5v6DrPFq5gK XS9Y+tH1A0Nd1v485TB2QRGAP2Qde6vTo46WOHdX+gmuS9mqdBV4meD2BPMVz7p/Sw hv3Kk1nebeI1CssxhUHzV8hWWyIL4z3Fd/1xCPw0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Qing Zhao To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4034] Fix PR111407--SSA corruption due to widening_mul opt on conflict across an abnormal edge X-Act-Checkin: gcc X-Git-Author: Qing Zhao X-Git-Refname: refs/heads/master X-Git-Oldrev: 540a1d936d8f73f5e2efdefafd8342ec27773ae8 X-Git-Newrev: 4aca1cfd6235090e48a53dab734437740671bbf3 Message-Id: <20230915134720.BD9883858D35@sourceware.org> Date: Fri, 15 Sep 2023 13:47:20 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4aca1cfd6235090e48a53dab734437740671bbf3 commit r14-4034-g4aca1cfd6235090e48a53dab734437740671bbf3 Author: Qing Zhao Date: Fri Sep 15 13:46:52 2023 +0000 Fix PR111407--SSA corruption due to widening_mul opt on conflict across an abnormal edge This is a bug in tree-ssa-math-opts.cc, when applying the widening mul optimization, the compiler needs to check whether the operand is in a ABNORMAL PHI, if YES, we should avoid the transformation. PR tree-optimization/111407 gcc/ChangeLog: * tree-ssa-math-opts.cc (convert_mult_to_widen): Avoid the transform when one of the operands is subject to abnormal coalescing. gcc/testsuite/ChangeLog: * gcc.dg/pr111407.c: New test. Diff: --- gcc/testsuite/gcc.dg/pr111407.c | 21 +++++++++++++++++++++ gcc/tree-ssa-math-opts.cc | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/testsuite/gcc.dg/pr111407.c b/gcc/testsuite/gcc.dg/pr111407.c new file mode 100644 index 00000000000..a171074753f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr111407.c @@ -0,0 +1,21 @@ +/* PR tree-optimization/111407*/ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +enum { SEND_TOFILE } __sigsetjmp(); +void fclose(); +void foldergets(); +void sendpart_stats(int *p1, int a1, int b1) { + int *a = p1; + fclose(); + p1 = 0; + long t = b1; + if (__sigsetjmp()) { + { + long t1 = a1; + a1+=1; + fclose(a1*(long)t1); + } + } + if (p1) + fclose(); +} diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index 3db69ad5733..51c14d6bad9 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -2755,6 +2755,14 @@ convert_mult_to_widen (gimple *stmt, gimple_stmt_iterator *gsi) if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2)) return false; + /* if any one of rhs1 and rhs2 is subject to abnormal coalescing, + avoid the tranform. */ + if ((TREE_CODE (rhs1) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)) + || (TREE_CODE (rhs2) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2))) + return false; + to_mode = SCALAR_INT_TYPE_MODE (type); from_mode = SCALAR_INT_TYPE_MODE (type1); if (to_mode == from_mode)