public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108757] New: We do not simplify (a - (N*M)) / N + M -> a / N
@ 2023-02-10 22:26 bergner at gcc dot gnu.org
  2023-02-10 22:28 ` [Bug tree-optimization/108757] " bergner at gcc dot gnu.org
                   ` (26 more replies)
  0 siblings, 27 replies; 28+ messages in thread
From: bergner at gcc dot gnu.org @ 2023-02-10 22:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108757

            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 
#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 

linux$ cat bug.s 
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?

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2023-09-04  3:26 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 22:26 [Bug tree-optimization/108757] New: We do not simplify (a - (N*M)) / N + M -> a / N bergner at gcc dot gnu.org
2023-02-10 22:28 ` [Bug tree-optimization/108757] " bergner at gcc dot gnu.org
2023-02-10 22:33 ` pinskia at gcc dot gnu.org
2023-02-10 22:40 ` pinskia at gcc dot gnu.org
2023-02-11 13:14 ` anlauf at gcc dot gnu.org
2023-02-11 16:38 ` segher at gcc dot gnu.org
2023-02-11 17:32 ` bergner at gcc dot gnu.org
2023-02-11 17:55 ` segher at gcc dot gnu.org
2023-02-11 18:05 ` bergner at gcc dot gnu.org
2023-02-11 18:15 ` segher at gcc dot gnu.org
2023-02-11 19:45 ` chip.kerchner at ibm dot com
2023-02-11 21:55 ` chip.kerchner at ibm dot com
2023-02-11 22:03 ` chip.kerchner at ibm dot com
2023-02-13 20:13 ` chip.kerchner at ibm dot com
2023-02-13 20:20 ` pinskia at gcc dot gnu.org
2023-02-13 20:27 ` [Bug rtl-optimization/108757] " pinskia at gcc dot gnu.org
2023-02-13 20:36 ` chip.kerchner at ibm dot com
2023-02-13 20:37 ` chip.kerchner at ibm dot com
2023-02-13 20:58 ` [Bug tree-optimization/108757] " pinskia at gcc dot gnu.org
2023-02-13 20:59 ` pinskia at gcc dot gnu.org
2023-02-13 21:01 ` pinskia at gcc dot gnu.org
2023-05-11 13:15 ` guojiufu at gcc dot gnu.org
2023-05-11 17:32 ` pinskia at gcc dot gnu.org
2023-05-12  1:52 ` guojiufu at gcc dot gnu.org
2023-05-12  6:25 ` guojiufu at gcc dot gnu.org
2023-05-12  9:35 ` guojiufu at gcc dot gnu.org
2023-09-04  2:46 ` cvs-commit at gcc dot gnu.org
2023-09-04  3:26 ` guojiufu at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).