<html>
    <head>
      <base href="https://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 --- - [AArch64] Miscompile - zeroing of high order bits omitted during bfi"
   href="https://llvm.org/bugs/show_bug.cgi?id=31138">31138</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64] Miscompile - zeroing of high order bits omitted during bfi
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>pirama@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>arnaud.degrandmaison@arm.com, james.molloy@arm.com, kristof.beyls@arm.com, llvm-bugs@lists.llvm.org, silviu.baranga@arm.com, srhines@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17638" name="attach_17638" title="Files to reproduce issue">attachment 17638</a> <a href="attachment.cgi?id=17638&action=edit" title="Files to reproduce issue">[details]</a></span>
Files to reproduce issue

Clang seems to be miscompile function decompressETC2Block in
tcuCompressedTexture.cpp [1] (which seems to happen between r256229 and
r271374).  The crux of the issue is miscompilation of the sequence (starting
line 597):

const deUint8   B1a             = (deUint8)getBit(src, 51);
const deUint8   B1b             = (deUint8)getBits(src, 47, 49);
...
baseB[0]                = extend4To8((deUint8)((B1a << 3) | B1b));
...
paintB[1]               = (deUint8)deClamp32((int)baseB[0] - dist, 0, 255);

This gets compiled to: (from attached broken_annotated.asm)

2171:  // x10 = src >> 51
2172:    5c:    d373fc2a        lsr     x10, x1, #51

2436:  // x13 = src >> 47
2437:   3ac:    d36ffc2d        lsr     x13, x1, #47

2461:  // before: w13 = (src >> 47) (line 2437)
2462:  // before: w10 = (src >> 51) (line 2172)
2463:  // w13[3:+1] = w10[0:1]
2464:  // w13 = (w13 & ~(1<<3)) | ((w10 & 1) << 3)
2465:  // w13 = (B1a << 3) | B1b
2466:  // PROBLEM: bits 4..31 are garbage - see later at line 2502
2467:   3c8:    331d014d        bfi     w13, w10, #3, #1

2500:  // w13 = extend4To8(w13)
2501:  // w13 = extend4To8((B1a << 3) | B1b) (baseB[0])
2502:   3ec:    331c0dad        bfi     w13, w13, #4, #4
2503:  // PROBLEM: bits 8..31 are garbage - see later at line 2581

2580:  // w13 = baseB[0] - dist
2580:   448:    4b0a01ad        sub     w13, w13, w10
2580:  // PROBLEM: operating as 32-bit value but bits 8..31 of w13 are garbage

The above asm was generated from the complete source file.  I've attached the
.ii from a reduced version of the same file (so the addresses and registers are
a bit different).

To compile it, run:
clang++ -c -O2 -mcpu=cortex-a53 -target aarch64-linux-android -fPIC  -o
deqp_reduced.o deqp_reduced.ii -save-temps

[1]
<a href="https://android.googlesource.com/platform/external/deqp/+/master/framework/common/tcuCompressedTexture.cpp">https://android.googlesource.com/platform/external/deqp/+/master/framework/common/tcuCompressedTexture.cpp</a></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>