https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70885
Bug ID: 70885 Summary: [SH] Use MSB pointer-tagging for pointer-to-member representation Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: olegendo at gcc dot gnu.org Target Milestone: --- Currently there are two available pointer-to-member representation options: ptrmemfunc_vbit_in_pfn, ptrmemfunc_vbit_in_delta where ptrmemfunc_vbit_in_pfn stores the "is a virtual function" pointer tag in the LSB of the pointer (assuming 16-bit aligned functions). When using the tagged pointer to make the function call, the tag needs to be tested and the pointer converted into a valid address. On SH this currently looks like this: struct test_class { int x; void func (void); }; void test (test_class* c, void (test_class::*f)(void) ) { (c->*f) (); } compiled with -O2: mov r5,r0 // r5 = r0 = __pfn field tst #1,r0 // test LSB add r6,r4 bt .L17 // if LSB not set, goto L17 mov.l @r4,r5 // when here, LSB is set add r5,r0 add #-1,r0 // subtract 1 to clear LSB mov.l @r0,r0 .L17: jmp @r0 nop At least on SH, it's better to do store pointer tags in the MSB. So that the tagged pointer value becomes: tagged_ptr_val = (ptr_val >> 1) | (tag_bit << 31) This allows for more efficient tag test and pointer value restoration, the code could look like: mov r5,r0 shll r5 // __pfn << 1, MSB -> T bit add r6,r4 bf .L17 // if MSB not set, goto L17 mov.l @r4,r5 add r5,r0 mov.l @r0,r0 .L17: jmp @r0 nop ... which saves one instruction. To enable that, there should be another option "ptrmemfunc_vbit_in_pfn_msb" along with some target specific m-option to enable this as well as a configure option to control the default setting.