[LLVMdev] folding x * 0 = 0
Jochen Wilhelmy
j.wilhelmy at arcor.de
Wed Mar 3 08:56:15 PST 2010
Hi!
> sin/cos etc should already be handled by lib/Analysis/ConstantFolding.cpp.
>
Thanks for the hint and it works!
Now I have a new Problem:
I have this function:
float foo(float a, float b)
{
float x = a * b * 0.0f;
return cos(0.5) * sin(0.5) * x;
};
after compiling it with clang (cpp mode) and renaming _ZSt3sinf to sin
and _ZSt3cosf to cos I get the following:
define float @_Z3fooff(float %a, float %b) nounwind {
entry:
%mul = fmul float %a, %b ; <float> [#uses=1]
%mul2 = fmul float %mul, 0.000000e+000 ; <float> [#uses=1]
%mul6 = fmul float 0x3FDAED54A0000000, %mul2 ; <float> [#uses=1]
ret float %mul6
}
the sin and cos calls are folded, but not the mul by zero.
May be this is missing in llvm::ConstantFoldInstOperands in
ConsantFolding.cpp?
I would expect the following optimizations, but didn't find them in the
code:
x + 0 = x
x * 0 = 0
x * 1 = 1
x * -1 = -x
-Jochen
More information about the llvm-dev
mailing list