<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63498>63498</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] [mlir] Why is `-mmlir --math-runtime=precise` not enabled by default when the optimization level is -O2?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
This issue is not a bug report, just a question. My question is, why is `-mmlir --math-runtime=precise` not enabled by default when the optimization level is -O2?
Here's the background to this question.
I checked if flang-new passes the Netlib LAPACK tests. In LAPACK's Makefile, the optimization level of the Fortran compiler is -O2, and if you use this as it is, you can run the test as follows.
```shell
$ diff make.inc.example make.inc
9c9
< CC = clang
---
> CC = gcc
20,21c20,21
< FC = flang-new
< FFLAGS = -O2
---
> FC = gfortran
> FFLAGS = -O2 -frecursive
23c23
< FFLAGS_NOOPT = -O0
---
> FFLAGS_NOOPT = -O0 -frecursive
46c46
< #TIMER = INT_ETIME
---
> TIMER = INT_ETIME
50c50
< TIMER = INT_CPU_TIME
---
> #TIMER = INT_CPU_TIME
$ make
```
I used LAPACK 3.11.0 and got the following result:
```shell
--> LAPACK TESTING SUMMARY <--
Processing LAPACK Testing output found in the TESTING directory
SUMMARY nb test run numerical error other error
================ =========== ================= ================
REAL 1327023 0 (0.000%) 0 (0.000%)
DOUBLE PRECISION 1327845 0 (0.000%) 0 (0.000%)
COMPLEX 282008 27027 (9.584%) 1855 (0.658%)
COMPLEX16 282791 27170 (9.608%) 1856 (0.656%)
--> ALL PRECISIONS 3219667 54197 (1.683%) 3711 (0.115%)
```
You can see errors in COMPLEX and COMPLEX16 tests. Then, after I enabled `-mmlir --math-runtime=precise`, I ran the test again as follows and got the following result:
```shell
$ diff make.inc.example make.inc
9c9
< CC = gcc
---
> CC = clang
20,21c20,21
< FC = gfortran
< FFLAGS = -O2 -frecursive
---
> FC = flang-new
> FFLAGS = -O2 -mmlir --math-runtime=precise
23c23
< FFLAGS_NOOPT = -O0 -frecursive
---
> FFLAGS_NOOPT = -O0
46c46
< TIMER = INT_ETIME
---
> #TIMER = INT_ETIME
50c50
< #TIMER = INT_CPU_TIME
---
> TIMER = INT_CPU_TIME
$ make
```
```shell
--> LAPACK TESTING SUMMARY <--
Processing LAPACK Testing output found in the TESTING directory
SUMMARY nb test run numerical error other error
================ =========== ================= ================
REAL 1327023 0 (0.000%) 0 (0.000%)
DOUBLE PRECISION 1327845 0 (0.000%) 0 (0.000%)
COMPLEX 786775 0 (0.000%) 0 (0.000%)
COMPLEX16 787842 0 (0.000%) 0 (0.000%)
--> ALL PRECISIONS 4229485 0 (0.000%) 0 (0.000%)
```
As you can see, in this case, no errors were observed at all.
Personally, I don't like the default state where it gives errors in tests of very famous apps like LAPACK. Also in my opinion, if the optimization level is -O2, it is desirable to turn off optimizations that cause numerical errors. I think that's why LAPACK's Makefile also specifies -O2 instead of -Ofast.
This is a matter of policy and may not be an issue that I should insist on further. However, I would like to know if some decisions have already been made in Flang community. I have noticed that the simillar issue (https://github.com/llvm/llvm-project/issues/58799) is still open.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWFtz4joS_jXmpQuXLd8feGBIOIfa3GqSqd3zNCXsNuhEllhJhmV__ZZkzC1kSM7Mbq2KCrHU_fVFan1uqNZsIRBHXvLFS24GtDVLqUavQ6qU3OjBXFbb0cuSaWBatwhMg5AGKMzbBShcSWU8MoE_W20n_9miNkwKH-B-u38Cpq3MZrm16l4aDJuGMwXDYUPNcqhaYViDXnSzUlgyjV4aOCMo6JxjBfMtVFjTlhvYLFGAWSLIlWEN-zd1-BzXyC328JF40dQLbrxg3P39HRV6JNNOaU7L14WSrajASDA2qoPHx1ozKJdYvmIFrIaaU7EYCtzAimqNHdQDGs7mcDd-Gk_-Bga10T7MxG7CWbynr1gzjjb2d1yWtVuZSmUUFVDKZsU4qj4UMgEqn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