You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently Phi Nodes dont really work well with Register Allocation, because it gets "invalided" when destructuring the SSA Form of the Phi Nodes
Cause
This is caused by an oversight of the interference graph/register allocation.
Lets say we define x1 in b1 and x2 in b2 and now define x3 as Phi(x1, x2). With the current System this means that we assign Registers to x1, x2 and x3 independently of each other and the Register assigned to x3 might be used before x3 was assigned with the Phi Node. When we then destructure our SSA we essentially move the assignment of x3 up into b1 and b2, but because the Register for x3 was also used before we originally assigned x3 using the Phi we now overwrite its register in between.
b1:
x1 = 13
x3 = x1
jump b3
b2:
x2 = 23
x3 = x2
jump b3
b3:
test1 = 123 // Could be storing into the same Register that x3 was previously stored in and therefore corrupting the Data
print (test1)
print (x3)
Because test1 and x3 dont interfere in the original SSA they could very well be assigned to the same Register meaning that we then generate an invalid SSA after destructuring because the Register for x3 is overwritten, but we just use it again afterwards as if nothing happened
The text was updated successfully, but these errors were encountered:
We should change the ways that we generate the interference Graph to correctly represent the destructured case. For this we should check if a variable is no longer used in a Block and only gets used once in a following Block and if that use case is as an Entry in a Phi-Node otherwise continue as normal. However if that is the Case, the current Variables liveness ends at the end of the current Block and we "raise" the start of the Variable defined by the Phi-Node to the end of the Block as well. This would basically mimic the way that the destructured SSA would look without actually changing the IR we are working with.
Problems
This would not deal with multiple Phi Nodes correctly, because we dont garantuee anything about the Order and therefore could still mess things up in that sense.
Its also unclear on how this could be implemented efficiently, but this would take a backseat as correctness is the Priority right now
For a temporary Fix we could use the fact that variables of the same group are assigned to the same underlying Memory location and we could therefore store the Phi-Entries to the shared memory location at the end of their blocks and replace the Phi-Node with a simple read from the shared memory location. This should work correctly and generate the correct result.
Problem
This obviously comes with a performance penalty because we need to perform at least two more extra memory writes and one more memory read. Moreover this also isnt really a fix because we are now just working around this issue and avoiding it instead of properly fixing its root cause
Problem
Currently Phi Nodes dont really work well with Register Allocation, because it gets "invalided" when destructuring the SSA Form of the Phi Nodes
Cause
This is caused by an oversight of the interference graph/register allocation.
Lets say we define x1 in b1 and x2 in b2 and now define x3 as Phi(x1, x2). With the current System this means that we assign Registers to x1, x2 and x3 independently of each other and the Register assigned to x3 might be used before x3 was assigned with the Phi Node. When we then destructure our SSA we essentially move the assignment of x3 up into b1 and b2, but because the Register for x3 was also used before we originally assigned x3 using the Phi we now overwrite its register in between.
Example
Original SSA:
Destructured
Because test1 and x3 dont interfere in the original SSA they could very well be assigned to the same Register meaning that we then generate an invalid SSA after destructuring because the Register for x3 is overwritten, but we just use it again afterwards as if nothing happened
The text was updated successfully, but these errors were encountered: