[Bug tree-optimization/108757] New: We do not simplify (a - (N*M)) / N + M -> a / N
bergner at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Feb 10 22:26:54 GMT 2023
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?
More information about the Gcc-bugs
mailing list