<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56204>56204</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Commit that relands _Float16 type support on X86 causes correctness error
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bgra8
      </td>
    </tr>
</table>

<pre>
    Last reland of the _Float16 type support on X86 ([655ba9c8a1d220](https://github.com/llvm/llvm-project/commit/655ba9c8a1d22075443711cc749f0b032e07adee)) causes correctness error.

Reproducer:

`float myabs(float value) {
  if (value > 0) return value;
  return value * (-1.f);
}

// The test passes if we remove the `__attribute__((noinline))`.
void __attribute__((noinline)) apply_myabs(
    const __fp16* input, __fp16* output, int size) {
  for (int i = 0; i < size; i++) {
    const __fp16 value = input[i];
    output[i] = myabs(value);
  }
}

bool is_near(float value, float expected, float epsilon) {
  auto diff = value - expected;
  if (diff < 0) {
    diff *= -1;
  }
  return diff <= epsilon;
}

int main(int argc, char* argv[]) {
  const __fp16 input_values[] = {1, -1, 0};
  const __fp16 output_ref[] = {1, 1, 0};
  __fp16 output[3];
  apply_myabs(input_values, output, 3);
  for (int i = 0; i < 3; ++i) {
    if (!is_near(output[i], output_ref[i], 1e-3f)) {
      return 1;
    }
  }

  return 0;
}
`

Command to build the test:
`clang -O3 test.cc -o /tmp/a.out`

Building with clang at the specified commit will exit with 1 and at the previous version will exit with 0.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVcGO4ygQ_Rr7gmJhYzvJwYckvX0aaaTVHvZmYQwJK2IswOnt_fotwO7EmcysVoocoF4VVfUe0On-s_lGrUOGKzr0SAvkLhy170pTl9fIfY4c2WkctXFID-jPXY2SYpdUx7qqOrpnO5r3RYGT6g2WL86NNiGHpHiH31m6y9RlTF9hotRt-duMRv_FmYMp2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