On Fri, 14 Mar 2025 13:30:39 +0800, Monk Chiang wrote: > 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
As I mentioned earlier, this is architecture-agnostic (regarding the handling of static functions at -O0). There is a minor concern about whether it is reasonable to insert instructions into static functions. Currently, LLVM does not encounter the same issue as GCC (LLVM does not handle static functions in the same way). Regardless, I understand that this will not affect the execution results. However, I believe it would be best to maintain logical consistency with LLVM (whether it's about lpad instructions or static functions in -O0). I'm not entirely certain, but I wanted to bring this up to hear everyone's thoughts on the matter :) Best regards, Jin Ma > On Wed, Mar 12, 2025 at 5:44=E2=80=AFPM 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 > > >