From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 917E9385B500; Fri, 5 Jan 2024 16:09:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 917E9385B500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704470990; bh=cjrUeWLkA/if2eWZYRRjDhCySlKS0aIIrFrCnvPfOAM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Splpgka6mas6ZP834f9sgqjl+2SZ7eOF8DA7ST4HMbgqNvkWK63IHToqCh7fGrkeA SP5qwK1IZXwlI40XzjadK1BLL8eP9ekZ4uSVYfgfAHCXpAQ60HqQCntTBb11YRY89p Sfbp4E+p7nWViAQasASm40i4SwlDr/82YDPzCYJc= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113210] [14 Regression] ICE: tree check: expected integer_cst, have cond_expr in get_len, at tree.h:6481 Date: Fri, 05 Jan 2024 16:09:49 +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: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 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=3D113210 --- Comment #7 from Jakub Jelinek --- Or maybe just a bug in the PLUS_EXPR folding? The code sets NITERSM1 to (short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1= + 255) : 0 and then fold_build2s PLUS_EXPR of that and 1 and somehow it folds to 1, th= at doesn't sound right to me. Now, when folding the + 1 addition just with the second operand, i.e. ~(short unsigned int) (a.0_1 + 255) it correctly folds into -(short unsigned int) (a.0_1 + 255) and obviously the second one to 1. There is also the /* (X + 1) > Y ? -X : 1 simplifies to X >=3D Y ? -X : 1 when X is unsigned, as when X + 1 overflows, X is -1, so -X =3D=3D 1. */ (simplify (cond (gt (plus @0 integer_onep) @1) (negate @0) integer_onep@2) (if (TYPE_UNSIGNED (type)) (cond (ge @0 @1) (negate @0) @2))) match.pd rule, but that I'd think should just fold the whole thing to: (short unsigned int) (a.0_1 + 255) >=3D 256 ? -(short unsigned int) (a.0_1 = + 255) : 1 Though, a.0_1 is unsigned char, so (short unsigned int) (a.0_1 + 255) + 1 >= 256 is actually never true. So guess the folding is correct.=