]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add some preference for floating point rtl ifcvt when sse4.1 is not available
authorliuhongt <hongtao.liu@intel.com>
Fri, 31 May 2024 06:38:07 +0000 (14:38 +0800)
committerliuhongt <hongtao.liu@intel.com>
Mon, 3 Jun 2024 07:18:10 +0000 (15:18 +0800)
W/o TARGET_SSE4_1, it takes 3 instructions (pand, pandn and por) for
movdfcc/movsfcc, and could possibly fail cost comparison. Increase
branch cost could hurt performance for other modes, so specially add
some preference for floating point ifcvt.

gcc/ChangeLog:

PR target/115299
* config/i386/i386.cc (ix86_noce_conversion_profitable_p): Add
some preference for floating point ifcvt when SSE4.1 is not
available.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr115299.c: New test.
* gcc.target/i386/pr86722.c: Adjust testcase.

gcc/config/i386/i386.cc
gcc/testsuite/gcc.target/i386/pr115299.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr86722.c

index 1a0206ab57368cea452286f76488e0cda0e4c155..271da127a89c94419e312b03ed990e4b69b38ce6 100644 (file)
@@ -24879,6 +24879,23 @@ ix86_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info)
            return false;
        }
     }
+
+  /* W/o TARGET_SSE4_1, it takes 3 instructions (pand, pandn and por)
+     for movdfcc/movsfcc, and could possibly fail cost comparison.
+     Increase branch cost will hurt performance for other modes, so
+     specially add some preference for floating point ifcvt.  */
+  if (!TARGET_SSE4_1 && if_info->x
+      && GET_MODE_CLASS (GET_MODE (if_info->x)) == MODE_FLOAT
+      && if_info->speed_p)
+    {
+      unsigned cost = seq_cost (seq, true);
+
+      if (cost <= if_info->original_cost)
+       return true;
+
+      return cost <= (if_info->max_seq_cost + COSTS_N_INSNS (2));
+    }
+
   return default_noce_conversion_profitable_p (seq, if_info);
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/pr115299.c b/gcc/testsuite/gcc.target/i386/pr115299.c
new file mode 100644 (file)
index 0000000..53c5899
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -mno-sse4.1 -msse2" } */
+
+void f(double*d,double*e){
+  for(;d<e;++d)
+    *d=(*d<.5)?.7:0;
+}
+
+/* { dg-final { scan-assembler {(?n)(?:cmpnltsd|cmpltsd)} } } */
+/* { dg-final { scan-assembler {(?n)(?:andnpd|andpd)} } } */
index 4de2ca1a6c01e293a60dec9e068f87bfeed4ebac..e266a1e56c2ff12f7e7d7912a562ff2e6cf8f8b5 100644 (file)
@@ -6,5 +6,5 @@ void f(double*d,double*e){
     *d=(*d<.5)?.7:0;
 }
 
-/* { dg-final { scan-assembler-not "andnpd" } } */
+/* { dg-final { scan-assembler-times {(?n)(?:andnpd|andpd)} 1 } } */
 /* { dg-final { scan-assembler-not "orpd" } } */