https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99383
Bug ID: 99383 Summary: No tree-switch-conversion under PIC Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jengelh at inai dot de Target Milestone: --- == Input source == enum { itm01, itm02, itm03, itm04, itm05, itm06, itm07, itm08, itm09, itm0A, itm0B, itm0C, itm0D, itm0E, itm0F, itm10, }; #define E(s) case s: return #s; const char *r2i(unsigned int i) { switch (i) { E(itm01) E(itm02) E(itm03) E(itm04) E(itm05) E(itm06) E(itm07) E(itm08) E(itm09) E(itm10) } return ""; } == Expected output == » g++-11 -v x.cpp -c -O2 » objdump -d x.o 0000000000000000 <_Z3r2ij>: 0: b8 00 00 00 00 mov $0x0,%eax 5: 83 ff 0f cmp $0xf,%edi 8: 77 0a ja 14 <_Z3r2ij+0x14> a: 89 ff mov %edi,%edi c: 48 8b 04 fd 00 00 00 mov 0x0(,%rdi,8),%rax 13: 00 14: c3 ret 0x0(,%rdi,8) points to a CSWTCH symbol generated by gcc's tree-switch-conversion.c. == Observed behavior with extra flag == When enabling pic/PIC, tree-switch-conversion optimization is completely missed and a lot of lea/ret instruction pairs are generated. » g++-11 -v x.cpp -c -O2 -fpic Target: x86_64-suse-linux gcc version 11.0.0 20210208 (experimental) [revision efcd941e86b507d77e90a1b13f621e036eacdb45] (SUSE Linux) ... » objdump -d x.o … 20: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 27 <_Z3r2ij+0x27> 27: c3 ret 28: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) 2f: 00 30: 48 8d 05 00 00 00 00 lea 0x0(%rip),%rax # 37 <_Z3r2ij+0x37> 37: c3 ret …