https://gcc.gnu.org/g:1b08180f9624b4048ead31899da78eebdf745aea

commit r17-6585-g1b08180f9624b4048ead31899da78eebdf745aea
Author: Kyrylo Tkachov <[email protected]>
Date:   Mon Sep 21 13:55:46 2026 +0200

    AArch64: Use parallel costs for if-conversion
    
    The AArch64 speed profitability check adds serial instruction costs for
    conditional-select sequences inside loops.  It can reject short
    independent register computations that fit within the target's issue
    rate and cost limit, so a block that computes two values that do not
    depend on each other and selects between them keeps its branch.
    
    Export noce_parallel_seq_cost and use it in the AArch64 speed check.
    Sequences it cannot model keep the serial cost.  Keep the target cost
    limit, the instruction-shape checks and the in-loop size policy.
    
    Add a loop test where two independent outputs now convert, guard tests
    where a long dependent chain and low explicit cost limits keep the
    branch and where -Os and -Oz still convert.
    
    Over the C torture and aarch64 target tests compiled at -O2, -O3 and
    -Os (13497 outputs), the assembly changes for 29 outputs, all at -O2 or
    -O3: 13 lose instructions, 11 gain them and 5 keep the same count.
    Conditional selects in these outputs go from 49 to 291 and conditional
    branches from 385 to 361, for 145 more instructions overall.
    
    Snappy (rev 26aa88cb) was built at -O3 -mcpu=olympus and run on an
    NVIDIA Vera system, six rounds in alternating order on one pinned core.
    With this patch and the two before it, compression (ZFlat) throughput
    rises by 4.7% geomean (best input +13.8%, worst -0.2%) and
    decompression (UFlat) by 0.05%.  The first patch alone gives +0.2% and
    the second does not change the Snappy code, so the gain comes from this
    patch.  It raises the number of conditional selects in the Snappy library
    from 70 to 78.
    
    gcc/ChangeLog:
    
            * ifcvt.cc (noce_parallel_seq_cost): Remove static.
            * ifcvt.h (noce_parallel_seq_cost): Declare.
            * config/aarch64/aarch64.cc
            (aarch64_noce_conversion_profitable_p): Use noce_parallel_seq_cost.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/noce-parallel-cost-1.c: New test.
            * gcc.target/aarch64/noce-parallel-cost-2.c: Likewise.
            * gcc.target/aarch64/noce-parallel-cost-3.c: Likewise.
            * gcc.target/aarch64/noce-parallel-cost-4.c: Likewise.
            * gcc.target/aarch64/noce-parallel-cost-5.c: Likewise.
    
    Signed-off-by: Kyrylo Tkachov <[email protected]>

Diff:
---
 gcc/config/aarch64/aarch64.cc                      |  2 +-
 gcc/ifcvt.cc                                       |  2 +-
 gcc/ifcvt.h                                        |  2 ++
 .../gcc.target/aarch64/noce-parallel-cost-1.c      | 27 +++++++++++++++++
 .../gcc.target/aarch64/noce-parallel-cost-2.c      | 34 ++++++++++++++++++++++
 .../gcc.target/aarch64/noce-parallel-cost-3.c      |  6 ++++
 .../gcc.target/aarch64/noce-parallel-cost-4.c      |  6 ++++
 .../gcc.target/aarch64/noce-parallel-cost-5.c      |  6 ++++
 8 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index d5629dc9c7ab..016af1486592 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -2466,7 +2466,7 @@ aarch64_noce_conversion_profitable_p (rtx_insn *seq,
           most cases.  */
   if (if_info->speed_p)
     {
-      unsigned cost = seq_cost (seq, true);
+      unsigned cost = noce_parallel_seq_cost (seq, true);
       return cost <= if_info->max_seq_cost;
     }
 
diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
index 7f0aab04ad03..377aa9430c0d 100644
--- a/gcc/ifcvt.cc
+++ b/gcc/ifcvt.cc
@@ -891,7 +891,7 @@ noce_dependency_level (noce_ready_map &ready,
      0.2 < ratio <= 0.4   0.91 percent
      0.0 < ratio <= 0.2   0.00 percent.  */
 
-static unsigned int
+unsigned int
 noce_parallel_seq_cost (rtx_insn *seq, bool speed_p)
 {
   unsigned int serial_cost = seq_cost (seq, speed_p);
diff --git a/gcc/ifcvt.h b/gcc/ifcvt.h
index 8347e0e8bc84..1ffd5bbb7970 100644
--- a/gcc/ifcvt.h
+++ b/gcc/ifcvt.h
@@ -138,4 +138,6 @@ struct noce_if_info
   const char *transform_name;
 };
 
+extern unsigned int noce_parallel_seq_cost (rtx_insn *, bool);
+
 #endif /* GCC_IFCVT_H */
diff --git a/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-1.c 
b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-1.c
new file mode 100644
index 000000000000..74f6677fa29e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-1.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=olympus -fdump-rtl-ce1" } */
+
+void
+select_values (unsigned int n, const volatile unsigned long input[][3],
+              volatile unsigned long output[][2])
+{
+  for (unsigned int i = 0; i < n; ++i)
+    {
+      unsigned long c = input[i][0], x = input[i][1], y = input[i][2];
+      unsigned long a, b;
+      if (c > 7)
+       {
+         a = x * 3 + y;
+         b = 2;
+       }
+      else
+       {
+         a = x + 9;
+         b = 3;
+       }
+      output[i][0] = a;
+      output[i][1] = b;
+    }
+}
+
+/* { dg-final { scan-rtl-dump-times "if-conversion succeeded through 
noce_convert_multiple_sets" 1 "ce1" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-2.c 
b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-2.c
new file mode 100644
index 000000000000..be414b109d7c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-2.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=olympus -fdump-rtl-ce1" } */
+
+void
+select_values (unsigned int n, const volatile unsigned long input[][3],
+              volatile unsigned long output[][2])
+{
+  for (unsigned int i = 0; i < n; ++i)
+    {
+      unsigned long c = input[i][0], x = input[i][1], y = input[i][2];
+      unsigned long a, b;
+      if (c > 7)
+       {
+         a = x + 9;
+         a ^= y;
+         a >>= 2;
+         a += 5;
+         a ^= y;
+         a >>= 3;
+         a += 13;
+         a ^= y;
+         b = 2;
+       }
+      else
+       {
+         a = x + 9;
+         b = 3;
+       }
+      output[i][0] = a;
+      output[i][1] = b;
+    }
+}
+
+/* { dg-final { scan-rtl-dump-not "if-conversion succeeded" "ce1" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-3.c 
b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-3.c
new file mode 100644
index 000000000000..d861b108e75e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-3.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mcpu=olympus 
--param=max-rtl-if-conversion-unpredictable-cost=1 
--param=max-rtl-if-conversion-predictable-cost=1 -fdump-rtl-ce1" } */
+
+#include "noce-parallel-cost-1.c"
+
+/* { dg-final { scan-rtl-dump-not "if-conversion succeeded" "ce1" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-4.c 
b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-4.c
new file mode 100644
index 000000000000..fac1f2eee3a5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-4.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -mcpu=olympus -fdump-rtl-ce1" } */
+
+#include "noce-parallel-cost-1.c"
+
+/* { dg-final { scan-rtl-dump-times "if-conversion succeeded through 
noce_convert_multiple_sets" 1 "ce1" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-5.c 
b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-5.c
new file mode 100644
index 000000000000..d2213a522f9a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/noce-parallel-cost-5.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Oz -mcpu=olympus -fdump-rtl-ce1" } */
+
+#include "noce-parallel-cost-1.c"
+
+/* { dg-final { scan-rtl-dump-times "if-conversion succeeded through 
noce_convert_multiple_sets" 1 "ce1" } } */

Reply via email to