On 11/18/26 11:36 PM, Jiahao Xu wrote:
When ext_dce_try_optimize_extension turns an extension such as
(set (reg:DI 145) (sign_extend:DI (subreg:SI (reg:DI 100) 0)))
into a plain move
(set (reg:DI 145) (reg:DI 100))
the upper bits of the destination are no longer guaranteed to be a sign
extension of the lower 32 bits. The existing code only wipes the notes
on the converted insn itself, but insns that use the destination register
may still carry REG_EQUAL/REG_EQUIV notes containing the original extension
expression, e.g.
(set (reg:DI 96) (reg:DI 145))
(expr_list:REG_EQUAL (sign_extend:DI (subreg:SI (reg:DI 100) 0)))
These notes are now incorrect. Later passes such as combine may take
them to mean that the upper 33 bits of the register are all copies of
the sign bit, and make wrong transformations based on that.
This patch walks the use chain of the destination register and removes
any REG_EQUAL or REG_EQUIV note that contains the original extension
expression.
PR rtl-optimization/127558
gcc/ChangeLog:
* ext-dce.cc (ext_dce_try_optimize_extension): Remove
REG_EQUAL/REG_EQUIV notes on users of the destination
register that reference the eliminated extension.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr127558.c: New test.
While I think this works, it may be a lot cleaner to drop notes after we
build the transitive closure of the changed pseudos. I think we can get
away with something much simpler in that context.
Also note this fails on RISC-V and probably other ports.
I'm going to play around a bit with this.
Jeff