commit ef26c151c14a87177d46fd3d725e7f82e040e89f
Author: Roger Sayle <[email protected]>
Date: Thu Dec 23 12:33:07 2021 +0000
x86: PR target/103773: Fix wrong-code with -Oz from pop to memory.
transformed "mov $0,mem" to the shorter and "$0,mem" for -Oz. But
(define_insn "*mov<mode>_and"
[(set (match_operand:SWI248 0 "memory_operand" "=m")
(match_operand:SWI248 1 "const0_operand"))
(clobber (reg:CC FLAGS_REG))]
"reload_completed"
"and{<imodesuffix>}\t{%1, %0|%0, %1}"
[(set_attr "type" "alu1")
(set_attr "mode" "<MODE>")
(set_attr "length_immediate" "1")])
isn't guarded for -Oz. As a result, "and $0,mem" is generated without
-Oz. Enable *mov<mode>_and only for -Oz.
gcc/
PR target/120427
* config/i386/i386.md (*mov<mode>_and): Enable only for -Oz.
gcc/testsuite/
PR target/120427
* gcc.target/i386/pr120427.c: New test.
OK for master?
--
H.J.
From ff829a2a7e13e1f6b1333f169b2f6adae6a5c192 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Sun, 25 May 2025 07:40:29 +0800
Subject: [PATCH] x86: Enable *mov<mode>_and only for -Oz
commit ef26c151c14a87177d46fd3d725e7f82e040e89f
Author: Roger Sayle <[email protected]>
Date: Thu Dec 23 12:33:07 2021 +0000
x86: PR target/103773: Fix wrong-code with -Oz from pop to memory.
transformed "mov $0,mem" to the shorter and "$0,mem" for -Oz. But
(define_insn "*mov<mode>_and"
[(set (match_operand:SWI248 0 "memory_operand" "=m")
(match_operand:SWI248 1 "const0_operand"))
(clobber (reg:CC FLAGS_REG))]
"reload_completed"
"and{<imodesuffix>}\t{%1, %0|%0, %1}"
[(set_attr "type" "alu1")
(set_attr "mode" "<MODE>")
(set_attr "length_immediate" "1")])
isn't guarded for -Oz. As a result, "and $0,mem" is generated without
-Oz. Enable *mov<mode>_and only for -Oz.
gcc/
PR target/120427
* config/i386/i386.md (*mov<mode>_and): Enable only for -Oz.
gcc/testsuite/
PR target/120427
* gcc.target/i386/pr120427.c: New test.
Signed-off-by: H.J. Lu <[email protected]>
---
gcc/config/i386/i386.md | 3 ++-
gcc/testsuite/gcc.target/i386/pr120427.c | 28 ++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr120427.c
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index b7a18d583da..6dcdff46642 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -2442,7 +2442,8 @@ (define_insn "*mov<mode>_and"
[(set (match_operand:SWI248 0 "memory_operand" "=m")
(match_operand:SWI248 1 "const0_operand"))
(clobber (reg:CC FLAGS_REG))]
- "reload_completed"
+ "reload_completed
+ && optimize_insn_for_size_p () && optimize_size > 1"
"and{<imodesuffix>}\t{%1, %0|%0, %1}"
[(set_attr "type" "alu1")
(set_attr "mode" "<MODE>")
diff --git a/gcc/testsuite/gcc.target/i386/pr120427.c b/gcc/testsuite/gcc.target/i386/pr120427.c
new file mode 100644
index 00000000000..2c2888b189d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr120427.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mtune=sapphirerapids" } */
+/* { dg-final { scan-assembler-not "and\[lq\]?\[\\t \]*\\\$0, \[0-9\]*\\(" } } */
+
+struct __pthread_mutex_s
+{
+ int __lock;
+ unsigned int __count;
+ int __owner;
+ unsigned int __nusers;
+ int __kind;
+ short __spins;
+ short __elision;
+ void *p[2];
+};
+typedef union
+{
+ struct __pthread_mutex_s __data;
+ char __size[40];
+ long int __align;
+} pthread_mutex_t;
+typedef struct { pthread_mutex_t mutex; } __rtld_lock_recursive_t;
+void
+foo (__rtld_lock_recursive_t *lock, int i)
+{
+ lock[i] = (__rtld_lock_recursive_t) {{ { 0, 0, 0, 0, 1,
+ 0, 0, { ((void *)0) , ((void *)0) } } }};
+}
--
2.49.0