llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[NVPTX] Incorrect kill flags after ProxyReg Erasure

Open andreww0210 opened this issue 6 months ago • 1 comments

Description

In the NVPTX backend, the NVPTXProxyRegErasure pass replaces uses of proxy registers with their source registers and erases the proxy register instructions. However, it fails to update the kill flags correctly during this replacement.

If a proxy register use is marked as killed, the pass blindly transfers the kill flag to the source register during replacement. If the source register has subsequent downstream uses, this incorrectly terminates its live range prematurely, leading to incorrect liveness information and potential miscompilation.

Steps to Reproduce

Consider the following Machine IR snippet before the nvptx-proxyreg-erasure pass:

    %2:b16 = CVT_u16_u32 %0:b32, 0
    %3:b16 = ProxyRegB16 %2:b16
    %4:b16 = ADD16rr %1:b16, killed %3:b16
    %5:b16 = ADD16rr %1:b16, %2:b16

After the pass runs, the current code replaces %3 with %2 but leaves the killed flag intact:

%2:b16 = CVT_u16_u32 %0:b32, 0
%4:b16 = ADD16rr %1:b16, killed %2:b16 ; BUG:   // %2 is incorrectly killed
%5:b16 = ADD16rr %1:b16, %2:b16 ;  // %2 is used after being “killed”

andreww0210 avatar May 17 '26 03:05 andreww0210

see https://github.com/llvm/llvm-project/pull/198143

andreww0210 avatar May 17 '26 03:05 andreww0210