<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [PATCH] armv5te thumb1 target generated UB code mov tGPR, tGPR (should => adds GPR,GPR,#0)"
   href="http://llvm.org/bugs/show_bug.cgi?id=17921">17921</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[PATCH] armv5te thumb1 target generated UB code mov tGPR, tGPR (should => adds GPR,GPR,#0)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: ARM
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dontbugme@mailinator.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Dear LLVM ARM backend developers,

llc generates invalid armv5te code, as per
<a href="https://android.googlesource.com/toolchain/binutils/+/92337cf27b1497415e3f345ea9292e96ced2a8fa">https://android.googlesource.com/toolchain/binutils/+/92337cf27b1497415e3f345ea9292e96ced2a8fa</a>

The following patch is a sketch, still somewhat problematic - it should be
active only for armv5te thumb1, and the CPSR clobber might have some unintended
consequences (perhaps this belongs somewhere else than copyPhysReg?)

Someone more well-versed in ARM target please take a look at it.

- anonymous

Index: lib/Target/ARM/Thumb1InstrInfo.cpp
===================================================================
--- lib/Target/ARM/Thumb1InstrInfo.cpp    (revision 194564)
+++ lib/Target/ARM/Thumb1InstrInfo.cpp    (working copy)
@@ -40,10 +40,17 @@

 void Thumb1InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
                                   MachineBasicBlock::iterator I, DebugLoc DL,
                                   unsigned DestReg, unsigned SrcReg,
                                   bool KillSrc) const {
+
+  if (isARMLowRegister(SrcReg) && isARMLowRegister(DestReg)) {
+    AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tADDrr),
DestReg).addReg(ARM::CPSR) // s suffix
+        .addReg(SrcReg, getKillRegState(KillSrc)).addImm(0));
+    return;
+  }
+
   AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tMOVr), DestReg)
     .addReg(SrcReg, getKillRegState(KillSrc)));
   assert(ARM::GPRRegClass.contains(DestReg, SrcReg) &&
          "Thumb1 can only copy GPR registers");
 }</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>