gcc/ChangeLog:

        PR target/91384
        * config/i386/i386.md: Add new peeophole2 for optimize *negsi_1
        followed by *cmpsi_ccno_1 with APX_F.

gcc/testsuite/ChangeLog:

        PR target/91384
        * gcc.target/i386/pr91384-1.c: New test.
---
 gcc/config/i386/i386.md                   | 11 +++++++++++
 gcc/testsuite/gcc.target/i386/pr91384-1.c | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr91384-1.c

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index b7a18d583da..6f87606b02b 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -14572,6 +14572,17 @@ (define_peephole2
                   (compare:CCZ (neg:SWI (match_dup 0)) (const_int 0)))
              (set (match_dup 0) (neg:SWI (match_dup 0)))])])
 
+;; Optimize *negsi_1 followed by *cmpsi_ccno_1 (PR target/91384) with APX_F
+(define_peephole2
+  [(parallel [(set (match_operand:SWI 0 "general_reg_operand")
+                  (neg:SWI (match_operand:SWI 1 "general_reg_operand")))
+             (clobber (reg:CC FLAGS_REG))])
+   (set (reg:CCZ FLAGS_REG) (compare:CCZ (match_dup 1) (const_int 0)))]
+  "TARGET_APX_NDD"
+  [(parallel [(set (reg:CCZ FLAGS_REG)
+                  (compare:CCZ (neg:SWI (match_dup 1)) (const_int 0)))
+             (set (match_dup 0) (neg:SWI (match_dup 1)))])])
+
 ;; Special expand pattern to handle integer mode abs
 
 (define_expand "abs<mode>2"
diff --git a/gcc/testsuite/gcc.target/i386/pr91384-1.c 
b/gcc/testsuite/gcc.target/i386/pr91384-1.c
new file mode 100644
index 00000000000..4f8823d6da2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr91384-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -mapxf" } */
+
+void foo (void);
+void bar (void);
+
+int
+test (int a)
+{
+  int r;
+
+  if (r = -a)
+    foo ();
+  else
+    bar ();
+
+  return r;
+}
+
+/* { dg-final { scan-assembler-not "testl" } } */
-- 
2.31.1

Reply via email to