<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - If-conversion fails to remove CPSR operand on thumb instructions, causing incorrect assembly"
   href="https://bugs.llvm.org/show_bug.cgi?id=42285">42285</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>If-conversion fails to remove CPSR operand on thumb instructions, causing incorrect assembly
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>john.brawn@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If you compile the following:

 int a, b;
 int c() { return b <= 0 && a && b && 7 / b ? b : b * a; }

with clang --target=arm-none-eabi -march=armv8-a -S -Os -mthumb then in the
assembly output you see

        it      eq
        mulseq  r0, r1, r0

This mulseq is invalid, and if you try to assemble it you get an invalid
instruction error. If you generate an object file directly though you get

        it      eq
        muleq   r0, r1, r0

which is correct.

What's going on here is that the 16-bit mul instruction is flags-setting
outside of an IT block, and non-flags-setting inside of it. This is modelled in
LLVM using an optional CPSR operand: if the operand is present then it's
flags-setting, if it's not then it's not. The CPSR operand is initially present
but marked as dead, then when deciding whether to predicate it
ARMBaseInstrInfo::isPredicable asks isEligibleForITBlock which asks
ARMBaseInstrInfo::isCPSRDefined which says CPSR is not defined as it's dead.

The logic deciding that it is safe to predicate the mul looks correct here, so
we just need to remove the dead CPSR operand. Looks like either
ARMBaseInstrInfo::PredicateInstruction or possibly
Thumb2ITBlockPass::InsertITInstructions would be the place to do this.</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>