So... I looked at this closer and from the *looks* of it, the current code is correct. It fixes up all the phi nodes in bb, which is the block whose inbound edges got all messed up. I will analyze your sample shader in more detail, hopefully it will become apparent to me why the current logic fails, despite *looking* right :)