I wonder what best to do about rtl-optimization/21767.
We sometimes have REG_EQUAL notes that are only true when
the instruction stays exactly where it is, like:
(insn 11 10 12 0 (set (reg:SI 147 t)
(eq:SI (reg/v:SI 159 [ i ])
(reg:SI 161))) 1 {cmpeqsi_t} (nil)
(expr_list:REG_EQUAL (eq:SI (reg/v:SI 159 [ i ])
(const_int 2345678 [0x23cace]))
(nil)))
(jump_insn 12 11 37 0 (set (pc)
(if_then_else (eq (reg:SI 147 t)
(const_int 0 [0x0]))
(label_ref 17)
(pc))) 201 {branch_false} (nil)
(expr_list:REG_BR_PROB (const_int 7100 [0x1bbc])
(nil)))
;; End of basic block 0, registers live:
(nil)
;; Start of basic block 1, registers live: (nil)
(note 37 12 14 1 [bb 1] NOTE_INSN_BASIC_BLOCK)
(insn 14 37 15 1 (set (reg/v:SI 160 [ r ])
(reg/v:SI 159 [ i ])) 168 {movsi_ie} (nil)
(expr_list:REG_EQUAL (const_int 2345678 [0x23cace])
(nil)))
if-conversion changes this to
(insn 11 10 14 0 (set (reg:SI 147 t)
(eq:SI (reg/v:SI 159 [ i ])
(reg:SI 161))) 1 {cmpeqsi_t} (nil)
(expr_list:REG_EQUAL (eq:SI (reg/v:SI 159 [ i ])
(const_int 2345678 [0x23cace]))
(nil)))
(insn 14 11 12 0 (set (reg/v:SI 160 [ r ])
(reg/v:SI 159 [ i ])) 168 {movsi_ie} (nil)
(expr_list:REG_EQUAL (const_int 2345678 [0x23cace])
(nil)))
(jump_insn 12 14 38 0 (set (pc)
(if_then_else (ne (reg:SI 147 t)
(const_int 0 [0x0]))
(label_ref:SI 21)
(pc))) 200 {branch_true} (nil)
(expr_list:REG_BR_PROB (const_int 2900 [0xb54])
(nil)))
;; End of basic block 0, registers live:
(nil)
so the REG_EQUAL note on insn 14 is no longer true.
In general, if a REG_EQUAL note remains valid is not computable.
(any REG_EQUAL note is trivially valid if its insn is unreachable.)
Even where it is computable, you'd probably need as much complexity
and target-dependent knowledge to prove it as if you were computing
the equality from scratch.
So, I think our main options are to remove all REG_EQUAL notes
of insns that are moved above a branch, or to change the value to reflect
the condition it depends on. I.e. we could have an UNKNOWN rtx
to describe an unknown value in a REG_EQUAL note (A note
with a bare UNKNOWN value would be meaningless and should be
removed), and then express the note for insn 14 as:
(expr_list:REG_EQUAL (if_then_else (ne (reg:SI 147 t) (const_int 0 [0x0]))
(const_int 2345678 [0x23cace]) (unknwon))
(nil))