<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109113>109113</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SystemZ] Bad Codegen for vec_gfmsum_accum_128
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
saitama951
</td>
</tr>
</table>
<pre>
Recently the dotnet team started seeing Compression test case failures. These tests fail when zlib-ng is compiled with clang.
on deeper inspection I have managed extract a test case from zlib-ng.
```
#include "stdio.h"
#include <vecintrin.h>
typedef unsigned char uv16qi __attribute__((vector_size(16)));
typedef unsigned int uv4si __attribute__((vector_size(16)));
typedef unsigned long long uv2di __attribute__((vector_size(16)));
int main()
{
const uv2di r2r1 = {0x1C6E41596, 0x154442BD4};
uv2di v1 = {7381244131595332141, 2315514454429938015};
uv16qi part1 = {97, 116, 115, 32, 109, 111, 114, 102, 32, 115, 101, 110, 105, 108, 32, 100};
uv2di result = (uv2di)vec_gfmsum_accum_128(r2r1, v1, part1);
printf("value 1: %llu\n value 2: %llu\n", result[0],result[1]);
return 0;
}
```
The results are as follows with gcc and clang:
```
[sanjam@s390x ~]$ gcc -g bug-clang.c -march=z15 -mzvector -o b.out
[sanjam@s390x ~]$ ./b.out
value 1: 7022364300429628393
value 2: 4831923049869144086
[sanjam@s390x ~]$ clang -g bug-clang.c -march=z15 -fzvector
[sanjam@s390x ~]$ ./a.out
value 1: 1591483802437686806
value 2: 1591483802437686806
```
now on inspect the disassembly I see this:
```
static inline __ATTRS_o_ai __vector unsigned char
vec_gfmsum_accum_128(__vector unsigned long long __a,
__vector unsigned long long __b,
__vector unsigned char __c) {
return (__vector unsigned char)
__builtin_s390_vgfmag(__a, __b, (unsigned __int128)__c);
1258: e7 00 b1 08 30 06 vl %v0,264(%r11),3
125e: e7 10 b0 f8 30 06 vl %v1,248(%r11),3
1264: e7 20 b0 e8 30 06 vl %v2,232(%r11),3
126a: e7 00 13 00 20 bc vgfmag %v0,%v0,%v1,%v2
1270: e7 00 00 03 20 21 vlgvf %r0,%v0,3
return (__vector unsigned char)
1276: e7 00 00 00 00 62 vlvgp %v0,%r0,%r0
127c: e7 00 00 07 00 4d vrepb %v0,%v0,7
1282: e7 00 b0 a0 30 0e vst %v0,160(%r11),3
```
here the sequence
```
1270: e7 00 00 03 20 21 vlgvf %r0,%v0,3
1276: e7 00 00 00 00 62 vlvgp %v0,%r0,%r0
127c: e7 00 00 07 00 4d vrepb %v0,%v0,7
```
looks strange, I believe this should be directly doing a `vst` after the `vgfmag`?
clang version:
```
clang version 20.0.0git (https://github.com/llvm/llvm-project a26ec542371652e1d774696e90016fd5b0b1c191)
Target: s390x-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sanjam/llvm-project/build/bin
```
cc: @uweigand @JonPsson
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV0tv4zgS_jX0pWCDL70OPnTsCdB7WszktBeBksoSZyTKQ1JK0of97QtScmJ3O5ntwQiCyiSLX73Ij7RyTrcGcU-SB5IcN2ry3Wj3TmmvBlUkbFONzev-V6zR-P4VfIfQjN6gB49qAOeV9diAQ9SmhcM4nC06p0cDHp2HWjmEk9L9ZNHt4KlDh3HExV547tDAt15XW9OCdlCPw1n32MCz9h3UvTLtjtAjoV9GAw3iGS1o485Y-2DjK3RqRhiUUS02gC_eqtqDujZux-FiYYVavyld36XJhTZ1PzUIhHPnGz3uOsL5j6PiMGOtjbfa7Doiflk0_OsZGzzBZGJGG6g7ZWGaWfqnhrJU3ltdTR7LkvCc8HzG2o-2dPobEp6zlPBifcXDB4jaeJhm6f4pvH407fKZZt78TdTlG1wblDZxVrGOZKsKrE89GudXW5ZbBkQcgWQP9IUd0l8kS4qU8APQF5ZIKfnDUZLs-GbogrLMn99mZyJnXEomWFIkQnAmWUDhgiUJkzKRkheFyClL7qPFAp2V9W-IRRYAGEsXkQQheGzQ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