https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128924
Bug ID: 128924
Summary: two multiples in gimple when only one is needed for
widdening multiple
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
CC: dfaust at gcc dot gnu.org
Blocks: 26163
Target Milestone: ---
Take:
```
unsigned long f(unsigned long a, unsigned long b, unsigned long *h)
{
unsigned __int128 t = a;
t *= b;
*h = t >> 64;
return a*b;
}
unsigned long f1(unsigned long a, unsigned long b, unsigned long *h)
{
unsigned __int128 t = a;
t *= b;
*h = t >> 64;
return t;
}
```
So before inlining, I would expect f to be the same IR as f1. This reduces
code of f slightly.
This IR shows up in sealcrypto's barrett_reduce_64 function (and others there).
With -flto, barrett_reduce_64 is not inlined due to htiting some inlining
limits (david faust can comment more on that).
For A place where it makes a finaly code difference take:
```
unsigned int g(unsigned int a, unsigned int b, unsigned int *h)
{
unsigned long t = a;
t *= b;
*h = t >> 32;
return a*b;
}
unsigned int g1(unsigned int a, unsigned int b, unsigned int *h)
{
unsigned long t = a;
t *= b;
*h = t >> 32;
return t;
}
```
And there is only one multiply for g1 for x86_64 and aarch64.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26163
[Bug 26163] [meta-bug] missed optimization in SPEC (2026, 2k17, 2k and 2k6 and
95)