From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4B950385841A; Fri, 10 Feb 2023 22:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B950385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676068015; bh=bF3YuleZKhdlSsE7ewI+o25NeHJYWOQ/tTm71XOX41M=; h=From:To:Subject:Date:From; b=rn8qU8LrplkhZqV71WSik2r53Fg72XrVDirx8wTQgyUgIAprlPK6OId/ucWlUqnmG w/jTb9cZMtfQ6UleDHGNKLYUdZSpdmaasyGPfh/bTkcyYQbuiF3dH9+TQcpNFKK+HB CxLJjKvlUpr0uwOHTsahqyuk/ivPDUHXF/FLYgg4= From: "bergner at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/108757] New: We do not simplify (a - (N*M)) / N + M -> a / N Date: Fri, 10 Feb 2023 22:26:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bergner at gcc dot gnu.org 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 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=3D108757 Bug ID: 108757 Summary: We do not simplify (a - (N*M)) / N + M -> a / N Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bergner at gcc dot gnu.org Target Milestone: --- The Eigen project code has a missed optimization that basically simplifies = down to the following test case: linux$ cat bug.c=20 #define N 32 #define M 2 unsigned long int foo (unsigned long int a) { return (a - (N*M)) / N + M; } linux$ gcc -O2 -S bug.c=20 linux$ cat bug.s=20 foo: addi 3,3,-64 srdi 3,3,5 addi 3,3,2 blr We should be able to simplify this down to just 'a / N', which for power-of= -2 N, results in just the srdi...although, I don't think N is required to be a power-of-2 to fold this down to just 'a / N'. Can we also simplify this for non-constant N & M? Maybe under -fast-math or something similar?=