This patch adds the fix for undef virtual register reading failure when trap optimization is enabled.
Failure scenario as below:
- In a machine basic block A, the definition of a virtual register MI was eliminated due to trap optimization (TRAP inserted before the MI)
- The same virtual register is still used in another machine basic block B (dominated by A) will trigger undef vr reading failure
Idea of the fix
- Detect and set all virtual register definition after the conditional trap to IMPLICIT_DEF
- Remove all the other machine instructions after the conditional trap and change the terminator machine instruction to an unconditional trap
Might be good to pull out MI.getOperand(0).isReg() into a separate variable since you're using it three times here.