Regalloc2 is great, but I have a question. Is this a failure of the heuristics? Or have I set up my machine instruction structure incorrectly? The test machine instruction that I pass to regalloc2 has no Defs or Clobbers so there is no reason it couldn't just TEST EAX,EAX.
You’re right in this particular case that move seems extraneous; it’s hard to say more without actually running your environment and getting trace logs from RA2 to see why it’s doing that. (And to be clear I unfortunately don’t have the spare cycles for that, much as I would like to!)
I would verify that the vreg placed in rax is not clobbered elsewhere and that that there aren’t any register constraints forcing this
Could the clobber on call
be interfering with regalloc somehow?
I figured out why it is happening.
The test instruction is testing 32 bit EAX, prior to it, a truncate
takes the RAX from the function call and converts it to a 32bit. Although the truncate instruction isn't actually emitted, it still creates a Def, see the below description:
10: call_rel32 (Def: v22i fixed(p0i)), ...
11: truncate (Use: v22i any),(Def: v29i reuse(0)),Clobbers {}
12: test_rs_r (Use: v29i any),(Use: v29i reg),Clobbers {}
So regalloc thinks that the value in is being mutated(because I'm telling it it is) and creates a mov into a different register to avoid mutating RAX which is used later after the current function returns.
So, not a problem with regalloc2, a problem with my own design decisions.
Glad to see the mystery solved!
Last updated: Dec 23 2024 at 13:07 UTC