This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

propagating mem expressions


Hi, 

I have an small optimization pass, which is situated right after sibling 
optimization. I am assigning constant values to global variables (which 
are referred as mem (symbol_ref ("my_variable")), and I expect them to be 
propagated by subsequent constant propagation passes (ssa, cse, gcse).

I am doing exactly the same thing for local variables, i.e. for registers, 
not memory locations, and it works.

I am aware of the fact that one can't simply generate the register number, 
but actually needs the structure containing that register rtx. So I save 
that, and I use it whenever I'm generating my own rtx for assigning a 
constant to that register. Like I said, that works.

I am trying to do the same thing for global variables. 
I assumed that I should be doing a similar thing as for registers, i.e. 
save somewhere the rtx represented by the symbol_ref expression, and use 
that when generating my own instruction.

The equivalent RTL for this line of source code:

ARCHnodes = 77;

is this:

(insn 56 48 58 0 0x4001f370 (set (mem/f:SI (symbol_ref:SI ("ARCHnodes")) 
[9 ARCHnodes+0 S4 A32])
        (const_int 77 [0x4d])) 45 {*movsi_1} (nil)
    (nil))


(as generated by gcc, not by me).

What I want to do is generate exactly the same instruction, without the 
statement in the source code, of course.

I tried saving the (symbol_ref:SI ("ARCHnodes") rtx, and using that when I 
generate my instruction. I also then tried the entire 
(mem/f:SI  (symbol_ref:SI ("ARCHnodes")) [9 ARCHnodes+0 S4 A32])
rtx, by saving it, and using it when I generate my instruction.

Although in both cases my generated instruction looks precisely as the one 
generated by gcc (as above), the constant is not propagated by cse, as it 
is the case with the original program (i.e., if we have the statement in 
the source code).

This is how I generate my instruction:

assume I previously saved the (mem/f:SI (symbol_ref (...)) rtx into 
mem_insn:

 const_insn = gen_rtx (CONST_INT, SImode, ivalue)

 new_insn = gen_rtx (SET, VOIDmode,
                     mem_insn,
                     const_insn);

Again, the corresponding generated insn looks identical to the one I 
showed above, as generated by gcc itself.

Does anybody have any suggestions as to why the original one is used by 
the constant propagation passes, but mine isn't ?

Thank you
mihai



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]