From 97d87f7502351f80784f77dbeb4119def98c133d Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 27 Apr 2015 11:02:34 +0000 Subject: [PATCH] combine.c (sign_extend_short_imm): New. 2015-04-27 Thomas Preud'homme * combine.c (sign_extend_short_imm): New. (set_nonzero_bits_and_sign_copies): Use above new function for sign extension of src short immediate. (reg_nonzero_bits_for_combine): Likewise for tem. From-SVN: r222457 --- gcc/ChangeLog | 7 +++++++ gcc/combine.c | 53 ++++++++++++++++++++++++--------------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3688fb459b1..ceb6dc361bd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2015-04-27 Thomas Preud'homme + + * combine.c (sign_extend_short_imm): New. + (set_nonzero_bits_and_sign_copies): Use above new function for sign + extension of src short immediate. + (reg_nonzero_bits_for_combine): Likewise for tem. + 2015-04-27 Eric Botcazou * stor-layout.c (self_referential_component_ref_p): New predicate. diff --git a/gcc/combine.c b/gcc/combine.c index 6cd55dd4432..2b1ba24a7c3 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -1646,6 +1646,28 @@ setup_incoming_promotions (rtx_insn *first) } } +#ifdef SHORT_IMMEDIATES_SIGN_EXTEND +/* If MODE has a precision lower than PREC and SRC is a non-negative constant + that would appear negative in MODE, sign-extend SRC for use in nonzero_bits + because some machines (maybe most) will actually do the sign-extension and + this is the conservative approach. + + ??? For 2.5, try to tighten up the MD files in this regard instead of this + kludge. */ + +static rtx +sign_extend_short_imm (rtx src, machine_mode mode, unsigned int prec) +{ + if (GET_MODE_PRECISION (mode) < prec + && CONST_INT_P (src) + && INTVAL (src) > 0 + && val_signbit_known_set_p (mode, INTVAL (src))) + src = GEN_INT (INTVAL (src) | ~GET_MODE_MASK (mode)); + + return src; +} +#endif + /* 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. @@ -1725,20 +1747,7 @@ set_nonzero_bits_and_sign_copies (rtx x, const_rtx set, void *data) rtx src = SET_SRC (set); #ifdef SHORT_IMMEDIATES_SIGN_EXTEND - /* If X is narrower than a word and SRC is a non-negative - constant that would appear negative in the mode of X, - sign-extend it for use in reg_stat[].nonzero_bits because some - machines (maybe most) will actually do the sign-extension - and this is the conservative approach. - - ??? For 2.5, try to tighten up the MD files in this regard - instead of this kludge. */ - - if (GET_MODE_PRECISION (GET_MODE (x)) < BITS_PER_WORD - && CONST_INT_P (src) - && INTVAL (src) > 0 - && val_signbit_known_set_p (GET_MODE (x), INTVAL (src))) - src = GEN_INT (INTVAL (src) | ~GET_MODE_MASK (GET_MODE (x))); + src = sign_extend_short_imm (src, GET_MODE (x), BITS_PER_WORD); #endif /* Don't call nonzero_bits if it cannot change anything. */ @@ -9788,20 +9797,8 @@ reg_nonzero_bits_for_combine (const_rtx x, machine_mode mode, if (tem) { #ifdef SHORT_IMMEDIATES_SIGN_EXTEND - /* If X is narrower than MODE and TEM is a non-negative - constant that would appear negative in the mode of X, - sign-extend it for use in reg_nonzero_bits because some - machines (maybe most) will actually do the sign-extension - and this is the conservative approach. - - ??? For 2.5, try to tighten up the MD files in this regard - instead of this kludge. */ - - if (GET_MODE_PRECISION (GET_MODE (x)) < GET_MODE_PRECISION (mode) - && CONST_INT_P (tem) - && INTVAL (tem) > 0 - && val_signbit_known_set_p (GET_MODE (x), INTVAL (tem))) - tem = GEN_INT (INTVAL (tem) | ~GET_MODE_MASK (GET_MODE (x))); + tem = sign_extend_short_imm (tem, GET_MODE (x), + GET_MODE_PRECISION (mode)); #endif return tem; } -- 2.30.2