https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113233

            Bug ID: 113233
           Summary: LoongArch: target options from LTO objects not
                    respected during linking
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyujie at loongson dot cn
  Target Milestone: ---

Compiling LTO objects with certain target options like -march=, -msimd= have no
effect on the final linked binary, since COLLECT_GCC_OPTIONS from the "linker
GCC" driver always overrides these options.

For instance, running the following command:

$ gcc -S -o- -xc - -msimd=lasx  -O3 <<< "void m2 (float *a, int n) { for (int i
= 0; i < n; i++) a[i] += 1; }" | grep vfadd

outputs SIMD instructions (as enabled by -msimd=lasx):

        xvfadd.s        $xr4,$xr4,$xr0
        xvfadd.s        $xr2,$xr2,$xr0
        xvfadd.s        $xr1,$xr1,$xr0
        xvfadd.s        $xr3,$xr3,$xr0
        vfadd.s $vr1,$vr1,$vr0
        vfadd.s $vr1,$vr1,$vr0
        vfadd.s $vr1,$vr1,$vr0
        vfadd.s $vr1,$vr1,$vr0
        vfadd.s $vr1,$vr1,$vr0
        vfadd.s $vr1,$vr1,$vr0
        vfadd.s $vr0,$vr1,$vr0

However, LTO generates code according to the compiler's default config
(-msimd=none).

Running:
$ gcc -flto -c -o test.o -xc - -msimd=lasx -O3 <<< "void m2 (float *a, int n) {
for (int i = 0; i < n; i++) a[i] += 1; }"

and then:
$ gcc -S -o- -xlto test.o | grep vfadd

outputs nothing, indicating that the final code generation have LSX/LASX
disabled.

While:
$ gcc -S -o- -xlto test.o -mlasx | grep vfadd

outputs the same "vfadd" / "xvfadd" instructions as above.

-------------------------------------------------------------------------------------
Proposed solution: implement option save/restore to enable LTO option
streaming.
-------------------------------------------------------------------------------------

Reply via email to