On 9/27/23 00:29, Vineet Gupta wrote:
Hi Jeff,
We touched upon this in our airport "rendezvous". I'm curious if you
have the wip bits lying around - (a) to get a feel for how this could be
done and (b) to see why REE and/or similar construct in CSE don't work
as expected.
Not in any usable form. Just several variants that didn't work ;-)
They don't work with REE because I'd forgotten a key point. REE doesn't
look for lexical redundancies like you'd see with CSE/PRE. ie, given a
pair of identical sign extensions in the IL, REE doesn't eliminate one.
Instead REE is focused on cases where we can transform an existing
operation such as a load into an extending load to eliminate a
subsequent extension.
This leads to a couple thoughts.
First, we ought to be able to use the same concept, but instead of
putting something like this into the IL to express the extension done by
the caller
(set (reg:DI a0) (sign_extend:DI (reg:SI a0)))
Instead we probably want to insert this as a dummy into the IL
(set (reg:SI a0) (mem:SI (sp))
If this is followed by a sign extension, then it'll get turned into
(set (reg:DI a0) (sign_extend:DI (mem:SI (sp)))
And the subsequent extension will get removed. And since we've tracked
the dummy, we can just eliminate the dummy as well. I'm a bit worried
about how this plays with the copy_needed bits in REE.
This should at least tell us how often there's an extension of an
incoming argument that can be trivially eliminated. I'm not sure it's
the best place to eliminate the extensions though. Leading to....
We should make sure that CSE/PRE are properly identifying and
eliminating lexical redundancies. I wouldn't be surprised if the class
of problems we're chasing are better detected and optimized by CSE/PRE
since those can work on an extended block or global basis respectively.
For CSE/PRE we'd want to insert something like
(set (reg:DI a0) (sign_extend:DI (reg:SI a0)))
Into the IL which should make any expressions like
(sign_extend:DI (reg:SI a0))
fully redundant in the IL, thus allowing CSE/PRE to eliminate them.
I've got a few things backed up from before the Cauldron, but expect to
be able to poke at this some this week.
jeff