[llvm-branch-commits] [llvm] 3bdf450 - [NFC] [TargetRegisterInfo] add one use check to lookThruCopyLike.

Chen Zheng via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Jan 17 17:06:33 PST 2021


Author: Chen Zheng
Date: 2021-01-17T19:56:42-05:00
New Revision: 3bdf4507b66348ad78df4655a8e4f36c3fc10f3c

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

LOG: [NFC] [TargetRegisterInfo] add one use check to lookThruCopyLike.

add one use check to lookThruCopyLike.

The root node is safe to be deleted if we are sure that every
definition in the copy chain only has one use.

Reviewed By: jsji

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

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/TargetRegisterInfo.h
    llvm/lib/CodeGen/TargetRegisterInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h
index 6f32729a1e83..e07779e04b7b 100644
--- a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h
@@ -410,10 +410,13 @@ class TargetRegisterInfo : public MCRegisterInfo {
 
   /// Returns the original SrcReg unless it is the target of a copy-like
   /// operation, in which case we chain backwards through all such operations
-  /// to the ultimate source register.  If a physical register is encountered,
+  /// to the ultimate source register. If a physical register is encountered,
   /// we stop the search.
+  /// If one definition in the copy chain has multiple uses, set \p
+  /// AllDefHaveOneUser to false, otherwise set it to true.
   virtual Register lookThruCopyLike(Register SrcReg,
-                                    const MachineRegisterInfo *MRI) const;
+                                    const MachineRegisterInfo *MRI,
+                                    bool *AllDefHaveOneUser = nullptr) const;
 
   /// Return a null-terminated list of all of the callee-saved registers on
   /// this target. The register should be in the order of desired callee-save

diff  --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp
index 4a190c9f50af..09c7383a291b 100644
--- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp
@@ -510,13 +510,19 @@ TargetRegisterInfo::getRegSizeInBits(Register Reg,
   return getRegSizeInBits(*RC);
 }
 
-Register
-TargetRegisterInfo::lookThruCopyLike(Register SrcReg,
-                                     const MachineRegisterInfo *MRI) const {
+Register TargetRegisterInfo::lookThruCopyLike(Register SrcReg,
+                                              const MachineRegisterInfo *MRI,
+                                              bool *AllDefHaveOneUser) const {
+  if (AllDefHaveOneUser)
+    *AllDefHaveOneUser = true;
+
   while (true) {
     const MachineInstr *MI = MRI->getVRegDef(SrcReg);
-    if (!MI->isCopyLike())
+    if (!MI->isCopyLike()) {
+      if (AllDefHaveOneUser && !MRI->hasOneNonDBGUse(SrcReg))
+        *AllDefHaveOneUser = false;
       return SrcReg;
+    }
 
     Register CopySrcReg;
     if (MI->isCopy())
@@ -526,8 +532,11 @@ TargetRegisterInfo::lookThruCopyLike(Register SrcReg,
       CopySrcReg = MI->getOperand(2).getReg();
     }
 
-    if (!CopySrcReg.isVirtual())
+    if (!CopySrcReg.isVirtual()) {
+      if (AllDefHaveOneUser)
+        *AllDefHaveOneUser = false;
       return CopySrcReg;
+    }
 
     SrcReg = CopySrcReg;
   }


        


More information about the llvm-branch-commits mailing list