> -----Original Message----- > From: gcc-patches-ow...@gcc.gnu.org [mailto:gcc-patches- > ow...@gcc.gnu.org] On Behalf Of Eric Botcazou > Sent: Monday, November 24, 2014 5:41 PM > To: Zhenqiang Chen > Cc: gcc-patches@gcc.gnu.org > Subject: Re: [PATCH, combine] Try REG_EQUAL for nonzero_bits > > > Thanks for the comments. I will compare the two nonzero_bits from src > > and REG_EQUAL. Then select the smaller one. > > They are masks so you can simply AND them before ORing the result. > > > Do you know why it use " SET_SRC (set)" other than "src" for > > num_sign_bit_copies? > > > > If it is "src", I should do the same for num_sign_bit_copies with > > REG_EQUAL info. > > Probably historical reasons, let's not try to change that now. You can apply > the same treatment to num_sign_bit_copies (you will need a comparison > here) while preserving the "src" vs "SET_SRC (set)" discrepancy.
Thanks for the comments. Patch is updated. diff --git a/gcc/combine.c b/gcc/combine.c index 1808f97..2e865d7 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -1603,6 +1603,28 @@ setup_incoming_promotions (rtx_insn *first) } } +/* Update RSP from INSN's REG_EQUAL note and SRC. */ + +static void +update_rsp_from_reg_equal (reg_stat_type *rsp, rtx_insn *insn, rtx src, rtx x) +{ + rtx reg_equal = insn ? find_reg_equal_equiv_note (insn) : NULL_RTX; + unsigned HOST_WIDE_INT bits = nonzero_bits (src, nonzero_bits_mode); + + if (reg_equal) + { + unsigned int num = num_sign_bit_copies (XEXP (reg_equal, 0), + GET_MODE (x)); + bits &= nonzero_bits (XEXP (reg_equal, 0), nonzero_bits_mode); + rsp->nonzero_bits |= bits; + + if (rsp->sign_bit_copies > num) + rsp->sign_bit_copies = num; + } + else + rsp->nonzero_bits |= bits; +} + /* Called via note_stores. If X is a pseudo that is narrower than HOST_BITS_PER_WIDE_INT and is being set, record what bits are known zero. @@ -1698,13 +1720,14 @@ set_nonzero_bits_and_sign_copies (rtx x, const_rtx set, void *data) src = GEN_INT (INTVAL (src) | ~GET_MODE_MASK (GET_MODE (x))); #endif - /* Don't call nonzero_bits if it cannot change anything. */ - if (rsp->nonzero_bits != ~(unsigned HOST_WIDE_INT) 0) - rsp->nonzero_bits |= nonzero_bits (src, nonzero_bits_mode); num = num_sign_bit_copies (SET_SRC (set), GET_MODE (x)); if (rsp->sign_bit_copies == 0 || rsp->sign_bit_copies > num) rsp->sign_bit_copies = num; + + /* Don't call nonzero_bits if it cannot change anything. */ + if (rsp->nonzero_bits != ~(unsigned HOST_WIDE_INT) 0) + update_rsp_from_reg_equal (rsp, insn, src, x); } else {