Stream: cranelift

Topic: RA2 Odd edit decisions.


view this post on Zulip Leaves (Jul 16 2024 at 00:42):

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.

view this post on Zulip Chris Fallin (Jul 16 2024 at 02:13):

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!)

view this post on Zulip Chris Fallin (Jul 16 2024 at 02:15):

I would verify that the vreg placed in rax is not clobbered elsewhere and that that there aren’t any register constraints forcing this

view this post on Zulip Amanieu (Jul 16 2024 at 14:45):

Could the clobber on call be interfering with regalloc somehow?

view this post on Zulip Leaves (Jul 16 2024 at 19:28):

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.

view this post on Zulip Chris Fallin (Jul 16 2024 at 20:16):

Glad to see the mystery solved!


Last updated: Oct 23 2024 at 20:03 UTC