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

    <tr>
        <th>Summary</th>
        <td>
            [flang][LoongArch] Runtime error in spec2017 527.cam4_r with size=ref and optimization levels "-O3"/"-Ofast"
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

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

<pre>
    Tested OS: Debian sid/experimental loong64 installed with llvm 20.1.3

Optimization setting:

`COPTIMIZE      = -g -Ofast -march=la464 -flto=auto`
`FOPTIMIZE      = -g -Ofast -march=la464 -flto=auto`

When I test spec2017 527.cam4_r with above optimization setting and ref size, I met the following error:

```
run_base_refrate_mytest_llvm_20d1d3-m64.0000 -f compare.cmd -E -e compare.err -o compare.stdout'; no non-empty output files exist
  Command returned exit code 1
****************************************
Contents of cam4_r_base.mytest_llvm_20d1d3-m64.err
****************************************
Fortran STOP
IEEE arithmetic exceptions signaled: DIVBYZERO INEXACT INVALID OVERFLOW UNDERFLOW

****************************************
*** Miscompare of cam4_validate.txt
```

The content in miscomparison file is:

```
0001: PASS:  4  points. 
        PASS:  0  points. 
              ^
```

The above error still appears when I change the optimization level of Fortran part to `-O3`. If the optimization level of Fortran part is `-O2` or lower, the program can run smoothly.

The above error only appears with ref size, with test/train sizes the program can run smoothly at optimization level of Fortran part `-Ofast`. 

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVU1v4zYQ_TX0ZSCBor7WBx-U2AYMZOMgSbPtXgxaGllsKVIgR0mcX19QdrLbNlsssIcQBExzPPS8NzNvpPfqYBAXLL9g-XImR-qsW8iX0aH_68iT2d42x8U9esIGtncsrWCJeyUNeNUwscbnAZ3q0ZDUoK01hyIDZTxJrbGBJ0UdaP3Yg-BxEqeMV4xX24FUr14kKWvAI5E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