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

    <tr>
        <th>Summary</th>
        <td>
            Wrong x86 binary generated with -O1 optimization level. Division by zero FPE exception. (Regression since Clang 16)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Following code (with -O1) throws signal SIGFPE due division by zero.
```

#include <cfenv>

double calc(int field)
{

  volatile int dField = 0;

  // make a or c non-zero to pass a without exception
  volatile double a = 0;
 volatile double c = 0;

  double fSource = 2;
  double dSource = 1;
  
 const double AUXD = a;
  const double AUXE = c;
  const double AUX = AUXD + AUXE;
  if (AUX > 1.0)// && AUX != 0.0) // this check forces Clang generate correct binary
  {
    dSource = AUXE / AUX;
    fSource = AUXD / AUX;
 }

  if (field == dField)
    return dSource;
  else 
    return fSource;
}

int main() {

    feenableexcept(FE_ALL_EXCEPT);

    auto d = calc(3);

    return d;
}
```
Affected Clang 16 and later versions. Checked at godbolt service. Wrong machine code is generated. 
Looks like a bug with optimization algorithm.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE1v4zYQ_TXUZRCBomxZOujgJFZRIEAX3Rbd24IiRxIbmjRIStnsry-oD8fOogBhC3iP8_H4Zrj3qjeINdk_kv1zwscwWFdf-IRaKz5Zw8ektfK9bqzW9k2ZHoSVCISVbyoM8PBHRlgFYXD2zUMMxjV8_f235ssJ5Igg1aS8sgbad_iJzqaEHklB10OP8bBcGaHHGDV_Eh2aieSnBZN2bDWC4FoQVioToFOoJWFVxA-PCwtgspoHpREiRTaRAyR_BkryK4ewhrAGzvwVgYN1IMBY8xCrgmDhwr0HDrErOwbAHwIvQVlzH38tiN9G_wUVv-Rege6rHZ3AGWbr5Q2TN1i2YfFHWOPDxjr-_e15pvCN8hk-zbD4P3hGlyjsceZvTNXFV10oJ8hSGlVeNCOsIKxYrrNsbm6GN03DoDyIAcUrdNYJ9PCkuemhR4OOBwRhnUMRoFWGu_eltcOSFu46XxpgTfzYCoM73dbabxnk8LwJvTTRbQaIFxY7LJaJwRyG0Zkt65YEtUe4Z3S3jGuO6LAzV4awclbgw4QAHaLhrcbFPISVzen78eXl--nb0-nLX7GE_IbNx2Bh8elq8PwzZav1roab8Tl2HYqActU7K4AbCZoHdDChi5PnU3iKL4MSeIDeytbqAB7dpASm8I-zpoczF4MyuMy28teHk2nU5MXaVw9azYPTjv08JGAvQZ3VTx6HBLjurVNhOKeJrHNZ5RVPsM4OO5rtD5RlyVDvZFbJdtdlBStYJbK93CFtCywpz0sp20TVjLI9ZSzLiv2BZinlBS8p5VUlM9lVnOwonrnSqdbTObWuT5T3I9YZKxmlieYtaj-vMsZEFIQwFreaq-OFh3bsPdlRrXzwHyGCChrrRYYfZbFa9EMB2PbcfcMaJ9QpPH_abxAX33V3pNGMf2Lv0M8kr4zA61sRViWj0_UQwsWT_LgMU6_CMLapsGfCmljl-vdwcfZfFIGwZu7aE9asjU81-y8AAP__NIG_3w">