From 495db1a1155904059e4239dc124c85717245d761 Mon Sep 17 00:00:00 2001 From: Andreas Krebbel Date: Tue, 25 Apr 2006 12:11:25 +0000 Subject: expmed.c (store_bit_field): Handle paradoxical subregs on big endian machines. 2006-04-25 Andreas Krebbel * expmed.c (store_bit_field): Handle paradoxical subregs on big endian machines. 2006-04-25 Andreas Krebbel * gcc.dg/20060425-1.c: New testcase. From-SVN: r113248 --- gcc/ChangeLog | 5 +++++ gcc/expmed.c | 20 +++++++++++++++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/20060425-1.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/20060425-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d88406..eb38288 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2006-04-25 Andreas Krebbel + + * expmed.c (store_bit_field): Handle paradoxical subregs on big endian + machines. + 2006-04-25 Bernd Schmidt * genmodes.c (make_vector_mode): Allow making VECTOR_MODE_INT of a diff --git a/gcc/expmed.c b/gcc/expmed.c index a4396c2..31b8241 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -363,7 +363,25 @@ store_bit_field (rtx str_rtx, unsigned HOST_WIDE_INT bitsize, meaningful at a much higher level; when structures are copied between memory and regs, the higher-numbered regs always get higher addresses. */ - bitnum += SUBREG_BYTE (op0) * BITS_PER_UNIT; + int inner_mode_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))); + int outer_mode_size = GET_MODE_SIZE (GET_MODE (op0)); + + byte_offset = 0; + + /* Paradoxical subregs need special handling on big endian machines. */ + if (SUBREG_BYTE (op0) == 0 && inner_mode_size < outer_mode_size) + { + int difference = inner_mode_size - outer_mode_size; + + if (WORDS_BIG_ENDIAN) + byte_offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD; + if (BYTES_BIG_ENDIAN) + byte_offset += difference % UNITS_PER_WORD; + } + else + byte_offset = SUBREG_BYTE (op0); + + bitnum += byte_offset * BITS_PER_UNIT; op0 = SUBREG_REG (op0); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3392b96..f29ab27 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-04-25 Andreas Krebbel + + * gcc.dg/20060425-1.c: New testcase. + 2006-04-25 Jakub Jelinek PR tree-optimization/26865 diff --git a/gcc/testsuite/gcc.dg/20060425-1.c b/gcc/testsuite/gcc.dg/20060425-1.c new file mode 100644 index 0000000..7d899b2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20060425-1.c @@ -0,0 +1,38 @@ +/* { dg-do run } */ +/* { dg-options "-O1" } */ + +/* This failed because if conversion didn't handle insv patterns properly. */ + +void abort (void); + +union y +{ + int a; + unsigned short b; +}; + +void __attribute__ ((noinline)) +bar (unsigned short u, union y v) +{ + if (u != 1) + abort (); +} + +void __attribute__ ((noinline)) +foo (int check) +{ + union y x; + + if (check != 0) + x.b = 1; + else + x.b = 2; + bar (x.b, x); +} + +int +main () +{ + foo (1); + return 0; +} -- cgit v1.1