Hi Eric,
> The note doesn't look particularly helpful in this case, given that gcse
> has replaced r974 with r1218 in the insn. How is it created?
The register replacement is done by gcse but the cse pass invoked from gcse
modifies the REG_EQUAL note. The limited scope of cse compared to gcse is
probably the reason why the information put into the insn note isn't helpful.
The REG_EQUAL note added to insn 2308 seems to be particularly pointless.
09.cse1:
(insn 1742 1740 1743 109 (set (reg/f:DI 974)
(const:DI (unspec:DI [
(symbol_ref:DI ("local") <var_decl 0x200004c9dc0 local>)
] 110))) 49 {*movdi_larl} (nil)
(nil))
(insn 1743 1742 1744 109 (set (reg/f:DI 973)
(mem/u/c:DI (reg/f:DI 974) [0 S8 A8])) 51 {*movdi_64} (nil)
(nil))
10.gcse1:
(insn 2308 1740 1743 111 (set (reg/f:DI 974)
(const:DI (unspec:DI [
(symbol_ref:DI ("local") <var_decl 0x200004c9dc0 local>)
] 110))) 49 {*movdi_larl} (nil)
(expr_list:REG_EQUAL (const:DI (unspec:DI [
(symbol_ref:DI ("local") <var_decl 0x200004c9dc0 local>)
] 110))
(nil)))
(insn 1743 2308 1744 111 (set (reg/f:DI 973)
(mem/u/c:DI (reg/f:DI 1218) [0 S8 A8])) 51 {*movdi_64} (nil)
(expr_list:REG_EQUAL (mem/u/c:DI (reg/f:DI 974) [0 S8 A8])
(nil)))
constprop_register first tries to replace r974 with a symbol_ref. This failes
and the symbol_ref is added as REG_EQUAL note in gcse.c:2686:
/* If we've failed to do replacement, have a single SET, don't already
have a note, and have no special SET, add a REG_EQUAL note to not
lose information. */
if (!success && note == 0 && set != 0
&& GET_CODE (SET_DEST (set)) != ZERO_EXTRACT
&& GET_CODE (SET_DEST (set)) != STRICT_LOW_PART)
note = set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
resulting in:
(insn 1743 2308 1744 109 (set (reg/f:DI 973)
(mem/u/c:DI (reg/f:DI 974) [0 S8 A8])) 51 {*movdi_64} (nil)
(expr_list:REG_EQUAL (mem/u/c:DI (const:DI (unspec:DI [
(symbol_ref:DI ("local") <var_decl 0x200004c9dc0 local>)
] 110)) [0 S8 A8])
(nil)))
local_cprop_pass then replaces r974 with r1218.
The cleanup cse pass called in gcse.c:6676 then modifies the REG_EQUAL note.
cse calls fold_rtx for the REG_EQUAL note in cse.c:4936 looking for a
replacement
of the symbol_ref. cse only sees that this value has already been copied to r974
and puts that register into the REG_EQUAL note.
> Is (reg/f:DI 974) loop invariant or only conditionally invariant?
It is only conditionally invariant since it is set in the loop body - to a
constant
value though. set_in_loop is -2 and loop_invariant_p returns 2 as expected.
Bye,
-Andreas-