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>
"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)
--- /dev/null
+/* 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 ();
+}