Hi Jin Ma, This situation is the same on x86. When using -O0, the lpad instruction is merely a redundant instruction and does not affect the execution result. This is the ASM result for x86, and there is also an endbr64 in foo(). https://godbolt.org/z/M1fTendE3
On Wed, Mar 12, 2025 at 5:44 PM Jin Ma <ji...@linux.alibaba.com> wrote: > Hi, Monk Chiang > > I noticed that at -O0, static functions are emitting lpad instructions, > whereas > they do not at -O2. I'm not sure if this is expected behavior. > > Upon further investigation, I found that c_node->only_called_directly_p() > returns > false, which is caused by force_output being set to 1. Tracing back, I > encountered > the following patch[1] and PR25961[2], which set force_output to 1 for > static > functions at -O0, while it is 0 at -O2. > > Do you have any comments on this? > > > Example code: > > int cc = 333; > extern int aa; > > __attribute__((noinline)) > static void > foo(void) > { > cc = aa; > } > int main(void) > > { > foo(); > return 0; > } > > [1] https://gcc.gnu.org/legacy-ml/gcc-patches/2006-05/msg00315.html > [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24561 >