Integer factorizations in clang

Hello,

I have a small test case :

a = b * c + b * d

and clang is fatorizing b to get only one multiplication (-O3) which is normally good for most architectures. But in my case, that pattern takes just one instruction and I would like to recover it as is.
Where can I find this particular optimization in clang ?
Is there a way of setting multiplications as being cheaper than additions/subtracions in clang ?

Thanks in advance,

Ivan

Hi Ivan,

I have a small test case :

a = b * c + b * d

and clang is fatorizing b to get only one multiplication (-O3) which is
normally good for most architectures. But in my case, that pattern takes
just one instruction and I would like to recover it as is.
Where can I find this particular optimization in clang ?
Is there a way of setting multiplications as being cheaper than
additions/subtracions in clang ?

if you see the b*(c+d) pattern can't you just generate your b*c+b*d instruction
for it?

Ciao, Duncan.

Wouldn't it be simpler to detect factorize pattern in you code and generate the appropriate instruction as it if was a decomposed form.
It would have the benefit to properly optimize the code if the developer choose to use the factorized form directly.

-- Jean-Daniel

Hello,

I have a small test case :

a = b * c + b * d

and clang is fatorizing b to get only one multiplication (-O3) which is
normally good for most architectures. But in my case, that pattern takes
just one instruction and I would like to recover it as is.
Where can I find this particular optimization in clang ?
Is there a way of setting multiplications as being cheaper than
additions/subtracions in clang ?

Wouldn't it be simpler to detect factorize pattern in you code and generate the appropriate instruction as it if was a decomposed form.
It would have the benefit to properly optimize the code if the developer choose to use the factorized form directly.

Ok, I will try to match the factorized form from my back-end. Thanks you all.