native_interpret_real in fold_const.c has an assumption that floats are at least 32-bits (on bigendian targets with UNITS_PER_WORD >= 4). This patch relaxes that assumption (allowing e.g. 16-bit HFmode values).

On aarch64_be-none-elf, this fixes the float16x4_t variant of gcc.target/aarch64/advsimd-intrinsics/vcreate.c added in the next patch in series.

Bootstrapped + check-gcc on:
x86-unknown-linux-gnu
powerpc64-unknown-linux-gnu (gcc110 on compile farm, as I believe this is bigendian, as opposed to powerpc64le-unknown-linux-gnu on gcc112)
arm-none-linux-gnueabihf
aarch64-none-elf

It's not clear that any of those actually test this code, but the aarch64_be-none-elf tests in next patch definitely do ;).

gcc/ChangeLog:

        fold-const.c (native_interpret_real): Correctly read floats of less
        than 32 bits on bigendian targets.
commit f8ad02fecdb7b6f91bab77cc154a246bd719ac20
Author: Alan Lawrence <alan.lawre...@arm.com>
Date:   Thu Apr 9 10:54:40 2015 +0100

    Fix native_interpret_real for HFmode floats on Bigendian with UNITS_PER_WORD>=4
    
    (with missing space)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6d085b1..52bc8e9 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7625,7 +7625,7 @@ native_interpret_real (tree type, const unsigned char *ptr, int len)
 	    offset += byte % UNITS_PER_WORD;
 	}
       else
-	offset = BYTES_BIG_ENDIAN ? 3 - byte : byte;
+	offset = BYTES_BIG_ENDIAN ? MIN (3, total_bytes - 1) - byte : byte;
       value = ptr[offset + ((bitpos / BITS_PER_UNIT) & ~3)];
 
       tmp[bitpos / 32] |= (unsigned long)value << (bitpos & 31);

Reply via email to