<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 - [MSP430][AVR][InstCombine][DAGCombine]Poor codegen for targets with no native shifts (4/8)"
   href="https://bugs.llvm.org/show_bug.cgi?id=44041">44041</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[MSP430][AVR][InstCombine][DAGCombine]Poor codegen for targets with no native shifts (4/8)
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>joan.lluch@icloud.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A number of comparisons involving bit tests are converted into shifts by
InstCombine and DAGCombine. However, shifts are expensive for most 8 and 16 bit
targets with comparatively cheaper selects. 

It is desirable that selects are emitted instead of shifts for these targets.
The following cases were identified in TargetLowering and DAGCombine and were
fixed by:

<a href="https://reviews.llvm.org/D69116">https://reviews.llvm.org/D69116</a> 
<a href="https://reviews.llvm.org/D69120">https://reviews.llvm.org/D69120</a>
<a href="https://reviews.llvm.org/D69326">https://reviews.llvm.org/D69326</a>
<a href="https://reviews.llvm.org/D70042">https://reviews.llvm.org/D70042</a>

Cases in InstCombine remain to be fixed. In llvm-dev it has been suggested that
these cases should be fixed by reversing the current canonicalisation. I am
showing them in this and following reports:

REPORTED CASE:

Source code:

int testExtendSignBit_1( int x )  // (InstCombineCasts::transformZExtICmp)
{
  return x>-1 ? 1 : 0;
}

IR code:

define i16 @testExtendSignBit_1(i16 %x) {
entry:
  %x.lobit = lshr i16 %x, 15
  %x.lobit.not = xor i16 %x.lobit, 1
  ret i16 %x.lobit.not
}

MSP430 Target code:

testExtendSignBit_1:
        inv     r12
        swpb    r12
        mov.b   r12, r12
        clrc
        rrc     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        ret

AVR Target code:

testExtendSignBit_1:
        com     r24
        com     r25
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        lsr     r25
        ror     r24
        ret


EXPECTED RESULT:

Source code:

int testExtendSignBit_1( int x )  // (InstCombineCasts::transformZExtICmp)
{
  return x>-1 ? 1 : 0;
}

Expected IR code:

define i16 @testExtendSignBit_1(i16 %x) {
entry:
  %cmp = icmp sgt i16 %x, -1
  %cond = zext i1 %cmp to i16
  ret i16 %cond
}



Expected MSP430 Target code: 

testExtendSignBit_1:
        mov     r12, r13
        mov     #1, r12
        tst     r13
        jge     .LBB3_2
        clr     r12
.LBB3_2:
        ret


Expected AVR Target code:

testExtendSignBit_1:
        ldi     r18, 1
        tst     r25
        brpl    LBB3_2
        ldi     r18, 0
LBB3_2:
        mov     r24, r18
        clr     r25
        ret</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>