Hello!

Attached patch enables post-reload compare optimization pass for x86 targets.

As shown in following test, patch removes redundant compare:

--cut here--
int test(int a, int b)
{
  int lt = a < b;
  int eq = a == b;
  if (lt)
    return 1;
  return eq;
}
--cut here--

gcc -O2 on x86_64, a cmove target:

test:
        xorl    %edx, %edx
        cmpl    %esi, %edi
        movl    $1, %eax
        sete    %dl
        cmovge  %edx, %eax
        ret

gcc-O2 -fno-compare-elim:

test:
        xorl    %edx, %edx
        cmpl    %esi, %edi
        movl    $1, %eax
        sete    %dl
        cmpl    %esi, %edi
        cmovge  %edx, %eax
        ret

2012-02-05  Uros Bizjak  <ubiz...@gmail.com>

        PR target/28685
        * config/i386/i386.c (TARGET_FLAGS_REGNUM): New.

testsuite/ChangeLog:

        PR target/28685
        * gcc.target/i386/pr28685.c: New test.

The patch was tested on x86_64-pc-linux-gnu {,-m32}. The patch will be
committed to 4.8 once stage 1 opens.

Uros.
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c  (revision 183904)
+++ config/i386/i386.c  (working copy)
@@ -38685,6 +38685,9 @@
 #undef TARGET_EXPAND_TO_RTL_HOOK
 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
 
+#undef TARGET_FLAGS_REGNUM
+#define TARGET_FLAGS_REGNUM FLAGS_REG
+
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
 
Index: testsuite/gcc.target/i386/pr28685.c
===================================================================
--- testsuite/gcc.target/i386/pr28685.c (revision 0)
+++ testsuite/gcc.target/i386/pr28685.c (revision 0)
@@ -0,0 +1,12 @@
+/* { dg-options "-O2" } */
+
+int test(int a, int b)
+{
+  int lt = a < b;
+  int eq = a == b;
+  if (lt)
+    return 1;
+  return eq;
+}
+
+/* { dg-final { scan-assembler-times "cmp" 1 } } */

Reply via email to