]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix ZIP1 order in aarch64_expand_vector_init [PR118891]
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 21 Jul 2025 14:41:01 +0000 (15:41 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Mon, 21 Jul 2025 14:41:01 +0000 (15:41 +0100)
aarch64_expand_vector_init contains some divide-and-conquer code
that tries to load the odd and even elements into 64-bit registers
and then ZIP them together.  On big-endian targets, the even elements
are more significant than the odd elements and so should come second
in the ZIP.

This fixes many execution failures on aarch64_be-elf, including
gcc.c-torture/execute/pr28982a.c.

gcc/
PR target/118891
* config/aarch64/aarch64.cc (aarch64_expand_vector_init): Fix the
ZIP1 operand order for big-endian targets.

(cherry picked from commit cb2b5471516c3c469f65d927a2a30eb15357e429)

gcc/config/aarch64/aarch64.cc

index 08506e95a0aa9d285ca07a13c05a912500896a5a..725339f38b6797881b3edd7a015c0ea78c6636b4 100644 (file)
@@ -24567,6 +24567,13 @@ aarch64_expand_vector_init (rtx target, rtx vals)
       emit_insn (rec_seq);
     }
 
+  /* The two halves should (by induction) be individually endian-correct.
+     However, in the memory layout provided by VALS, the nth element of
+     HALVES[0] comes immediately before the nth element HALVES[1].
+     This means that, on big-endian targets, the nth element of HALVES[0]
+     is more significant than the nth element HALVES[1].  */
+  if (BYTES_BIG_ENDIAN)
+    std::swap (halves[0], halves[1]);
   rtvec v = gen_rtvec (2, halves[0], halves[1]);
   rtx_insn *zip1_insn
     = emit_set_insn (target, gen_rtx_UNSPEC (mode, v, UNSPEC_ZIP1));