From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 236E2385841A; Thu, 7 Mar 2024 15:31:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 236E2385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709825517; bh=zTpchH/NMNx27Jzn0ozrmh0dPmw+KgJqwqp7Ma62+Jg=; h=From:To:Subject:Date:From; b=NSVFtl/xxy354AXPaA06qVWZDjXHSO+W/zajS6J3tCDlLHN/3aajEIlkDc8JfifXM JiKRuFR92VokZaR7E57hH7W9X9QYkL7EQfHsJhmSfIAnCannmcn2J3ZO1yJUkFB5Sw b1Cx78flCuf8f0oM37A0C8CrAYA6CsaitmvnneRs= From: "antoshkka at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/114270] New: Integer multiplication on floating point constant with conversion back to integer is not optimized Date: Thu, 07 Mar 2024 15:31:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: antoshkka at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D114270 Bug ID: 114270 Summary: Integer multiplication on floating point constant with conversion back to integer is not optimized Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the following example: unsigned test(unsigned x) { return (unsigned)(x * 0.5); } With -O2 GCC generates the code with a fair conversion to fp and multiplication: test(unsigned int): mov edi, edi pxor xmm0, xmm0 cvtsi2sd xmm0, rdi mulsd xmm0, QWORD PTR .LC0[rip] cvttsd2si rax, xmm0 ret However the multiplication does not overflow and the floating point constan= t is a normal number. A more optimal code should look like the following: test(unsigned int): mov eax, edi shr eax ret Probably the optimization could be used for * any multiplication of integer on positive fp-number less or equal to 1.0 * any division of integer on positive fp-number greater or equal to 1.0 if the result is converted back to integer=