From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 410273857C75; Fri, 12 Feb 2021 18:56:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 410273857C75 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/99079] Maybe a wrong code since r6-1462-g4ab1e111ef0669bb Date: Fri, 12 Feb 2021 18:56:46 +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: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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: 8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Feb 2021 18:56:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99079 --- Comment #2 from Jakub Jelinek --- Created attachment 50175 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50175&action=3Dedit gcc11-pr99079.patch Untested fix. The problem is that the tree_nop_conversion_p (type, TREE_TYPE (@3)) test actually didn't test what it was meant to test, in (mod @0 (convert?@3 (...))) TREE_TYPE (@3) is the type of the second argument of the modulo, so necessarily compatible with type (compatible also with TREE_TYPE (@0)). But, I think we actually don't need to require only nop conversions, which = are certainly fine. If the conversion is narrowing, i.e. TREE_TYPE (@1) is wider than type, then we know that @1 is some power of two and after the cast, it will be either 0 (but then UB, so we can rule that out), or that power of two. For widening conversion where TREE_TYPE (@1) is unsigned it is also fine, @1 will be some power of two (0 being UB) and @1 - 1 is a mask we can use a= fter widening it to the type of the mod. The only problematic case is widening conversion where TREE_TYPE (@1) is signed, as the testcase shows, if the power of two is negative, i.e. msb set and all other bits clear, then the widening cast turns that into 0xffffffff80000000 (if type is unsigned) and as that is not a power of two, we can't transform= it into a mask by 0x7fffffff.=