[llvm] 963287a - Add a baseline test for D131958

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 05:50:42 PDT 2022


Author: Alex Richardson
Date: 2022-09-21T12:50:12Z
New Revision: 963287acbf42867a8f7a14b1db0043daf22174f2

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

LOG: Add a baseline test for D131958

This test shows that the save of MIPS $zero to a callee-saved register
is not elided by the machine-cp pass.

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

Added: 
    llvm/test/CodeGen/AArch64/avoid-zero-copy.mir
    llvm/test/CodeGen/Mips/avoid-zero-copy.mir

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/AArch64/avoid-zero-copy.mir b/llvm/test/CodeGen/AArch64/avoid-zero-copy.mir
new file mode 100644
index 0000000000000..4558a1108d8fa
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/avoid-zero-copy.mir
@@ -0,0 +1,40 @@
+# Check that we can remove the redundant save of constant registers such as $wzr
+# RUN: llc -mtriple=aarch64-unknown-linux %s -verify-machineinstrs -start-before=machine-cp -o - | FileCheck %s --check-prefix ASM
+# RUN: llc -mtriple=aarch64-unknown-linux %s -verify-machineinstrs -run-pass=machine-cp -o - | FileCheck %s
+--- |
+  target triple = "aarch64-unknown-linux"
+  declare i32 @bar(i32) nounwind
+  define i32 @foo() nounwind {
+  ; ASM-LABEL: foo:
+  ; ASM:       // %bb.0:
+  ; ASM-NEXT:    stp x30, x19, [sp, #-16]! // 16-byte Folded Spill
+  ; ASM-NEXT:    mov w0, wzr
+  ; ASM-NEXT:    mov w19, wzr
+  ; ASM-NEXT:    bl bar
+  ; ASM-NEXT:    mov w0, w19
+  ; ASM-NEXT:    ldp x30, x19, [sp], #16 // 16-byte Folded Reload
+  ; ASM-NEXT:    ret
+    call i32 @bar(i32 0)
+    ret i32 0
+  }
+...
+---
+name: foo
+body: |
+  bb.0 (%ir-block.0):
+    ; CHECK-LABEL: name: foo
+    ; CHECK: ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
+    ; CHECK-NEXT: renamable $w19 = COPY $wzr
+    ; CHECK-NEXT: $w0 = COPY $wzr
+    ; CHECK-NEXT: BL @bar, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
+    ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
+    ; CHECK-NEXT: $w0 = COPY killed renamable $w19
+    ; CHECK-NEXT: RET_ReallyLR implicit $w0
+    ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
+    renamable $w19 = COPY $wzr
+    $w0 = COPY renamable $w19
+    BL @bar, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
+    ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
+    $w0 = COPY killed renamable $w19
+    RET_ReallyLR implicit $w0
+...

diff  --git a/llvm/test/CodeGen/Mips/avoid-zero-copy.mir b/llvm/test/CodeGen/Mips/avoid-zero-copy.mir
new file mode 100644
index 0000000000000..e617c7d91d9ad
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/avoid-zero-copy.mir
@@ -0,0 +1,45 @@
+# Check that we can remove the redundant save of constant registers such as $zero
+# RUN: llc -mtriple=mips64-unknown-freebsd %s -start-before=machine-cp -o - | FileCheck %s --check-prefix ASM
+# RUN: llc -mtriple=mips64-unknown-freebsd %s -verify-machineinstrs -run-pass=machine-cp -o - | FileCheck %s
+--- |
+  target triple = "mips64-unknown-freebsd"
+  define i32 @a() nounwind {
+  ; ASM-LABEL: a:
+  ; ASM:       # %bb.0:
+  ; ASM-NEXT:    daddiu $sp, $sp, -16
+  ; ASM-NEXT:    sd $ra, 8($sp) # 8-byte Folded Spill
+  ; ASM-NEXT:    sd $16, 0($sp) # 8-byte Folded Spill
+  ; ASM-NEXT:    move $16, $zero
+  ; ASM-NEXT:    jalr $25
+  ; ASM-NEXT:    move $4, $zero
+  ; ASM-NEXT:    move $4, $16
+  ; ASM-NEXT:    ld $16, 0($sp) # 8-byte Folded Reload
+  ; ASM-NEXT:    ld $ra, 8($sp) # 8-byte Folded Reload
+  ; ASM-NEXT:    jr $ra
+  ; ASM-NEXT:    daddiu $sp, $sp, 16
+    ret i32 0
+  }
+...
+---
+name:            a
+body:             |
+  bb.0 (%ir-block.0):
+    liveins: $a0_64, $t9_64, $ra_64, $fp_64, $gp_64
+    ; CHECK-LABEL: name: a
+    ; CHECK: liveins: $a0_64, $t9_64, $ra_64, $fp_64, $gp_64
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
+    ; CHECK-NEXT: renamable $s0_64 = COPY $zero_64
+    ; CHECK-NEXT: $a0_64 = COPY $zero_64
+    ; CHECK-NEXT: JALR64Pseudo $t9_64, csr_n64, implicit-def dead $ra, implicit $a0_64, implicit $gp_64, implicit-def $sp, implicit-def $v0
+    ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
+    ; CHECK-NEXT: $a0_64 = COPY killed renamable $s0_64
+    ; CHECK-NEXT: PseudoReturn64 undef $ra_64, implicit $v0_64, implicit killed $a0_64
+    ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
+    renamable $s0_64 = COPY $zero_64
+    $a0_64 = COPY renamable $s0_64
+    JALR64Pseudo $t9_64, csr_n64, implicit-def dead $ra, implicit $a0_64, implicit $gp_64, implicit-def $sp, implicit-def $v0
+    ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
+    $a0_64 = COPY killed renamable $s0_64
+    PseudoReturn64 undef $ra_64, implicit $v0_64, implicit killed $a0_64
+...


        


More information about the llvm-commits mailing list