[llvm] c0e965e - [Statepoints] FixupStatepoint: Clear isKill flag if COPY is not deleted.

Denis Antrushin via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 00:53:07 PDT 2022


Author: Denis Antrushin
Date: 2022-06-14T10:52:32+03:00
New Revision: c0e965e222900e1fdee417a73242e408943d9fb0

URL: https://github.com/llvm/llvm-project/commit/c0e965e222900e1fdee417a73242e408943d9fb0
DIFF: https://github.com/llvm/llvm-project/commit/c0e965e222900e1fdee417a73242e408943d9fb0.diff

LOG: [Statepoints] FixupStatepoint: Clear isKill flag if COPY is not deleted.

When spilling CSRs, FixupStatepoint pass does simple copy propagation,
trying to find COPY instruction which defines register being spilled
and spill COPY source instead. I.e., if we have CSR $x and found
  $x = COPY $y
we will spill $y instead.
But we may be unable to delete COPY instruction for some reason.
Then, spill will be inserted after it, adding another use of $y.
If COPY instruction was last use of $y (killed it), after insertion of
the spill it is not, so `isKill` flag must be cleared. We failed to do
so and this patch fixes this issue.

Reviewed By: skatkov

Differential Revision: https://reviews.llvm.org/D127308

Added: 
    

Modified: 
    llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
    llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
index 7aa484ad78d6a..252910fd94627 100644
--- a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
+++ b/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
@@ -153,12 +153,17 @@ static Register performCopyPropagation(Register Reg,
   RI = ++MachineBasicBlock::iterator(Def);
   IsKill = DestSrc->Source->isKill();
 
-  // There are no uses of original register between COPY and STATEPOINT.
-  // There can't be any after STATEPOINT, so we can eliminate Def.
   if (!Use) {
+    // There are no uses of original register between COPY and STATEPOINT.
+    // There can't be any after STATEPOINT, so we can eliminate Def.
     LLVM_DEBUG(dbgs() << "spillRegisters: removing dead copy " << *Def);
     Def->eraseFromParent();
+  } else if (IsKill) {
+    // COPY will remain in place, spill will be inserted *after* it, so it is
+    // not a kill of source anymore.
+    const_cast<MachineOperand *>(DestSrc->Source)->setIsKill(false);
   }
+
   return SrcReg;
 }
 

diff  --git a/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir b/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir
index 523005566ec77..d03c3ebce5622 100644
--- a/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir
+++ b/llvm/test/CodeGen/X86/statepoint-fixup-copy-prop.mir
@@ -1,4 +1,4 @@
-# RUN: not --crash llc -o - %s -run-pass fixup-statepoint-caller-saved -verify-machineinstrs 2>&1 | FileCheck %s
+# RUN: llc -o - %s -run-pass fixup-statepoint-caller-saved -verify-machineinstrs | FileCheck %s
 
 --- |
   target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
@@ -21,22 +21,11 @@ body:             |
   bb.0:
     liveins: $rax, $rdi, $rbp
 
-
-    ; CHECK: # After Fixup Statepoint Caller Saved
-    ; CHECK: # Machine code for function test_cp:
-    ; CHECK:   bb.0:
-    ; CHECK:     liveins: $rax, $rdi, $rbp
-    ; CHECK:   renamable $rdi = COPY killed renamable $rax
+    ; CHECK:   renamable $rdi = COPY renamable $rax
     ; CHECK:   MOV64mr %stack.1, 1, $noreg, 0, $noreg, killed $rax :: (store (s64) into %stack.1)
     ; CHECK:   renamable $rax = MOV64rm renamable $rdi, 1, $noreg, 16, $noreg
     ; CHECK:   MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed $rax :: (store (s64) into %stack.0)
-    ; CHECK:   STATEPOINT 0, 0, 0, @foo, 2, 0, 2, 0, 2, 1, 1, 8, %stack.0, 0, 2, 1, 1, 8, %stack.1, 0, 2, 0, 2, 1, 0, 0, <regmask $bh $bl $bp $bph $bpl $bx $ebp $ebx $hbp $hbx $rbp $rbx $r12 $r13 $r14 $r15 $r12b $r13b $r14b $r15b $r12bh $r13bh $r14bh $r15bh $r12d $r13d $r14d $r15d $r12w $r13w $r14w $r15w $r12wh and 3 more...>, implicit-def $rsp, implicit-def $ssp
-    ; CHECK: *** Bad machine code: Using an undefined physical register ***
-    ; CHECK: - function:    test_cp
-    ; CHECK: - basic block: %bb.0
-    ; CHECK: - instruction: MOV64mr %stack.1, 1, $noreg, 0, $noreg, killed $rax :: (store (s64) into %stack.1)
-    ; CHECK: - operand 5:   killed $rax
-    ; CHECK: LLVM ERROR: Found 1 machine code errors.
+    ; CHECK:   STATEPOINT 0, 0, 0, @foo, 2, 0, 2, 0, 2, 1, 1, 8, %stack.0, 0, 2, 1, 1, 8, %stack.1, 0, 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp :: (load (s64) from %stack.0), (load store (s64) on %stack.1)
     renamable $rdi = COPY killed renamable $rax
     renamable $rax = MOV64rm renamable $rdi, 1, $noreg, 16, $noreg
     renamable $rdi = STATEPOINT 0, 0, 0, @foo, 2, 0, 2, 0, 2, 1, renamable $rax, 2, 1, killed renamable $rdi(tied-def 0), 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp


        


More information about the llvm-commits mailing list