https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106585
--- Comment #11 from Jeffrey A. Law <law at gcc dot gnu.org> --- Coming back to this. WRT extension elimination. I've been pondering if we want a late pass to do a bit of this that can't be handled by REE. So let's take the case of a Zbs instruction operating on a variable bit in RV64. I think we can probably agree that in the absence of additional information we can't do those kind of bit manipulations because we could potentially change bit 31 and have the result escape as a parameter to a function call, return value or get used in a compare type instruction. So to make use of the Zbs instructions that manipulate a variable bit we could could emit a suitable sign extension after each such operation. That, of course, has the potential to be expensive. But if we chase down the uses we can probably eliminate a lot of these extensions. Essentially we need to know if the extension reaches a comparison, one of the ABI escape points or a real 64bit operation. If not, then the extension is unnecessary and can be dropped. Ideally we'd find that a significant number of extensions could be dropped. We're not actively working on this, but it is something rattling around in the empty space between my ears.