From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E513D393743A; Wed, 8 May 2024 08:18:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E513D393743A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715156304; bh=JBrnbBeas59T2t7tPnq0fhNrIvkLMUIXp6fHS8uwaMs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=L0R+Wmt0MIJE4+AU/mwAK/Uy+kC9hhCFzRikYowJ+XlDfSV0NyFvC6rrD+YqefAHD q4jsm0mW2QQs24ugdbNY5tHyb1a7svlTWCleTeZkPxIMTYPcZM4shaUK/T5t+sHybJ i82qe/kog6QJoFAwhHjLAnxM+3/dGAVwS9MnZQFc= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2) Date: Wed, 08 May 2024 08:18:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114965 --- Comment #13 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:9adec2d91e62a479474ae79df5b455fd4b8463ba commit r15-315-g9adec2d91e62a479474ae79df5b455fd4b8463ba Author: Jakub Jelinek Date: Wed May 8 10:17:32 2024 +0200 reassoc: Fix up optimize_range_tests_to_bit_test [PR114965] The optimize_range_tests_to_bit_test optimization normally emits a range test first: if (entry_test_needed) { tem =3D build_range_check (loc, optype, unshare_expr (exp= ), false, lowi, high); if (tem =3D=3D NULL_TREE || is_gimple_val (tem)) continue; } so during the bit test we already know that exp is in the [lowi, high] range, but skips it if we have range info which tells us this isn't necessary. Also, normally it emits shifts by exp - lowi counter, but has an optimization to use just exp counter if the mask isn't a more expensive constant in that case and lowi is > 0 and high is smaller than prec. The following testcase is miscompiled because the two abnormal cases are triggered. The range of exp is [43, 43][48, 48][95, 95], so we on 64-bit arch decide we don't need the entry test, because 95 - 43 < 64. And we also decide to use just exp as counter, because the range test tests just for exp =3D=3D 43 || exp =3D=3D 48, so high is smaller than = 64 too. Because 95 is in the exp range, we can't do that, we'd either need to do a range test first, i.e. if (exp - 43U <=3D 48U - 43U) if ((1UL << exp) & mask1)) or need to subtract lowi from the shift counter, i.e. if ((1UL << (exp - 43)) & mask2) but can't do both unless r.upper_bound () is < prec. The following patch ensures that. 2024-05-08 Jakub Jelinek PR tree-optimization/114965 * tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Don't= try to optimize away exp - lowi subtraction from shift count unless en= try test is emitted or unless r.upper_bound () is smaller than prec. * gcc.c-torture/execute/pr114965.c: New test.=