[gcc r17-3498] avoid-store-forwarding: Reject BLKmode memory operands [PR126686]
Philipp Tomsich via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:b01cd452a6c7ba2a2f95a77f62f0727cbbe9d6a5 commit r17-3498-gb01cd452a6c7ba2a2f95a77f62f0727cbbe9d6a5 Author: Konstantinos Eleftheriou <[email protected]> Date: Thu Aug 20 03:57:02 2026 -0700 avoid-store-forwarding: Reject BLKmode memory operands [PR126686] Memory operands were only rejected when their size is unknown or non-constant, so a BLKmode store with a known size could become a forwarding candidate. Building the bit insert sequence for it asserts in store_bit_field, as BLKmode has no corresponding integer mode. Reject such memory when collecting candidates. PR rtl-optimization/126686 gcc/ChangeLog: * avoid-store-forwarding.cc (store_forwarding_analyzer::avoid_store_forwarding): Reject BLKmode stores and loads as forwarding candidates. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr126686.c: New test. Diff: --- gcc/avoid-store-forwarding.cc | 10 +++++++--- gcc/testsuite/gcc.dg/torture/pr126686.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/avoid-store-forwarding.cc b/gcc/avoid-store-forwarding.cc index 141f96c3d848..6cc3a3b4486d 100644 --- a/gcc/avoid-store-forwarding.cc +++ b/gcc/avoid-store-forwarding.cc @@ -565,10 +565,14 @@ store_forwarding_analyzer::avoid_store_forwarding (basic_block bb) /* The mem RTX if INSN is a store, NULL_RTX otherwise. */ rtx store_mem = MEM_P (SET_DEST (set)) ? SET_DEST (set) : NULL_RTX; - /* We cannot analyze memory RTXs that have unknown size. */ - if ((store_mem && (!MEM_SIZE_KNOWN_P (store_mem) + /* We cannot analyze memory RTXs that have unknown size. BLKmode + memory is rejected as well, as there is no mode for the forwarded + value, even when its size is known. */ + if ((store_mem && (GET_MODE (store_mem) == BLKmode + || !MEM_SIZE_KNOWN_P (store_mem) || !MEM_SIZE (store_mem).is_constant ())) - || (load_mem && (!MEM_SIZE_KNOWN_P (load_mem) + || (load_mem && (GET_MODE (load_mem) == BLKmode + || !MEM_SIZE_KNOWN_P (load_mem) || !MEM_SIZE (load_mem).is_constant ()))) { store_exprs.truncate (0); diff --git a/gcc/testsuite/gcc.dg/torture/pr126686.c b/gcc/testsuite/gcc.dg/torture/pr126686.c new file mode 100644 index 000000000000..b9e03ba5c473 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr126686.c @@ -0,0 +1,16 @@ +/* PR rtl-optimization/126686 */ +/* { dg-do compile } */ +/* { dg-additional-options "-favoid-store-forwarding" } */ + +int tmp; +short d_e; + +int +foo () +{ + long f = 0; + __builtin_memset ((char *) &f + sizeof f - 2, d_e, 2); + tmp = f; + + return f; +}