<div dir="ltr">What about the other code which was converted to use reg_nodbg_empty in r242173? Shouldn't it also be moved back to isPhysRegUsed now?</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 18, 2015 at 2:54 PM, Matthias Braun via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: matze<br>
Date: Tue Aug 18 13:54:27 2015<br>
New Revision: 245329<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=245329&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=245329&view=rev</a><br>
Log:<br>
MachineRegisterInfo: Introduce isPhysRegUsed()<br>
<br>
This method checks whether a physical regiser or any of its aliases are<br>
used in the function.<br>
<br>
Using this function in SIRegisterInfo::findUnusedReg() should also fix<br>
this reported failure:<br>
<br>
<a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/292143.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/292143.html</a><br>
<a href="http://reviews.llvm.org/rL242173#inline-533" rel="noreferrer" target="_blank">http://reviews.llvm.org/rL242173#inline-533</a><br>
<br>
The report doesn't come with a testcase and I don't know enough about<br>
AMDGPU to create one myself.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h<br>
    llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp<br>
    llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp<br>
    llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h?rev=245329&r1=245328&r2=245329&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h?rev=245329&r1=245328&r2=245329&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h (original)<br>
+++ llvm/trunk/include/llvm/CodeGen/MachineRegisterInfo.h Tue Aug 18 13:54:27 2015<br>
@@ -644,9 +644,16 @@ public:<br>
   /// Return true if the specified register is modified in this function.<br>
   /// This checks that no defining machine operands exist for the register or<br>
   /// any of its aliases. Definitions found on functions marked noreturn are<br>
-  /// ignored.<br>
+  /// ignored. The register is also considered modified when it is set in the<br>
+  /// UsedPhysRegMask.<br>
   bool isPhysRegModified(unsigned PhysReg) const;<br>
<br>
+  /// Return true if the specified register is modified or read in this<br>
+  /// function. This checks that no machine operands exist for the register or<br>
+  /// any of its aliases. The register is also considered used when it is set<br>
+  /// in the UsedPhysRegMask.<br>
+  bool isPhysRegUsed(unsigned PhysReg) const;<br>
+<br>
   /// addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.<br>
   /// This corresponds to the bit mask attached to register mask operands.<br>
   void addPhysRegsUsedFromRegMask(const uint32_t *RegMask) {<br>
<br>
Modified: llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp?rev=245329&r1=245328&r2=245329&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp?rev=245329&r1=245328&r2=245329&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/ExecutionDepsFix.cpp Tue Aug 18 13:54:27 2015<br>
@@ -733,13 +733,12 @@ bool ExeDepsFix::runOnMachineFunction(Ma<br>
   // completely.<br>
   bool anyregs = false;<br>
   const MachineRegisterInfo &MRI = mf.getRegInfo();<br>
-  for (TargetRegisterClass::const_iterator I = RC->begin(), E = RC->end();<br>
-       I != E && !anyregs; ++I)<br>
-    for (MCRegAliasIterator AI(*I, TRI, true); AI.isValid(); ++AI)<br>
-      if (!MRI.reg_nodbg_empty(*AI)) {<br>
-        anyregs = true;<br>
-        break;<br>
-      }<br>
+  for (unsigned Reg : *RC) {<br>
+    if (MRI.isPhysRegUsed(Reg)) {<br>
+      anyregs = true;<br>
+      break;<br>
+    }<br>
+  }<br>
   if (!anyregs) return false;<br>
<br>
   // Initialize the AliasMap on the first use.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp?rev=245329&r1=245328&r2=245329&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp?rev=245329&r1=245328&r2=245329&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/MachineRegisterInfo.cpp Tue Aug 18 13:54:27 2015<br>
@@ -489,3 +489,15 @@ bool MachineRegisterInfo::isPhysRegModif<br>
   }<br>
   return false;<br>
 }<br>
+<br>
+bool MachineRegisterInfo::isPhysRegUsed(unsigned PhysReg) const {<br>
+  if (UsedPhysRegMask.test(PhysReg))<br>
+    return true;<br>
+  const TargetRegisterInfo *TRI = getTargetRegisterInfo();<br>
+  for (MCRegAliasIterator AliasReg(PhysReg, TRI, true); AliasReg.isValid();<br>
+       ++AliasReg) {<br>
+    if (!reg_nodbg_empty(*AliasReg))<br>
+      return true;<br>
+  }<br>
+  return false;<br>
+}<br>
<br>
Modified: llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp?rev=245329&r1=245328&r2=245329&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp?rev=245329&r1=245328&r2=245329&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp (original)<br>
+++ llvm/trunk/lib/Target/AMDGPU/SIRegisterInfo.cpp Tue Aug 18 13:54:27 2015<br>
@@ -495,12 +495,9 @@ unsigned SIRegisterInfo::getPreloadedVal<br>
 //         AMDGPU::NoRegister.<br>
 unsigned SIRegisterInfo::findUnusedRegister(const MachineRegisterInfo &MRI,<br>
                                            const TargetRegisterClass *RC) const {<br>
-<br>
-  for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();<br>
-       I != E; ++I) {<br>
-    if (MRI.reg_nodbg_empty(*I))<br>
-      return *I;<br>
-  }<br>
+  for (unsigned Reg : *RC)<br>
+    if (!MRI.isPhysRegUsed(Reg))<br>
+      return Reg;<br>
   return AMDGPU::NoRegister;<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>