<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 --- - [ARM64] Miscompile possibly due to incorrect fcsel"
   href="http://llvm.org/bugs/show_bug.cgi?id=19700">19700</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[ARM64] Miscompile possibly due to incorrect fcsel
          </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>Windows NT
          </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: AArch64
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mcrosier@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>apazos@codeaurora.org, llvmbugs@cs.uiuc.edu, t.p.northover@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the below IR the AArch64 backend produces the expected result, while the
ARM64 does not.

linux{169}> more bad.ll
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "arm64-none-linux-gnu"

@foo.b = internal unnamed_addr global float -1.000000e+00, align 4

define float @foo(float %a) noinline {
entry:
  %cmp = fcmp olt float %a, 1.000000e+00
  %selv = select i1 %cmp, float 1.000000e+00, float %a
  %0 = load float* @foo.b, align 4
  %cmp2 = fcmp une float %0, %selv
  %selv7 = select i1 %cmp2, float %selv, float %0
  store float %selv7, float* @foo.b, align 4
  ret float %selv7
}

define i32 @main() {
entry:
  %call = tail call float @foo(float 0.000000e+00)
  %not.cmp = fcmp une float %call, 1.000000e+00
  %cond = zext i1 %not.cmp to i32
  ret i32 %cond
}

linux{170}> clang-arm64-x bad.ll -mcpu=cortex-a53 -O3 -ffast-math -o bad
-static
linux{171}> ./qemu-aarch64 bad
linux{172}> echo $?
1

linux{173}> clang-aarch64-x bad.ll -mcpu=cortex-a53 -O3 -ffast-math -o bad
-static
linux{174}> ./qemu-aarch64 bad
linux{175}> echo $?
0

Looking at the generated assembly,

linux{176}> clang-arm64-x bad.ll -mcpu=cortex-a53 -O3 -ffast-math -o - -S
        .text
        .file   "bad.ll"
        .globl  foo
        .align  2
        .type   foo,@function
foo:                                    // @foo
// BB#0:                                // %entry
        fmov    s1, #1.00000000
        fmax    s0, s0, s1
        adrp    x8, foo.b
        ldr     s1, [x8, :lo12:foo.b]
        fcmp    s1, s0
        fcsel   s0, s1, s0, ne  <==========
        str     s0, [x8, :lo12:foo.b]
        ret
.Ltmp1:
        .size   foo, .Ltmp1-foo

The marked fcsel seems incorrect, I believe it should be fcsel s0, s0, s1, ne.</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>