From 2891beff1aa8e627ba27b35d28d6a8e6198a0625 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 29 Sep 2017 09:20:09 +0200 Subject: [PATCH] re PR target/82339 (Inefficient movabs instruction) PR target/82339 * config/i386/i386.md (*movdi_internal peephole2): New -Os peephole for movabsq $(i32 << shift), r64. From-SVN: r253279 --- gcc/ChangeLog | 6 ++++++ gcc/config/i386/i386.md | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2802cdf7511..c702d48d047 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-09-29 Jakub Jelinek + + PR target/82339 + * config/i386/i386.md (*movdi_internal peephole2): New -Os peephole + for movabsq $(i32 << shift), r64. + 2017-09-28 Uros Bizjak * config/i386/i386.c (ix86_print_operand_address_as): Do not check diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index b9a392852d4..8786ee4036a 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -2379,6 +2379,28 @@ 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") -- 2.30.2