4 ms·
Wouldn't be possible for the compiler to optimize it away?
by ducaale 6y ago
Wouldn't be possible for the compiler to optimize it away?
- flohofwoe 6y agoOnly if the function is inlined, at least it seems that way from experimenting on godbolt.org.
- nikki93 6y agohttps://godbolt.org/z/11931W https://godbolt.org/z/11931W Here's an example where it happens even when not inlining.
- flohofwoe 6y agoI guess that's because the struct size is below 16 bytes (see my sister comment). Adding two more ints to the struct places the entire content on the stack.
- bitwalker 6y agoI'd expect scalar replacement of aggregates (SROA) would eliminate the use of a struct like this in some cases, but there are definitely limits, especially if not compiling with LTO enabled, since optimizations across compilation units will be limited. Honestly doesn't seem worth the cost.
- nikki93 6y agoUsing registers to pass structs is an ABI thing and doesn't need LTO, it happens during compilation (see godbolt.org links on the rest of this thread).