<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58579>58579</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] validation failure in 416.gamess@ref
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:ir,
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vzakhari
</td>
</tr>
</table>
<pre>
Specdiff is reporting the following miscompare:
```
0397: EXTRAP=T DAMP=T SHIFT=T RSTRCT=F DIIS=F SOSCF=T
EXTRAP=T DAMP=F SHIFT=F RSTRCT=F DIIS=F SOSCF=T
^
```
Values computed for `DAMP` is not passed correctly to Fortran runtime:
```
4019 SUBROUTINE UHFOP(SZ,S2)
...
4187 DAMPH = MOD(MCONV,4) .GE. 2
4188 VSHIFT = MOD(MCONV,8) .GE. 4
...
4591 IF(SOME) WRITE(IW,9020) EN,MAXIT,MPUNCH,MUL,EXTRAH,DAMPH,
4592 * VSHIFT,RSTRCT,DODIIS,SOSCF
```
The problem appears after `SLPVectorizerPass` with `-march=native` (Icelake), but it is just a trigger.
I believe the following C++ test demonstrates the problem:
1. `repro.cpp` mimics the Fortran code:
```
extern void printer(bool x);
__attribute__((noinline)) void test(int x) {
bool t1 = (x % 4) >= 2;
bool t2 = (x % 8) >= 4;
printer(t1);
printer(t2);
}
int main() {
test(65);
}
```
2. `report_rt.cpp` mimics Fortran runtime code that prints logical values:
```
#include <cstdint>
#include <cstdio>
__attribute__((noinline)) void printer2(void *x) {
printf("%s\n", *(std::int8_t *)x ? "T" : "F");
}
__attribute__((noinline)) void printer(bool x) {
printer2(reinterpret_cast<void *>(&x));
}
```
Compilation commands to reproduce the issue:
```
$ clang++ repro.cpp -march=native -O3 -emit-llvm -Xclang -disable-llvm-passes -S -o repro_orig.ll
$ clang++ -march=native -O3 repro_rt.cpp repro_orig.ll
$ ./a.out
F
F
```
This is the correct result above, but it becomes incorrect (as with Flang generated code) when I remove `zeroext` attribute from `_Z7printerb` in `repro_orig.ll` - see attached `repro_error.ll`:
```
$ clang++ -march=native -O3 repro_rt.cpp repro_error.ll
$ ./a.out
T
T
```
So the problem is that the caller of `printer` does not zero extends the `i1` argument before the calls as required by ABI because of the missing `zeroext` attribute.
[repro_orig.ll.gz](https://github.com/llvm/llvm-project/files/9855978/repro_orig.ll.gz)
[repro_error.ll.gz](https://github.com/llvm/llvm-project/files/9855979/repro_error.ll.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVltvozoQ_jXkxQoKBpLwkIc0CaeRtk3VpN3VvkQOGOJdg3OM6bb768-MIbc20ekeHYTAl5nxzHxz8Ualb6PljiepyDIiKqL5TmkjypyYLSeZklL9wlkhqkQVO6a544-d3tTpjZ1-r33ttOdHA9gjzTP7tnocPzj-dEXIdHzXjpa383jVDB-Xq8cJjmMgmM-XzWi5WE5iJGhkkpPngsT4KDH-DxLPHyecXbSr-T4zWfOKoA9qw1PwjCZAYhXp99BzpTJkx6oKNhOlNU-MfCNGkRj8qVlJdF0aUVx1Hwl6XtSqsny6eVw8reb3M_J0Gy8eHDpcfnfoZEkdGjXkruvu-bzhoOVDbW7BEn9K7hZT4LqbLO6fgTEAPkLcv2YuoUe2Ycv2bJ14gW14ZAs-HBtG3tF58xh1XNzNkOPr43wFg-H8K8iIerSHi7N7mNyNv81X-H94up_c4uDpC3wttDi1BsD_eAZtwaEXkGv0BvIWeeBfWODBUxb163CuILh3Wm0kLwjb7TjTFWGZ4RbU5ZeHZ4BPafGb6weAFBH-JcwWN7sF08kWfFUyI144bqGpCZfsJ0d46IRsakOEwaD4UVeGMGK0yHOu3VMV5mTDpeAv_F2mTRx6Ay8xHFhTXqiygviBmaVrlT5EkeeiUpC1WrnJbofqFKIQSUO9j71EpVcDj7-C2SV5USIF6aKEGRi0UUqSV7THvznVer1mBqwBC_l6DXTwlkqUUpSN8VEjCJWHLZBmhRBncLPPPyvZeDbcgOQVPiG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