re PR target/82339 (Inefficient movabs instruction)
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Sep 2017 07:20:09 +0000 (09:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 29 Sep 2017 07:20:09 +0000 (09:20 +0200)
PR target/82339
* config/i386/i386.md (*movdi_internal peephole2): New -Os peephole
for movabsq $(i32 << shift), r64.

From-SVN: r253279

gcc/ChangeLog
gcc/config/i386/i386.md

index 2802cdf75114a587a380e21b3bc394ee83b27a39..c702d48d047e12e5b4b29cf0b83231d835cf908b 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR target/82339
+       * config/i386/i386.md (*movdi_internal peephole2): New -Os peephole
+       for movabsq $(i32 << shift), r64.
+
 2017-09-28  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.c (ix86_print_operand_address_as): Do not check
index b9a392852d4e25d5718a6520bbf7e6a78d609eab..8786ee4036af5e1e70d459df04be3b04577f2dd7 100644 (file)
                  gen_lowpart (SImode, operands[1]));
 })
 
+;; movabsq $0x0012345678000000, %rax is longer
+;; than movl $0x12345678, %eax; shlq $24, %rax.
+(define_peephole2
+  [(set (match_operand:DI 0 "register_operand")
+       (match_operand:DI 1 "const_int_operand"))]
+  "TARGET_64BIT
+   && optimize_insn_for_size_p ()
+   && LEGACY_INT_REG_P (operands[0])
+   && !x86_64_immediate_operand (operands[1], DImode)
+   && !x86_64_zext_immediate_operand (operands[1], DImode)
+   && !((UINTVAL (operands[1]) >> ctz_hwi (UINTVAL (operands[1])))
+        & ~(HOST_WIDE_INT) 0xffffffff)
+   && peep2_regno_dead_p (0, FLAGS_REG)"
+  [(set (match_dup 0) (match_dup 1))
+   (parallel [(set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))
+             (clobber (reg:CC FLAGS_REG))])]
+{
+  int shift = ctz_hwi (UINTVAL (operands[1]));
+  operands[1] = gen_int_mode (UINTVAL (operands[1]) >> shift, DImode);
+  operands[2] = gen_int_mode (shift, QImode);
+})
+
 (define_insn "*movsi_internal"
   [(set (match_operand:SI 0 "nonimmediate_operand"
     "=r,m ,*y,*y,?*y,?m,?r ,?*Ym,*v,*v,*v,m ,?r ,?*Yi,*k,*k ,*rm")