From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id DC2E7385C311; Wed, 29 Jun 2022 09:15:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC2E7385C311 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1341] tree-optimization/106112 - fix CSE from wider operation X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: d42c1598e52ec0a33fbcc4efa39f4c299d09a3fc X-Git-Newrev: 2dbb45d6dc0d20dc159b3d8e27ebb6825074827a Message-Id: <20220629091505.DC2E7385C311@sourceware.org> Date: Wed, 29 Jun 2022 09:15:05 +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, 29 Jun 2022 09:15:06 -0000 https://gcc.gnu.org/g:2dbb45d6dc0d20dc159b3d8e27ebb6825074827a commit r13-1341-g2dbb45d6dc0d20dc159b3d8e27ebb6825074827a Author: Richard Biener Date: Tue Jun 28 13:57:29 2022 +0200 tree-optimization/106112 - fix CSE from wider operation The following fixes a mistake in looking up an extended operand in the CSE of a truncated operation. 2022-06-28 Richard Biener PR tree-optimization/106112 * tree-ssa-sccvn.cc (valueized_wider_op): Properly extend a constant operand according to its type. * gcc.dg/torture/pr106112.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr106112.c | 16 ++++++++++++++++ gcc/tree-ssa-sccvn.cc | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr106112.c b/gcc/testsuite/gcc.dg/torture/pr106112.c new file mode 100644 index 00000000000..bd7f63c0935 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106112.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ + +__INT32_TYPE__ a = 5, b, c, d; +__UINT64_TYPE__ e = 20862985922; +int main() +{ + __UINT32_TYPE__ f = 4294967292; + e = e | f; + c = -1 % ((~f ^ 4294967292) - (e - d)); + b = ~-~e % ~-d; + if (b) + a = 0; + if (a < 1) + __builtin_abort(); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 5214f142f52..9deedeac378 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -4983,7 +4983,7 @@ valueized_wider_op (tree wide_type, tree op, bool allow_truncate) /* For constants simply extend it. */ if (TREE_CODE (op) == INTEGER_CST) - return wide_int_to_tree (wide_type, wi::to_wide (op)); + return wide_int_to_tree (wide_type, wi::to_widest (op)); return NULL_TREE; }