[llvm-dev] The value of padding when storing an aggregate into memory

Alexander Cherepanov via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 19 13:37:30 PDT 2020


Hello Juneyoung,

On 19/08/2020 18.55, Juneyoung Lee via llvm-dev wrote:
>> Interesting topic. Is any such optimization reachable from C?
 >
> Yes, I think so - both PassBuilder and PassManagerBuilder add MemCpyOpt &
> IPSCCP in the default pass pipeline.

In my experience, clang (unlike gcc) preserves the naive meaning of the 
source C code in dealing with padding in structs -- assignments of whole 
structs copy the padding while assignments to members of structs retain 
their old padding. The only exception I know is returning structs from 
functions, as was pointed by Greg Parker in 
https://twitter.com/gparker/status/1193996158768578561 .

I don't think this is required by any standard and it would be 
interesting to find out why exactly it's done this way (and whether the 
mentioned exception is a bug). This is especially wasteful in case of 
bit-fields.

OTOH it's not clear to me this has anything to do with the 
transformations of LLVM IR that you mentioned. Perhaps clang just 
doesn't emit any IR that could trigger those optimizations.

-- 
Alexander Cherepanov


More information about the llvm-dev mailing list