Hi Segher, I think the current documentation is sufficient. During compilation, GCC's combine pass will often substitute a register with an expression defining it's value, and then attempt to simplify it. As you point out, this often produces (temporary intermediate) expressions with poorly defined semantics. The purpose of my patch is to avoid (constructing) SUBREGs that have TRUNCATE as an argument (that some folks consider undefined) and instead simplify them to either a single TRUNCATE or a SUBREG of a REG, both of which are well defined. I'm making/helping the implementation match the documentation.
>From the current output of -fdump-rtl-combine-all=stdout Trying 10 -> 15: 10: r29:QI=trunc(r32:SI) REG_DEAD r32:SI 15: r38:HI=r29:QI#0 REG_DEAD r29:QI Failed to match this instruction: (set (reg:HI 38) (subreg:HI (truncate:QI (reg:SI 32)) 0)) with this patch: Trying 10 -> 15: 10: r29:QI=trunc(r32:SI) REG_DEAD r32:SI 15: r38:HI=r29:QI#0 REG_DEAD r29:QI Successfully matched this instruction: (set (reg:HI 38) (truncate:HI (reg:SI 32))) allowing combination of insns 10 and 15 original costs 4 + 12 = 16 replacement cost 4 deferring deletion of insn with uid = 10. A few lines earlier in this function, it simplifies SUBREGs of CONST_INT, which would also have poorly defined semantics. Perhaps your interpretation of the RTL documentation doesn't strictly apply to this part of the RTL optimizers? Let me know what you think. Best regards, Roger -- -----Original Message----- From: Segher Boessenkool <seg...@kernel.crashing.org> Sent: 06 September 2021 11:14 To: Roger Sayle <ro...@nextmovesoftware.com> Cc: 'GCC Patches' <gcc-patches@gcc.gnu.org> Subject: Re: [PATCH] Simplify paradoxical subreg extensions of TRUNCATE On Sun, Sep 05, 2021 at 11:28:30PM +0100, Roger Sayle wrote: > This patch simplifies the RTX (subreg:HI (truncate:QI (reg:SI))) as > (truncate:HI (reg:SI)), and closely related variants. Subregs of other than regs are undefined in RTL. You will first have to define this (in documentation as well as in other code that handles subregs). I doubt this is possible to do, subreg have so many overloaded meanings already. Segher