[PATCH] D70699: [CriticalAntiDepBreaker] Teach the regmask clobber check to check if any subregister is preserved before considering the super register clobbered

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 15:33:16 PST 2019


craig.topper created this revision.
craig.topper added reviewers: atrick, MatzeB, qcolombet, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

X86 has some calling conventions where bits 127:0 of a vector register are callee saved, but the upper bits aren't. Previously we could detect that the full ymm register was clobbered when the xmm portion was really preserved. This patch checks the subregisters to make sure they aren't preserved.

Fixes PR44140


https://reviews.llvm.org/D70699

Files:
  llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
  llvm/test/CodeGen/X86/pr44140.ll


Index: llvm/test/CodeGen/X86/pr44140.ll
===================================================================
--- llvm/test/CodeGen/X86/pr44140.ll
+++ llvm/test/CodeGen/X86/pr44140.ll
@@ -23,7 +23,7 @@
 ; CHECK-NEXT:    # =>This Inner Loop Header: Depth=1
 ; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm0
 ; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm1
-; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm6
+; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm7
 ; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm2
 ; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm3
 ; CHECK-NEXT:    vmovups %ymm0, {{[0-9]+}}(%rsp)
@@ -31,10 +31,10 @@
 ; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm1
 ; CHECK-NEXT:    vmovups %ymm3, {{[0-9]+}}(%rsp)
 ; CHECK-NEXT:    vmovups %ymm2, {{[0-9]+}}(%rsp)
-; CHECK-NEXT:    vmovups %ymm6, {{[0-9]+}}(%rsp)
+; CHECK-NEXT:    vmovups %ymm7, {{[0-9]+}}(%rsp)
 ; CHECK-NEXT:    vmovups %ymm3, {{[0-9]+}}(%rsp)
 ; CHECK-NEXT:    vmovups %ymm2, {{[0-9]+}}(%rsp)
-; CHECK-NEXT:    vmovups %ymm6, {{[0-9]+}}(%rsp)
+; CHECK-NEXT:    vmovups %ymm7, {{[0-9]+}}(%rsp)
 ; CHECK-NEXT:    vmovups %ymm1, {{[0-9]+}}(%rsp)
 ; CHECK-NEXT:    vmovups %ymm1, {{[0-9]+}}(%rsp)
 ; CHECK-NEXT:    vmovups {{[0-9]+}}(%rsp), %ymm5
Index: llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
===================================================================
--- llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
+++ llvm/lib/CodeGen/CriticalAntiDepBreaker.cpp
@@ -261,15 +261,28 @@
     for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
       MachineOperand &MO = MI.getOperand(i);
 
-      if (MO.isRegMask())
-        for (unsigned i = 0, e = TRI->getNumRegs(); i != e; ++i)
+      if (MO.isRegMask()) {
+        for (unsigned i = 0, e = TRI->getNumRegs(); i != e; ++i) {
           if (MO.clobbersPhysReg(i)) {
-            DefIndices[i] = Count;
-            KillIndices[i] = ~0u;
-            KeepRegs.reset(i);
-            Classes[i] = nullptr;
-            RegRefs.erase(i);
+            // Make sure all subregisters are also clobbered.
+            bool PreservesSubReg = false;
+            for (MCSubRegIterator SRI(i, TRI, true); SRI.isValid(); ++SRI) {
+              if (!MO.clobbersPhysReg(*SRI)) {
+                PreservesSubReg = true;
+                break;
+              }
+            }
+
+            if (!PreservesSubReg) {
+              DefIndices[i] = Count;
+              KillIndices[i] = ~0u;
+              KeepRegs.reset(i);
+              Classes[i] = nullptr;
+              RegRefs.erase(i);
+            }
           }
+        }
+      }
 
       if (!MO.isReg()) continue;
       Register Reg = MO.getReg();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70699.230981.patch
Type: text/x-patch
Size: 2640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191125/57de9aa9/attachment.bin>


More information about the llvm-commits mailing list