[llvm] 9cfbe7b - [PowerPC][ctrloop] handles calls in preheader before MTCTRloop

Chen Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 22:35:15 PDT 2022


Author: Chen Zheng
Date: 2022-06-21T01:22:39-04:00
New Revision: 9cfbe7bbfea762d72b60c51c8ab5dadf6b317a9a

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

LOG: [PowerPC][ctrloop] handles calls in preheader before MTCTRloop

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
    llvm/test/CodeGen/PowerPC/ctrloops32.mir
    llvm/test/CodeGen/PowerPC/ctrloops64.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp b/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
index ea3bdb937ddd..48167c3dc9ca 100644
--- a/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
+++ b/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
@@ -108,6 +108,18 @@ bool PPCCTRLoops::runOnMachineFunction(MachineFunction &MF) {
 }
 
 bool PPCCTRLoops::isCTRClobber(MachineInstr *MI, bool CheckReads) const {
+  if (!CheckReads) {
+    // If we are only checking for defs, that is we are going to find
+    // definitions before MTCTRloop, for this case:
+    // CTR defination inside the callee of a call instruction will not impact
+    // the defination of MTCTRloop, so we can use definesRegister() for the
+    // check, no need to check the regmask.
+    return (MI->definesRegister(PPC::CTR) &&
+            !MI->registerDefIsDead(PPC::CTR)) ||
+           (MI->definesRegister(PPC::CTR8) &&
+            !MI->registerDefIsDead(PPC::CTR8));
+  }
+
   if ((MI->modifiesRegister(PPC::CTR) && !MI->registerDefIsDead(PPC::CTR)) ||
       (MI->modifiesRegister(PPC::CTR8) && !MI->registerDefIsDead(PPC::CTR8)))
     return true;
@@ -115,9 +127,6 @@ bool PPCCTRLoops::isCTRClobber(MachineInstr *MI, bool CheckReads) const {
   if (MI->getDesc().isCall())
     return true;
 
-  if (!CheckReads)
-    return false;
-
   // We define the CTR in the loop preheader, so if there is any CTR reader in
   // the loop, we also can not use CTR loop form.
   if (MI->readsRegister(PPC::CTR) || MI->readsRegister(PPC::CTR8))

diff  --git a/llvm/test/CodeGen/PowerPC/ctrloops32.mir b/llvm/test/CodeGen/PowerPC/ctrloops32.mir
index 2153d738b0fc..90ee800042c3 100644
--- a/llvm/test/CodeGen/PowerPC/ctrloops32.mir
+++ b/llvm/test/CodeGen/PowerPC/ctrloops32.mir
@@ -80,6 +80,58 @@ body:             |
     BLR implicit $lr, implicit $rm
 ...
 ---
+name:            test_fail_call_in_preheader_after_mtctr
+# CHECK: test_fail_call_in_preheader_after_mtctr
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+
+    %0:gprc = LI 2048
+    ; CHECK-NOT: MTCTR
+    ; CHECK-NOT: BDNZ
+    ; CHECK: ADDI
+    ; CHECK: CMPLWI
+    ; CHECK: BC
+    MTCTRPseudo killed %0:gprc, implicit-def dead $ctr
+    BL @test_fail_use_in_loop, csr_aix32, implicit-def dead $lr, implicit $rm
+
+  bb.1:
+
+    %1:crbitrc = DecreaseCTRPseudo 1, implicit-def dead $ctr, implicit $ctr
+    BC killed %1:crbitrc, %bb.1
+    B %bb.2
+
+  bb.2:
+
+    BLR implicit $lr, implicit $rm
+...
+---
+name:            test_succ_call_in_preheader_before_mtctr
+# CHECK: test_succ_call_in_preheader_before_mtctr
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+
+    %0:gprc = LI 2048
+    BL @test_fail_use_in_loop, csr_aix32, implicit-def dead $lr, implicit $rm
+    ; CHECK: MTCTR
+    ; CHECK: BDNZ
+    ; CHECK-NOT: ADDI
+    ; CHECK-NOT: CMPLWI
+    ; CHECK-NOT: BC
+    MTCTRPseudo killed %0:gprc, implicit-def dead $ctr
+
+  bb.1:
+
+    %1:crbitrc = DecreaseCTRPseudo 1, implicit-def dead $ctr, implicit $ctr
+    BC killed %1:crbitrc, %bb.1
+    B %bb.2
+
+  bb.2:
+
+    BLR implicit $lr, implicit $rm
+...
+---
 name:            test_fail_call_in_loop
 # CHECK: test_fail_call_in_loop
 tracksRegLiveness: true

diff  --git a/llvm/test/CodeGen/PowerPC/ctrloops64.mir b/llvm/test/CodeGen/PowerPC/ctrloops64.mir
index 841faa34bf84..1d4ed84cdd6b 100644
--- a/llvm/test/CodeGen/PowerPC/ctrloops64.mir
+++ b/llvm/test/CodeGen/PowerPC/ctrloops64.mir
@@ -82,6 +82,58 @@ body:             |
     BLR8 implicit $lr8, implicit $rm
 ...
 ---
+name:            test_fail_call_in_preheader_after_mtctr
+# CHECK: test_fail_call_in_preheader_after_mtctr
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+
+    %0:g8rc = LI8 2048
+    ; CHECK-NOT: MTCTR8
+    ; CHECK-NOT: BDNZ8
+    ; CHECK: ADDI8
+    ; CHECK: CMPLDI
+    ; CHECK: BC
+    MTCTR8Pseudo killed %0:g8rc, implicit-def dead $ctr8
+    BL8 @test_fail_use_in_loop, csr_ppc64, implicit-def dead $lr8, implicit $rm
+
+  bb.1:
+
+    %1:crbitrc = DecreaseCTR8Pseudo 1, implicit-def dead $ctr8, implicit $ctr8
+    BC killed %1:crbitrc, %bb.1
+    B %bb.2
+
+  bb.2:
+
+    BLR8 implicit $lr8, implicit $rm
+...
+---
+name:            test_succ_call_in_preheader_before_mtctr
+# CHECK: test_succ_call_in_preheader_before_mtctr
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+
+    %0:g8rc = LI8 2048
+    BL8 @test_fail_use_in_loop, csr_ppc64, implicit-def dead $lr8, implicit $rm
+    ; CHECK: MTCTR8
+    ; CHECK: BDNZ8
+    ; CHECK-NOT: ADDI8
+    ; CHECK-NOT: CMPLDI
+    ; CHECK-NOT: BC
+    MTCTR8Pseudo killed %0:g8rc, implicit-def dead $ctr8
+
+  bb.1:
+
+    %1:crbitrc = DecreaseCTR8Pseudo 1, implicit-def dead $ctr8, implicit $ctr8
+    BC killed %1:crbitrc, %bb.1
+    B %bb.2
+
+  bb.2:
+
+    BLR8 implicit $lr8, implicit $rm
+...
+---
 name:            test_fail_call_in_loop
 # CHECK: test_fail_call_in_loop
 tracksRegLiveness: true


        


More information about the llvm-commits mailing list