If there is no cost information from the backend, the middle end
estimates the cost of if_then_else, which has three operands, as
3 instructions (i.e. 12 units). Define its cost as a single machine
cycle, ignoring the cost of actually taking the branch, to enable
more if-conversion optimizations.

gcc/ChangeLog:

        * config/loongarch/loongarch.cc (loongarch_rtx_costs):
        <IF_THEN_ELSE>: New case.

gcc/testsuite/ChangeLog:

        * gcc.target/loongarch/ifcvt-1.c: New test.
---
 gcc/config/loongarch/loongarch.cc            |  4 ++++
 gcc/testsuite/gcc.target/loongarch/ifcvt-1.c | 22 ++++++++++++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/ifcvt-1.c

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 1715b483c96..413de2e3906 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -4082,6 +4082,10 @@ loongarch_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
 
   switch (code)
     {
+    case IF_THEN_ELSE:
+      *total = COSTS_N_INSNS (1);
+      return true;
+
     case CONST_INT:
       if (TARGET_64BIT && outer_code == AND && UINTVAL (x) == 0xffffffff)
        {
diff --git a/gcc/testsuite/gcc.target/loongarch/ifcvt-1.c 
b/gcc/testsuite/gcc.target/loongarch/ifcvt-1.c
new file mode 100644
index 00000000000..64a151a92f4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/ifcvt-1.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler-times "maskeqz" 2 } }  */
+/* { dg-final { scan-assembler-times "masknez" 2 } }  */
+
+int
+remove_one_fast (int *move_ordering, const int num_moves, int mark)
+{
+  int i, best = -1000000;
+  int tmp = 0;
+
+  for (i = mark; i < num_moves; i++)
+    {
+      if (move_ordering[i] > best)
+        {
+          best = move_ordering[i];
+          tmp = i;
+        }
+    }
+
+  return tmp;
+}
-- 
2.20.1

Reply via email to