https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122911
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Component|tree-optimization |middle-end
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> which calculates u1/10 twice.
No, it calculates u1/10 once and (u1/10)%10 the other time.
The gimple looks like the best it could be:
```
u1_3 = u1_2(D) / 10;
_1 = u1_3 % 10;
u3_4 = (long int) _1;
```
We chose unsigned for the %10:
```
;; positive division: unsigned cost: 57; signed cost: 65
```
Doing it as:
```
void foo(unsigned long u1)
{
long u3;
u3 = u1 % 10;
u1 = u1 / 10;
bar(u1,u3);
}
```
Or:
```
void foo(unsigned long u1)
{
long u3;
unsigned long u2 = u1 / 10;
u3 = u1 % 10;
bar(u2,u3);
}
```
We only do /10 once.