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

    <tr>
        <th>Summary</th>
        <td>
            if statements not cleanly short-circuiting on Apple Silicon with optimizations
        </td>
    </tr>

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

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

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

<pre>
    - x-ref https://github.com/boostorg/math/pull/945

Overflows are reported for `-O2` and `-O3` due to evaluation of unsafe calculations in if-statements that should have been guarded by a previous condition short-circuiting.  We only observe this on certain versions of MacOS, e.g., Monterrey 12.6.

Reproducer:
```cpp
// main.cpp
#include <iostream>
#include <limits>
#include <cfenv>

int main(int argc, char** argv) {
    if (argc != 2) {
        return 1;
    }
 const double x = std::atof(argv[1]);
    double f1 = std::numeric_limits<double>::max();
    double res;
    if((x < 1) && (std::numeric_limits<double>::max() * x < f1)) {
        std::cout << "if branch\n";
    } else {
        std::cout << "else branch\n";
 }

    if(std::fetestexcept(FE_OVERFLOW)) {
        std::cout << "overflow reported\n";
    } else {
        std::cout << "overflow not reported\n";
    }

    return 0;
}

// output:
// else branch
//     overflow reported
```

Build:
```bash
clang++ -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -O2 -std=gnu++14 main.cpp
```

Run:
```bash
./a.out 42.0
```

Version information:
```
% clang++ --version
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVt1u2zgTfRr6ZiBBGsmKfeGLJK6AD1-LAG3R7l1BkSOLW4oU-OMk-_QLSk7qOG13A6wQSOHM8AzPoTlD7r06GKIdW9-w9X7FYxis243iu-pw1Vn5uMvgIXP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