ast_tools icon indicating copy to clipboard operation
ast_tools copied to clipboard

SSA pass producing unnecessary phi nodes

Open rdaly525 opened this issue 6 years ago • 4 comments

The following example will produce a phi node for 'a' even thought it is unneeded. This causes problems when the types of 'a' in each branch are different

def foo(pred : Bit, x : BitVector[16]):
    if pred:
        a = Signed[16](x)
        b = a > 0
    else:
        a = Unsigned[16](x)
        b = a > 0
    #code that never uses 'a' again

rdaly525 avatar Jan 06 '20 22:01 rdaly525

If a is never used again I would immagine dead code elimination in the rtl compiler would optimize this away. Is there evidence that this effect QOR?

cdonovick avatar Jan 07 '20 18:01 cdonovick

The problem is when 'a' is a different type in each branch. The extraneous phi node causes type errors.

rdaly525 avatar Jan 07 '20 18:01 rdaly525

Ahh I see. While possible, this is actually quite annoying to fix. Could we work around this for now?

cdonovick avatar Jan 07 '20 18:01 cdonovick

@leonardt, it seems that magma handles this case without erroring. Is there a way to leverage what you have written?

rdaly525 avatar Jan 07 '20 18:01 rdaly525