Caller pass a local variable as const reference to callee (function declaration); shall the local variable be SROA'ed?

Compiler Explorer has a small example.

Basically, the local variable x remains stack allocated; caller passes x by const reference so callee shouldn’t modify x.

My question is, is it an legitimate optimization to SROA x?

Two-fold answer:

Roman

1 Like