]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Avoid splitting 16/32-bit volatile mem test into 8-bit test [PR125180]
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 May 2026 08:44:25 +0000 (10:44 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 May 2026 08:44:25 +0000 (10:44 +0200)
With -ffuse-ops-with-volatile-access which is now even on by default
thie splitter can split a 16 or 32-bit volatile memory test into
an 8-bit volatile memory test, which is undesirable and e.g. when
it refers to some memory mapped hw registers it could misbehave.

2026-05-05  Jakub Jelinek  <jakub@redhat.com>

PR target/125180
* config/i386/i386.md (HI/SI test -> QI test splitter): Punt if
operands[2] is a volatile MEM.

* gcc.target/i386/pr125180.c: New test.

Reviewed-by: Uros Bizjak <ubizjak@gmail.com>
gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr125180.c [new file with mode: 0644]

index b0990294b9a81acd8b2d0ad94133d4faae472f4d..b4e397bc925b450a921a7b49abb85a6a4cb8e114 100644 (file)
    "reload_completed
     && GET_MODE (operands[2]) != QImode
     && (!REG_P (operands[2]) || ANY_QI_REG_P (operands[2]))
+    && !(MEM_P (operands[2]) && MEM_VOLATILE_P (operands[2]))
     && ((ix86_match_ccmode (insn, CCZmode)
         && !(INTVAL (operands[3]) & ~255))
        || (ix86_match_ccmode (insn, CCNOmode)
diff --git a/gcc/testsuite/gcc.target/i386/pr125180.c b/gcc/testsuite/gcc.target/i386/pr125180.c
new file mode 100644 (file)
index 0000000..fa5d5fc
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR target/125180 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -masm=att" } */
+/* { dg-final { scan-assembler "\ttestl\t\\\$1, \\\(" } } */
+/* { dg-final { scan-assembler-not "\ttestb\t\\\$1, \\\(" } } */
+
+void foo (void);
+
+void
+bar (unsigned volatile *x)
+{
+  if (*x & 1)
+    foo ();
+}