https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64410

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Conrad from comment #2)
> (In reply to Marc Glisse from comment #1)
> > 3) the ABI for complex uses 2 separate double instead of a vector of 2
> > double.
> 
> Technically yes, but in practice aren't the 2 separate doubles guaranteed to
> be consecutive in memory?

When the complex is in memory, yes. But passing a complex by value to a
function is done with 2 separate registers. And somehow that means the default
expansion for complex addition is 2 addsd, whereas the default expansion for
vector addition is addpd. Using addpd by default for complex would make some
code better (this example would hopefully be optimal without need for any
optimization) and some worse, I don't know if there are good benchmarks for
complex numbers.

Clang's use of add[ps]d seems based entirely on what is done with the result,
as can be seen on:

typedef _Complex double cd;
void f(cd&r,cd x,cd y){
  r=x+y;
}
cd f(cd&x,cd&y,cd&z){
  return x+y+z;
}

(I agree that gcc should be improved, I am not trying to defend the current
code generation. And now I'll shut up and let people who actually know the code
speak ;-)

Reply via email to