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

    <tr>
        <th>Summary</th>
        <td>
            [llvm] Incorrect simplification of fabs intrinsic
        </td>
    </tr>

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

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

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

<pre>
    The below test case fails at optimization levels greater than -O1
```cpp
#include <math.h>
#include <stdio.h>

__attribute__((noinline))
int test(double a, double b)
{
 int maxIdx = 0;
  double maxDot = 0.0;
  for (int i = 0; i < 2; ++i) {
 double dot = a * b;
    if (fabs(dot) > fabs(maxDot)) {
      maxIdx = i;
 maxDot = dot;
    }
  }
  return maxIdx;
}

int main(int argc, char *argv[])
{

  int i = test(1.0, -1.0);
  int failed = (i != 0);

 printf("Returned %d, should be 0: %s\n", i, (failed ? "failed" : "success"));

  return failed;
}
```

This is a regression introduced in #76360

The bug is due to https://github.com/llvm/llvm-project/pull/76360/files#diff-532fd830a7b080a7121645e6c8dccb2f94a7e25450c74aa496b8600f8f4481ccR6220

comparing a std::optional<bool> to false rather than dereferencing it (maybe we need a way to warn about this? it's a super easy error)


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVE2P4ygQ_TXkUuqIFHZsH3JIJxNpTiuN5t7ioxwzIhAB7o_99Suw092rPW1kxZiq93i8KpAp2asnOrD2mSGGP9PsM0Nk7Xkj5zyFeFjmNiqYj8PviUCRC2-QKWXQMhGM0roEMkO4Z3uzf8tsgwdHr-QSXCPJTBHyJD08_bVj_Mj2fHn0_V4-UViv3WwImDjdZJ62ExM__hNJ2djwGeLHlxeZc7RqzvTywrBn2PtgvbOeGA7l4UfrcxXKsDdhVo5AMjzBOlZLEuueGT9Cyb3J95_mHZg4A2eiTj-Sb_L9HPIS2n4GxxC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