diff mbox series

[i386] : PR 82618, Inefficient double-word subtraction on x86_64

Message ID CAFULd4ayoPZ84PoPKRZhuUvPbrRmNm2XC7omAbVRDEay6KB=bQ@mail.gmail.com
State New
Headers show
Series [i386] : PR 82618, Inefficient double-word subtraction on x86_64 | expand

Commit Message

Uros Bizjak Oct. 19, 2017, 5:41 p.m. UTC
Attached patch converts SUB with its output unused to CMP. This can
happen in double-word subtraction when lowpart of the result is unused
(but highpart subtraction still needs to borrow carry flag).

2017-10-19  Uros Bizjak  <ubizjak@gmail.com>

    PR target/82618
    * config/i386/i386.md (sub to cmp): New peephole2 pattern.

testsuite/ChangeLog:

2017-10-18  Uros Bizjak  <ubizjak@gmail.com>
        Jakub Jelinek  <jakub@redhat.com>

    PR target/82618
    * gcc.target/i386/pr82618.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

Uros.
diff mbox series

Patch

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 253899)
+++ config/i386/i386.md	(working copy)
@@ -6766,6 +6766,17 @@ 
   [(set_attr "type" "alu")
    (set_attr "mode" "<MODE>")])
 
+(define_peephole2
+  [(parallel
+     [(set (reg:CC FLAGS_REG)
+	   (compare:CC (match_operand:SWI 0 "general_reg_operand")
+		       (match_operand:SWI 1 "general_gr_operand")))
+      (set (match_dup 0)
+	   (minus:SWI (match_dup 0) (match_dup 1)))])]
+  "find_regno_note (peep2_next_insn (0), REG_UNUSED, REGNO (operands[0])) != 0"
+  [(set (reg:CC FLAGS_REG)
+	(compare:CC (match_dup 0) (match_dup 1)))])
+
 (define_insn "*subsi_3_zext"
   [(set (reg FLAGS_REG)
 	(compare (match_operand:SI 1 "register_operand" "0")
Index: testsuite/gcc.target/i386/pr82618.c
===================================================================
--- testsuite/gcc.target/i386/pr82618.c	(nonexistent)
+++ testsuite/gcc.target/i386/pr82618.c	(working copy)
@@ -0,0 +1,18 @@ 
+/* PR target/82618 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#ifdef __SIZEOF_INT128__
+typedef unsigned __int128 U;
+typedef unsigned long long H;
+#else
+typedef unsigned long long U;
+typedef unsigned int H;
+#endif
+
+H f0 (U x, U y)
+{
+  return (x - y) >> (__CHAR_BIT__ * sizeof (H));
+}
+
+/* { dg-final { scan-assembler {\mcmp} } } */