<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92602>92602</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ReduceMax_4xU8 test program fails on s390x when compiled with Clang 18.1.6
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
johnplatts
</td>
</tr>
</table>
<pre>
Here is a C test program that fails to execute correctly when compiled for the s390x-linux-gnu target (with the -O2 -mzvector options) with Clang 18.1.6, but passes when compiled for the s390x-linux-gnu target (with the -O2 -mzvector options) with GCC 12.3.0:
```
#include <stdio.h>
#include <stdlib.h>
#pragma push_macro("vector")
#pragma push_macro("pixel")
#pragma push_macro("bool")
#undef vector
#undef pixel
#undef bool
#if defined(__s390x__)
#include <vecintrin.h>
#else
#include <altivec.h>
#endif
#pragma pop_macro("vector")
#pragma pop_macro("pixel")
#pragma pop_macro("bool")
#define ALTIVEC_TEST_ASSERT(cond) \
do { \
if (!(cond)) { \
printf("Assertion " #cond " failed at line %d of %s\n", __LINE__, \
__FILE__); \
abort(); \
} \
} while (false)
#define ALTIVEC_TEST_UNLIKELY(cond) (!!__builtin_expect(cond, 0))
static inline __attribute__((__always_inline__)) __vector unsigned short
PromoteU8ToU16(__vector unsigned char v) {
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const __vector unsigned char a = v;
const __vector unsigned char b = vec_splats((unsigned char)0);
#else
const __vector unsigned char a = vec_splats((unsigned char)0);
const __vector unsigned char b = v;
#endif
return (__vector unsigned short)vec_mergeh(a, b);
}
static inline __attribute__((__always_inline__)) unsigned short ReduceMax_4xU16(
__vector unsigned short v3210) {
const __vector unsigned char kReverse4Shuffle = {
6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9};
const __vector unsigned short v0123 =
vec_perm(v3210, v3210, kReverse4Shuffle);
const __vector unsigned short v03_12_12_03 = vec_max(v3210, v0123);
const __vector unsigned short v12_03_03_12 = (__vector unsigned short)vec_rl(
(__vector unsigned int)v03_12_12_03, vec_splats(16u));
const __vector unsigned short max_val = vec_max(v03_12_12_03, v12_03_03_12);
return max_val[0];
}
static inline __attribute__((__always_inline__)) unsigned char ReduceMax_4xU8(
__vector unsigned char v) {
return (unsigned char)ReduceMax_4xU16(PromoteU8ToU16(v));
}
static __attribute__((__noinline__)) void DoTestReduceMax4xU8() {
const __vector unsigned char kInputVals = {0, 2, 4, 3, 0, 2, 4, 3,
0, 2, 4, 3, 0, 2, 4, 3};
unsigned long long non_elided_zero;
__asm__("" : "+r"(non_elided_zero)::);
unsigned char actual = ReduceMax_4xU8(
kInputVals | ((__vector unsigned char)vec_splats(non_elided_zero)));
if (actual != 4) {
printf("Actual result of ReduceMax_4xU8: %u\n", (unsigned)actual);
abort();
}
}
int main(int argc, char** argv) {
printf("Running test\n");
DoTestReduceMax4xU8();
printf("Test completed successfully\n");
return 0;
}
```
The above program compiles and runs correctly when compiled for the powerpc64-linux-gnu and powerpc64le-linux-gnu targets with the -O2 -mcpu=power8 options with Clang 18.1.6.
Here is the output that is generated by the above program when compiled for s390x-linux-gnu with the -O2 -mzvector options with Clang 18.1.6:
```
Running test
Actual result of ReduceMax_4xU8: 2
Aborted (core dumped)
```
Here is the expected output of the above test program:
```
Running test
Test completed successfully
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WF9v6jgW_zTm5agocaCEBx4o0N1qu3dWLXekebJMciCeNXZkO5TOp1_ZCTRJaUuvdhBKqfPL-fs7Jz7m1oqdQpyR8R0ZLwe8coU2sz91oUrJnbODjc5fZ_9EgyAscFiAQ-ugNHpn-B5cwR1suZAWnAY8YlY5hEwbg5mTr_BSoIJM70shMYetNuAKBJtMo-ONFKo63uxUBY6bHTogNH0RrgiQm98o3Oz_OmDmtAFdOqGVJXQKAbGQXO0gTofx8JbQBWwqByW3Fu3fpfEfiwXEdJ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