]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Add a new peeophole2 for PR91384 under APX_F
authorHu, Lin1 <lin1.hu@intel.com>
Tue, 8 Apr 2025 07:43:59 +0000 (15:43 +0800)
committerHu, Lin1 <lin1.hu@intel.com>
Fri, 11 Jul 2025 08:50:29 +0000 (16:50 +0800)
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
gcc/testsuite/gcc.target/i386/pr91384-1.c [new file with mode: 0644]

index 5825acabb94611e847b04366264c9a76ba3c92ef..83c438b129c9cdd75db8dd7b5a2d90e5bab2a0c0 100644 (file)
                   (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 (file)
index 0000000..4f8823d
--- /dev/null
@@ -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" } } */