https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117283
Bug ID: 117283 Summary: [RISC-V] Miscompilation triggered by `__riscv_vsseg7e32_v_i32m1x7`, GCC 14.2.0 at `-O1`, `-O2`, `-O3`, and `-Os`. Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: yibohe at pku dot edu.cn Target Milestone: --- For the following code with rvv intrinsics, I load data from a to c, and from b to d. There seems to be a miscompilation: ``` #include <riscv_vector.h> int printf(const char *, ...); #define dataLen 520 int32_t a[dataLen]; int32_t b[dataLen]; int32_t c[dataLen]; int32_t d[dataLen]; int main(){ int32_t tmp_a[dataLen] = {-48, 111, -33, 24, 127, -88, -60, -106, 62, 125, -18, 120, 99, -94, 107, -70, 8, -105, -126, 127, 61, -75, 124, 21, 88, -79, 74, 105, -85, 6, -107, 31, -38, -52, 70, -55, 71, 19, 70, 18, 114, 75, 90, 81, 90, -11, 33, 76, 1, -23, 54, -33, 89, 90, -128, 50, -28, 28, 7, -1, 12, 21, -86, -32, 39, 94, 91, 22, -20, -81, 84, 71, -20, -113, -67, 71, -60, 48, -10, 15, -42, 22, 67, 119, -103, -73, -89, 108, 58, 4, 12, 35, -59, -53, -33, -31, -108, -25, -56, -112, 39, 111, -52, -104, -25, 5, 78, -28, -46, 33, 29, 22, -45, -124, -33, -79, 87, 105, 122, 88, 94, -37, 94, 74, -118, 60, 115, -95, -128, -114, -34, -26, -65, -75, -40, 125, 66, 88, 120, -119, 50, -44, 1, -41, -33, -42, 48, 32, 45, 62, -77, -96, 110, -111, -100, -33, 21, -5, -17, 22, -77, -36, 68, 2, -25, -79, -110, -127, 43, 45, 70, 52, 7, -24, 26, -15, -3, -40, 55, 95, 71, -27, 70, 107, -10, 115, -85, 29, 125, -28, -111, 44, -61, 81, 89, -69, -8, -23, 122, 52, 38, -101, -126, 5, -123, 26, 29, 81, 100, 43, -113, -66, -79, -42, 113, 22, -69, 77, -5, -16, 8, -75, 124, -67, 98, -117, -24, -108, -38, 113, -123, -119, 120, 75, -116, -24, -95, 83, -86, 66, -85, -35, -79, -83, -63, -72, -106, -47, -48, 86, -37, 9, -23, -125, 27, -75, -64, -73, -63, -114, -62, 93, 15, 94, -77, -16, -115, -17, -64, -113, -61, -85, -124, -50, 48, 30, -93, 52, 36, 92, 8, 75, 53, 63, -67, 13, -31, 62, 79, 48, 115, 54, 4, 88, -26, 77, -71, 102, 80, -97, 57, 32, -108, -25, -85, 10, -105, -73, -14, -115, -33, -4, -55, 6, -58, 6, 88, 25, 31, -32, 48, -87, 14, -111, 1, -1, 32, -74, 122, 79, -41, -71, 93, 64, 34, 28, 81, 13, 96, 102, 50, 126, 107, -91, -86, 48, -66, -106, -24, 101, -48, 122, -49, -77, 18, 112, -36, -128, -19, -82, -78, 106, -52, 120, 19, 86, 74, -26, -53, -26, -71, -35, 122, -96, 46, 124, 51, -44, 50, -113, 31, -59, -125, 81, -17, -15, 7, -36, -30, 85, -127, -60, 84, -17, -88, 64, 101, -104, -12, -36, 33, -34, -23, -121, 77, 8, 111, -60, 74, 89, 60, 127, -48, -111, 88, -77, -114, -109, -110, 16, 27, 38, 13, -5, -111, 124, -4, 55, -128, 87, -32, -54, -54, -100, -57, -12, 37, -31, 80, 50, 64, 32, 10, 5, 77, 127, 22, -11, -116, -4, -19, 96, -50, 0, 9, -80, 62, -48, -98, -128, -96, -25, 3, 68, 41, -47, -39, 70, 122, -8, -105, -112, -78, -38, 67, -111, 1, 22, -63, 27, 29, -122, -33, 74, 47, 109, 14, 51, 79, 72, 108, -26, -30, 60, 20, -55, 109, -3, 1, -103, -52, 73, -33, -127, -3, -22, 59, 83, -23, 5, -104, 53, 41, 98, 89, -83, -72, 63, 69, -10, }; int32_t tmp_b[dataLen] = {56, 126, -104, -122, 36, -39, 78, 24, -51, 25, -59, -51, 117, 53, -98, 79, 102, 61, -31, -109, 126, 31, -34, 6, -103, -70, -36, -65, -65, 98, -121, -4, -19, -83, -40, -110, -12, 73, -74, 26, -56, -71, 66, -70, -16, -110, -48, -46, -112, -74, -104, -25, 48, 122, 52, 37, -82, -14, 102, 104, -86, 44, 99, 105, -78, 45, -49, 18, -108, 115, -22, -58, -75, 107, 126, -21, 45, -127, 42, 80, 36, -85, -7, 107, -14, -103, -52, -25, -78, 116, -67, 64, 49, 23, 74, 26, 77, -58, 68, 86, -73, -108, -54, 12, 96, 19, -4, -73, -112, -7, -10, 102, -26, 99, 110, -26, 94, -72, -111, -68, -55, -100, 118, -56, -38, 124, 76, -61, 107, 43, -105, 25, -81, -42, 6, -126, -66, -57, 44, 57, -10, -108, -9, -118, 33, -64, 15, 72, -33, 49, 105, 36, 30, 100, -62, 76, -8, -69, -78, -11, -26, -46, 54, -16, -46, -17, -111, 92, -27, -29, -22, -83, -46, 2, 57, 105, -101, -28, -105, 94, -104, 1, 123, 97, 43, 41, 23, 107, -78, 97, -93, -91, 33, 9, 69, -50, -81, 126, 90, 17, 29, 96, 33, 57, -113, -17, -2, -62, -59, -21, 88, 2, 71, -23, 89, -8, -111, -80, 69, 64, 48, -114, 93, -14, -38, -68, 32, 65, 107, 1, -115, -80, -6, 101, -62, -108, 91, 123, -80, -124, -98, 42, -15, 37, 30, 105, -67, 69, -125, -28, -46, -99, 53, -63, -124, 89, 78, 38, -69, 80, -108, 87, -53, 121, 51, 82, 108, 41, 1, -122, -25, 107, 99, 102, 25, 42, -3, -75, -65, -112, 22, -105, 108, 76, -83, -121, -99, 33, 60, -91, 110, -77, -66, -7, 59, 51, 124, -86, 13, 47, 82, -45, 27, 69, 107, -124, -8, -103, -1, 20, 117, 83, 85, -83, 112, 73, -116, 10, -110, 103, -14, -24, 19, -31, -122, 64, 25, -39, -73, -87, -53, -70, 61, 123, -47, 113, 83, -59, -99, -50, -119, -66, -86, -98, -56, 49, -97, 62, 20, -57, 17, -75, 6, 119, 93, 102, 114, 65, -118, -123, 90, -111, 37, -62, -72, 107, -9, -93, -116, 94, -117, -58, -15, -29, 27, -118, 80, -19, -18, 90, 45, 117, -85, 87, 82, -46, 112, -44, 73, -86, -7, -39, -12, -31, 36, -21, -40, 12, -25, -85, 29, -116, 93, -101, -23, -92, -106, -11, 58, -117, -61, -125, -67, 92, 113, 35, 100, 92, -35, 126, 77, 75, 116, -106, 124, 72, 69, -46, 66, -49, -80, 112, -24, 19, 1, 110, -43, 1, 72, 5, 22, 66, 10, -21, 108, -8, -56, 20, 30, 42, -115, -63, 102, 103, -114, 7, -118, -52, 20, -105, -97, 40, 64, 20, -102, 78, 84, 37, 124, -104, -100, 75, 101, 49, 14, -25, 121, 40, -60, -92, -7, 14, 109, 26, 120, -106, -89, -83, 59, -9, 55, 29, 73, -101, -128, 12, 29, -120, 41, 110, 91, 59, -54, 57, 32, 62, 56, -97, -53, -128, -109, 82, 75, -112, 59, -26, 24, -110, -9, -101, }; for (int i = 0; i < dataLen; ++i) { a[i] = tmp_a[i]; } for (int i = 0; i < dataLen; ++i) { b[i] = tmp_b[i]; } for (int i = 0; i < dataLen; ++i) { c[i] = 0; } for (int i = 0; i < dataLen; ++i) { d[i] = 0; } int placeholder0 = dataLen; int32_t* ptr_a = a; int32_t* ptr_b = b; int32_t* ptr_c = c; int32_t* ptr_d = d; for (size_t vl; placeholder0 > 0; placeholder0 -= vl){ vl = __riscv_vsetvl_e32m1(placeholder0); vint32m1_t va = __riscv_vle32_v_i32m1(ptr_a, vl); vint32m1x7_t vb = __riscv_vlsseg7e32_v_i32m1x7(ptr_b, 1, vl); __riscv_vse32_v_i32m1(ptr_c, va, vl); __riscv_vsseg7e32_v_i32m1x7(ptr_d, vb, vl); ptr_a += vl; ptr_b += vl; ptr_c += vl; ptr_d += vl; } for(int i=0; i<dataLen; ++i) if(c[i] != a[i]) { printf("failed!\n"); __builtin_abort(); } return 0; } ``` The code failed on GCC 14.2.0 and qemu 9.1.0. ``` $ riscv64-unknown-elf-gcc --version riscv64-unknown-elf-gcc () 14.2.0 Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ qemu-riscv64 --version qemu-riscv64 version 9.1.0 Copyright (c) 2003-2024 Fabrice Bellard and the QEMU Project developers ``` Link to the Compiler Explorer: https://godbolt.org/z/4h3K4E1dP