diff --git a/gcc/expr.cc b/gcc/expr.cc index 4d1a6f3dd1c..ba00226c4e7 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -5976,9 +5976,9 @@ mem_ref_refers_to_non_mem_p (tree ref) static bool store_field_updates_msb_p (poly_int64 bitpos, poly_int64 bitsize, rtx to_rtx) { - poly_int64 to_size = GET_MODE_SIZE (GET_MODE (to_rtx)); - poly_int64 bitnum = BYTES_BIG_ENDIAN ? to_size - bitsize - bitpos : bitpos; - return maybe_eq (bitnum + bitsize, to_size); + return (BYTES_BIG_ENDIAN + ? maybe_le (bitpos, 0) + : maybe_ge (bitpos + bitsize, GET_MODE_BITSIZE (GET_MODE (to_rtx)))); } /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL diff --git a/gcc/testsuite/gcc.dg/torture/pr124435.c b/gcc/testsuite/gcc.dg/torture/pr124435.c new file mode 100644 index 00000000000..d9e1edf9f62 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr124435.c @@ -0,0 +1,18 @@ +/* { dg-do run { target le } } */ + +short c; + +__attribute__((__noipa__)) short +foo (short s) +{ + __builtin_memmove (1 + (char *) &s, &c, 1); + return s >> 10; +} + +int +main () +{ + short x = foo (-6); + if (x) + __builtin_abort(); +}