llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.57k stars 11.81k forks source link

missed optimization for static constexpr field without definition #17986

Open brunodefraine opened 11 years ago

brunodefraine commented 11 years ago
Bugzilla Link 17612
Version 3.3
OS Linux
Attachments test case
CC @majnemer,@DougGregor

Extended Description

Consider the code in attachment. clang only properly optimizes the function f()' when it has a definition for the constexpr fieldfoo' in the same compilation unit.

Note that I'm not complaining that I have to provide a definition for field `foo'. But my choice for the compilation unit for this definition should not affect performance?

$ clang++ -std=c++11 -O2 -Wall -c report.cpp && objdump -d report.o

report.o: file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <_Z1fv>: 0: b8 01 00 00 00 mov $0x1,%eax 5: 83 3d 00 00 00 00 01 cmpl $0x1,0x0(%rip) # c <_Z1fv+0xc> c: 74 05 je 13 <_Z1fv+0x13> e: b8 02 00 00 00 mov $0x2,%eax 13: c3 retq

$ clang++ -DDEF -std=c++11 -O2 -Wall -c report.cpp && objdump -d report.o

report.o: file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <_Z1fv>: 0: b8 01 00 00 00 mov $0x1,%eax 5: c3 retq

991901f3-cc14-4404-b340-165691b62a58 commented 11 years ago

gcc emits the optimal code for this, EDG rejects because of the 'static constexpr' with "a member of type "Literal" cannot have an in-class initializer".