I'm looking at the argpromotion optimizer pass in LLVM, but it doesn't seem to
reliably work right now in combination with clang (didn't try with llvm-gcc).
When passing a struct to a function, clang currently generates a call to
memcpy and passes the pointer to the (temp copy of the) struct to the
function. ArgPromotion can succesfully promote this struct argument (i.e.,
replace it by multiple scalar arguments) but only if the called function does
not modify the struct.
Now, on to my actual question. Why does clang do this memcpy trick in the
frontend? Wouldn't it be more flexible to simply pass the struct pointer byval
to the function and let the codegenerator or a later optimization step add the
memcpy (if still needed)? Is this a deliberate choice (perhaps because the
codegen doesn't support byval properly yet?), or is it simply generic
handling of structs that causes this (from looking at the code, it looks like
Any suggestions on how and where to implement this byval passing of structs?
I'm still digging around in the source code, following call paths to see what
actually happens right now