In the phi-node-elimination pass, we set the killed flag incorrectly.
When we eliminate the PHI node, we replace the PHI with a copy for the incoming value.
Before this patch, we will set incoming value as killed(PHICopy). And we will remove the killed flag
from last using incoming value(OldKill). This is correct, only if the new PHICopy is after the OldKill.
Below is an example:
%35:gprc = PHI %26, %bb.2, %28, %bb.3 %36:gprc = PHI %19, %bb.2, %35, %bb.3 %37:gprc = PHI %26, %bb.2, %28, %bb.3 %38:g8rc_and_g8rc_nox0 = PHI %25, %bb.2, %34, %bb.3
After phi-node-elimination pass, we will get:
%38:g8rc_and_g8rc_nox0 = COPY killed %59 %37:gprc = COPY killed %57 %36:gprc = COPY killed %58 %35:gprc = COPY %57
It's obvious that, we have set the wrong killed flag for %57, if we enabled the verification for
phi-node-elimination pass, we will get the error Using a killed virtual register.
In fact, the right output should be this:
%38:g8rc_and_g8rc_nox0 = COPY killed %59 %37:gprc = COPY %57 %36:gprc = COPY killed %58 %35:gprc = COPY killed %57
This patch is to fix above error, it can fix below cases:
LLVM :: CodeGen/Hexagon/late_instr.ll LLVM :: CodeGen/Hexagon/rdf-filter-defs.ll LLVM :: CodeGen/Hexagon/swp-epilog-phi11.ll LLVM :: CodeGen/Hexagon/swp-epilog-phi13.ll LLVM :: CodeGen/Hexagon/swp-epilog-phi7.ll LLVM :: CodeGen/Hexagon/swp-lots-deps.ll LLVM :: CodeGen/Hexagon/swp-phi-def-use.ll LLVM :: CodeGen/Hexagon/swp-phi-dep1.ll LLVM :: CodeGen/Hexagon/swp-phi.ll LLVM :: CodeGen/Hexagon/swp-stages5.ll LLVM :: CodeGen/PowerPC/sms-phi-2.ll LLVM :: CodeGen/Thumb/2009-08-12-ConstIslandAssert.ll LLVM :: CodeGen/X86/2009-04-27-CoalescerAssert.ll LLVM :: CodeGen/X86/avx512-masked_memop-16-8.ll LLVM :: CodeGen/X86/crash.ll LLVM :: CodeGen/X86/mmx-coalescing.ll LLVM :: CodeGen/X86/statepoint-vector.ll
This findKill was guarded by if (reusedIncoming) in the past. I guess it won't hurt to keep it that way (to avoid any unpleasant surprises with build speeds, not that I think it will cause any big problems but OldKill is only of interest if reusedIncoming is true).