On Wed, Apr 22, 2015 at 10:16 PM, Steve Ellcey <sell...@imgtec.com> wrote: > Following up to my own email, I think I found the missing magic. I > needed to set global_regs[16] to 1. Once global_regs was set for the > register, the assignment stopped getting optimized out.
There is a helper in varasm.c (?) that does most of that magic for you. Btw, why don't you use an inline asm node instead? There shouldn't be any reason to mark the register global? > Steve Ellcey > sell...@imgtec.com > > > On Wed, 2015-04-22 at 12:27 -0700, Steve Ellcey wrote: >> On Wed, 2015-04-22 at 12:28 +0200, Steven Bosscher wrote: >> >> > This is wrong for sure. You can't have DECL_RTL in GIMPLE. >> > >> > You will want to set has_local_explicit_reg_vars, DECL_HARD_REGISTER, >> > and DECL_ASSEMBLER_NAME, and leave it to the middle end to take care >> > of everything else. >> > >> > Ciao! >> > Steven >> >> Thanks for the advice, I switched to DECL_HARD_REGISTER and >> DECL_ASSEMBLER_NAME but I am still having the same problem, which is >> that the assignment to this global (register) variable is getting >> optimized away. >> >> If I have: >> >> ptr_type = build_pointer_type (char_type_node); >> id = get_identifier ("X"); >> ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type); >> TREE_PUBLIC (ptr_var) = 1; >> DECL_EXTERNAL (ptr_var) = 1; >> varpool_node::finalize_decl (ptr_var); >> >> The the assignment to this global variable is not removed by the >> optimizer, which makes sense because someone outside the function could >> access the value of the global variable. >> >> But if I change it to: >> >> ptr_type = build_pointer_type (char_type_node); >> id = get_identifier ("*$16"); >> ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type); >> TREE_PUBLIC (ptr_var) = 1; >> DECL_EXTERNAL (ptr_var) = 1; >> DECL_REGISTER (ptr_var) = 1; >> DECL_HARD_REGISTER (ptr_var) = 1; >> SET_DECL_ASSEMBLER_NAME (ptr_var, id); >> varpool_node::finalize_decl (ptr_var); >> >> Then the assignment to this variable is optimized away by the cse1 >> optimization phase. >> >> Steve Ellcey >> sell...@imgtec.com > > >