https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87522
Bug ID: 87522 Summary: LTO incorrectly merges target specific options Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com CC: marxin at gcc dot gnu.org Target Milestone: --- [hjl@gnu-cfl-1 lto-test-functions]$ cat a.c char a[32] = {}; void no_avx (void) { __builtin_memset(a, 0, sizeof(a)); } [hjl@gnu-cfl-1 lto-test-functions]$ cat b.c char b[32] = {}; void avx (void) { __builtin_memset(b, 0, sizeof(b)); } [hjl@gnu-cfl-1 lto-test-functions]$ cat c.c char c[32] = {}; void sse_only (void) { __builtin_memset(c, 0, sizeof(c)); } [hjl@gnu-cfl-1 lto-test-functions]$ make cc -O2 -fPIC -flto -g -mno-avx -c -o a.o a.c cc -O2 -fPIC -flto -g -mavx -c -o b.o b.c cc -shared -O2 -fPIC -flto -g -o lib1.so a.o b.o cc -O2 -fPIC -flto -g -c -o c.o c.c cc -shared -O2 -fPIC -flto -g -o lib2.so c.o b.o [hjl@gnu-cfl-1 lto-test-functions]$ 0000000000001100 <avx>: 1100: 48 8b 05 d1 2e 00 00 mov 0x2ed1(%rip),%rax # 3fd8 <b@@Base-0x88> 1107: c5 f9 ef c0 vpxor %xmm0,%xmm0,%xmm0 110b: c5 f8 29 00 vmovaps %xmm0,(%rax) 110f: c5 f8 29 40 10 vmovaps %xmm0,0x10(%rax) 1114: c3 retq 1115: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 0000000000001120 <no_avx>: 1120: 48 8b 05 c1 2e 00 00 mov 0x2ec1(%rip),%rax # 3fe8 <a@@Base-0x58> 1127: 66 0f ef c0 pxor %xmm0,%xmm0 112b: 0f 29 00 movaps %xmm0,(%rax) 112e: 0f 29 40 10 movaps %xmm0,0x10(%rax) 1132: c3 retq no_avx has no AVX instructions. 0000000000001100 <avx>: 1100: 48 8b 05 d1 2e 00 00 mov 0x2ed1(%rip),%rax # 3fd8 <b@@Base-0x88> 1107: c5 f9 ef c0 vpxor %xmm0,%xmm0,%xmm0 110b: c5 f8 29 00 vmovaps %xmm0,(%rax) 110f: c5 f8 29 40 10 vmovaps %xmm0,0x10(%rax) 1114: c3 retq 1115: 66 66 2e 0f 1f 84 00 00 00 00 00 data16 nopw %cs:0x0(%rax,%rax,1) 0000000000001120 <sse_only>: 1120: 48 8b 05 c1 2e 00 00 mov 0x2ec1(%rip),%rax # 3fe8 <c@@Base-0x58> 1127: c5 f9 ef c0 vpxor %xmm0,%xmm0,%xmm0 112b: c5 f8 29 00 vmovaps %xmm0,(%rax) 112f: c5 f8 29 40 10 vmovaps %xmm0,0x10(%rax) 1134: c3 retq sse_only has AVX instructions.