<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 - [GlobalISel][AArch64] i1 value in aggregate not zero-extend prior to store"
   href="https://bugs.llvm.org/show_bug.cgi?id=37397">37397</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[GlobalISel][AArch64] i1 value in aggregate not zero-extend prior to store
          </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>Linux
          </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>Backend: AArch64
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>tstellar@redhat.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>efriedma@codeaurora.org, jistone@redhat.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>36649
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This testcase comes from  <a href="https://github.com/rust-lang/rust/issues/50516">https://github.com/rust-lang/rust/issues/50516</a> and
shows that GlobalISel does not zero-extend an i1 value to 8-bits prior to
writing it to memory:

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
define void @i1_store() {
start:
  %tmp0 = alloca { i32, i1 }, align 4
  %tmp1 = call { i32, i1 } @foo()
  store { i32, i1 } %tmp1, { i32, i1 }* %tmp0, align 4
  ret void
}
declare { i32, i1 } @foo()

llc -O0 gives us:

        sub     sp, sp, #32             // =32
        str     x30, [sp, #16]          // 8-byte Folded Spill
        .cfi_def_cfa_offset 32
        .cfi_offset w30, -16
        bl      foo
                                        // implicit-def: $x8
        mov     w9, w0
        bfxil   x8, x9, #0, #32
        mov     w9, w1
        bfi     x8, x9, #32, #1
        str     x8, [sp, #8]


i1 values are stored in memory as 8-bit values, but it is expected that value
will be either 0x0 or 0x1.  In this case, since Bits 33-39 of x8 remain
uninitialized, when this value is loaded there will be random values in the
high 7-bits.

Fast-ISel seems to handle this test case correctly:


        sub     sp, sp, #32             // =32
        str     x30, [sp, #16]          // 8-byte Folded Spill
        .cfi_def_cfa_offset 32
        .cfi_offset w30, -16
        bl      foo
        str     w0, [sp, #8]
        and     w0, w1, #0x1
        strb    w0, [sp, #12]
        ldr     x30, [sp, #16]          // 8-byte Folded Reload
        add     sp, sp, #32             // =32
        ret</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [meta] 6.0.1 Release Blockers"
   href="https://bugs.llvm.org/show_bug.cgi?id=36649">Bug 36649</a>] [meta] 6.0.1 Release Blockers
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>