Hi Avinash, I noticed only a few typos and formatting issues in the patch. On 22/10/26 11:26 am, Avinash Jayakar wrote: > From: Avinash Jayakar <[email protected]> > > The results produced by the intrinsic vec_genpcvm were wrong for LE > targets and the test case xxgenpc-runnable.c had incorrect expected > results, due to which the BE target reported it as failed. > > For preserving the bi-endian semantics of this built-in the input as > well as the ouput has to be reversed based on the type for LE targets.
Typo: ouput should be output. > Therefore in this commit, we hass a helper vsx_reverse_elts_<mode> which Typo: hass should be add?. > generates instructions to reverse the elements in a vector register > based on the mode for LE targets. Using this in the xxgenpcvm expansion > to reverse inputs and the outputs fixes the tests in both LE and BE > Bootstrapped and regtests on ppc64-linux-gnu and ppc64le-linux-gnu. Ok > for trunk? > > 2026-10-22 Avinash Jayakar <[email protected]> > > gcc/ChangeLog: > PR target/127157 > * config/rs6000/vsx.md (vsx_reverse_elts_<mode>): New expand to reverse > elements based on mode for LE targets. > (xxgenpcvm_<mode>): Reverse input and output for LE target to preserve > bi-endian semantics. > > gcc/testsuite/ChangeLog: > PR target/127157 > * gcc.target/powerpc/xxgenpc-runnable.c: Update expected > results. > --- > gcc/config/rs6000/vsx.md | 46 +++++++++++++-- > .../gcc.target/powerpc/xxgenpc-runnable.c | 58 +++++++++---------- > 2 files changed, 69 insertions(+), 35 deletions(-) > > diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md > index dfb2485f2ec..7955a150fd3 100644 > --- a/gcc/config/rs6000/vsx.md > +++ b/gcc/config/rs6000/vsx.md > @@ -3392,6 +3392,36 @@ (define_insn "xxgenpcvm_<mode>_internal" > "xxgenpcv<wd>m %x0,%1,%2" > [(set_attr "type" "vecsimple")]) > > +;; Reverse the order of the elements of a vector (element contents are > +;; preserved). V2DI is a doubleword swap (xxswapd), the other modes use > +;; a vperm with a reversed-element byte selector. > +(define_expand "vsx_reverse_elts_<mode>" > + [(use (match_operand:VSX_EXTRACT_I4 0 "register_operand")) > + (use (match_operand:VSX_EXTRACT_I4 1 "register_operand"))] > + "TARGET_POWER10" > +{ > + if (<MODE>mode == V2DImode) > + emit_insn (gen_xxswapd_<mode> (operands[0], operands[1])); > + else > + { > + int size = GET_MODE_UNIT_SIZE (<MODE>mode); > + rtx perm[16]; > + > + for (int i = 0; i < (16 / size); i++) > + for (int j=0; j < size; j++) > + { > + perm[(i * size) + (size - j - 1)] = GEN_INT ((i*size) + j); > + } > + Formatting: Please add spaces around the operators in j=0 and i*size. Thanks, Jeevitha. > + rtx sel = force_reg (V16QImode, > + gen_rtx_CONST_VECTOR (V16QImode, > + gen_rtvec_v (16, perm))); > + emit_insn (gen_altivec_vperm_<mode>_direct (operands[0], operands[1], > + operands[1], sel)); > + } > + DONE; > +}) > + > (define_expand "xxgenpcvm_<mode>" > [(use (match_operand:VSX_EXTRACT_I4 0 "register_operand")) > (use (match_operand:VSX_EXTRACT_I4 1 "register_operand")) > @@ -3400,13 +3430,17 @@ (define_expand "xxgenpcvm_<mode>" > { > if (!BYTES_BIG_ENDIAN) > { > - /* gen_xxgenpcvm assumes Big Endian order. If LE, > - change swap upper and lower double words. */ > - rtx tmp = gen_reg_rtx (<MODE>mode); > - > - emit_insn (gen_xxswapd_<mode> (tmp, operands[1])); > - operands[1] = tmp; > + /* gen_xxgenpcvm assumes Big Endian order. If LE, reverse the > + elements of the input, and reverse the elements of the result. */ > + rtx tmp_in = gen_reg_rtx (<MODE>mode); > + rtx tmp_out = gen_reg_rtx (<MODE>mode); > + > + emit_insn (gen_vsx_reverse_elts_<mode> (tmp_in, operands[1])); > + emit_insn (gen_xxgenpcvm_<mode>_internal (tmp_out, tmp_in, > + operands[2])); > + emit_insn (gen_vsx_reverse_elts_<mode> (operands[0], tmp_out)); > } > + else > emit_insn (gen_xxgenpcvm_<mode>_internal (operands[0], operands[1], > operands[2])); > DONE; > diff --git a/gcc/testsuite/gcc.target/powerpc/xxgenpc-runnable.c > b/gcc/testsuite/gcc.target/powerpc/xxgenpc-runnable.c > index d4040ea8b70..017925b62b4 100644 > --- a/gcc/testsuite/gcc.target/powerpc/xxgenpc-runnable.c > +++ b/gcc/testsuite/gcc.target/powerpc/xxgenpc-runnable.c > @@ -42,46 +42,46 @@ int main () > 0xFF, 0xFF, 0xFF, 0xFF, > 0xFF, 0xFF, 0xFF, 0xFF }; > > - vec_byte_expected0 = (vector unsigned char){ 0x1F, 0x1E, 0x1D, 0x1C, > - 0x1B, 0x1A, 0x19, 0x18, > - 0x06, 0x05, 0x15, 0x04, > - 0x03, 0x02, 0x01, 0x00 }; > + vec_byte_expected0 = (vector unsigned char){ 0x00, 0x01, 0x12, 0x02, > + 0x03, 0x04, 0x05, 0x06, > + 0x18, 0x19, 0x1a, 0x1b, > + 0x1c, 0x1d, 0x1e, 0x1f }; > > - vec_byte_expected1 = (vector unsigned char){ 0x00, 0x00, 0x00, 0x00, > + vec_byte_expected1 = (vector unsigned char){ 0x00, 0x01, 0x03, 0x04, > + 0x05, 0x06, 0x07, 0x00, > 0x00, 0x00, 0x00, 0x00, > - 0x00, 0x07, 0x06, 0x04, > - 0x03, 0x02, 0x01, 0x00 }; > + 0x00, 0x00, 0x00, 0x00 }; > > - vec_byte_expected2 = (vector unsigned char){ 0x10, 0x11, 0x12, 0x13, > - 0x14, 0x15, 0x16, 0x17, > - 0x00, 0x01, 0x1a, 0x02, > - 0x03, 0x04, 0x05, 0x06 }; > + vec_byte_expected2 = (vector unsigned char){ 0x06, 0x05, 0x1d, 0x04, > + 0x03, 0x02, 0x01, 0x00, > + 0x17, 0x16, 0x15, 0x14, > + 0x13, 0x12, 0x11, 0x10 }; > > - vec_byte_expected3 = (vector unsigned char){ 0x08, 0x09, 0x0B, 0x0C, > - 0x0D, 0x0E, 0x0F, 0x00, > + vec_byte_expected3 = (vector unsigned char){ 0x00, 0x00, 0x00, 0x00, > 0x00, 0x00, 0x00, 0x00, > - 0x00, 0x00, 0x00, 0x00 }; > + 0x00, 0x0f, 0x0e, 0x0c, > + 0x0b, 0x0a, 0x09, 0x08 }; > > vec_hword_arg = (vector unsigned short) { 0x0004, 0xF003, 0x0002, 0x0001, > 0xF004, 0x1003, 0xF002, 0x0001 }; > - vec_hword_expected0 = (vector unsigned short int){ 0x405, 0x1c1d, 0x203, > - 0x1819, 0x1617, 0x1, > - 0x1213, 0x1011 }; > - vec_hword_expected1 = (vector unsigned short int){ 0x0, 0x0, 0x0, 0x0, > - 0x0, 0xe0f, 0xa0b, 0x405 }; > - vec_hword_expected2 = (vector unsigned short int){ 0x100, 0x1312, 0x302, > - 0x1716, 0x1918, 0x504, > - 0x1d1c, 0x1f1e }; > - vec_hword_expected3 = (vector unsigned short int){ 0x100, 0x504, 0xb0a, > 0x0, > + vec_hword_expected0 = (vector unsigned short int){ 0x1011, 0x0001, 0x1415, > + 0x1617, 0x0203, 0x1a1b, > + 0x0405, 0x1e1f }; > + vec_hword_expected1 = (vector unsigned short int){ 0x0203, 0x0809, 0x0c0d, > 0x0, > 0x0, 0x0, 0x0, 0x0 }; > + vec_hword_expected2 = (vector unsigned short int){ 0x1f1e, 0x0504, 0x1b1a, > + 0x1918, 0x0302, 0x1514, > + 0x0100, 0x1110 }; > + vec_hword_expected3 = (vector unsigned short int){ 0x0, 0x0, 0x0, 0x0, > + 0x0, 0x0d0c, 0x0706, > 0x0302 }; > > vec_word_arg = (vector unsigned int){ 0xFEDCBA90, 0xF101, 0xF0000202, > 0xF303 }; > - vec_word_expected0 = (vector unsigned int){ 0x4050607, 0x18191a1b, > - 0x10203, 0x10111213 }; > - vec_word_expected1 = (vector unsigned int){ 0x0, 0x0, 0xc0d0e0f, 0x4050607 > }; > - vec_word_expected2 = (vector unsigned int){ 0x3020100, 0x17161514, > - 0x7060504, 0x1f1e1d1c }; > - vec_word_expected3 = (vector unsigned int){ 0x3020100, 0xb0a0908, 0x0, 0x0 > }; > + vec_word_expected0 = (vector unsigned int){ 0x00010203, 0x14151617, > + 0x04050607, 0x1c1d1e1f }; > + vec_word_expected1 = (vector unsigned int){ 0x00010203, 0x08090a0b, 0x0, > 0x0 }; > + vec_word_expected2 = (vector unsigned int){ 0x07060504, 0x1b1a1918, > + 0x03020100, 0x13121110 }; > + vec_word_expected3 = (vector unsigned int){ 0x0, 0x0, 0x0f0e0d0c, > 0x07060504 }; > > vec_byte_result = vec_genpcvm (vec_byte_arg, IMM0); >
