From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 39FB938582B1 for ; Wed, 29 Jun 2022 09:13:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 39FB938582B1 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 1A44F21DCE for ; Wed, 29 Jun 2022 09:13:40 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 13D7A2C141 for ; Wed, 29 Jun 2022 09:13:39 +0000 (UTC) Date: Wed, 29 Jun 2022 09:13:39 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106112 - fix CSE from wider operation User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jun 2022 09:13:43 -0000 Message-ID: <20220629091339.6tgb_9pMDjOz8QMi0mhL_yZSQlpxuuppTEQSEKOEBV0@z> The following fixes a mistake in looking up an extended operand in the CSE of a truncated operation. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 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. --- gcc/testsuite/gcc.dg/torture/pr106112.c | 16 ++++++++++++++++ gcc/tree-ssa-sccvn.cc | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr106112.c 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; } -- 2.35.3