Hi, Jiufu
* config/rs6000/rs6000.cc (can_be_rotated_to_possitive_li): New
function.
(can_be_rotated_to_negative_li): New function.
(can_be_built_by_li_and_rotldi): New function.
(rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi.
In English the word "positive" contains one "s", not two. Please
correct throughout the patches.
Also a style issue, comments before a function should be followed by a
blank line.
> +/* Check if C can be rotated to a possitive value which 'li' instruction
positive
> + is able to load. If so, set *ROT to the number by which C is rotated,
> + and return true. Return false otherwise. */
Add a blank line here
> +static bool
> +can_be_rotated_to_possitive_li (HOST_WIDE_INT c, int *rot)
positive
> +{
> + /* 49 leading zeros and 15 lowbits on the possitive value
low bits, positive
> + generated by 'li' instruction. */
> + return can_be_rotated_to_lowbits (c, 15, rot);
> +}
> +/* Check if value C can be built by 2 instructions: one is 'li', another is
> + rotldi.
> +
> + If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK
> + is set to -1, and return true. Return false otherwise. */
> +static bool
> +can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift,
> + HOST_WIDE_INT *mask)
> +{
> + int n;
> + if (can_be_rotated_to_possitive_li (c, &n)
> + || can_be_rotated_to_negative_li (c, &n))
> + {
> + *mask = HOST_WIDE_INT_M1;
> + *shift = HOST_BITS_PER_WIDE_INT - n;
> + return true;
> + }
> +
> + return false;
> +}
> +
> /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode.
> Output insns to set DEST equal to the constant C as a series of
> lis, ori and shl instructions. */
> @@ -10246,15 +10285,14 @@ static void> rs6000_emit_set_long_const (rtx dest,
> HOST_WIDE_INT c)> {> rtx temp;> + int shift;> + HOST_WIDE_INT mask;>
> HOST_WIDE_INT ud1, ud2, ud3, ud4;> > ud1 = c & 0xffff;> - c = c >> 16;>
> - ud2 = c & 0xffff;> - c = c >> 16;> - ud3 = c & 0xffff;> - c = c >> 16;>
> - ud4 = c & 0xffff;> + ud2 = (c >> 16) & 0xffff;> + ud3 = (c >> 32) &
> 0xffff;> + ud4 = (c >> 48) & 0xffff;> > if ((ud4 == 0xffff && ud3 ==
> 0xffff && ud2 == 0xffff && (ud1 & 0x8000))> || (ud4 == 0 && ud3 == 0
> && ud2 == 0 && ! (ud1 & 0x8000)))> @@ -10278,6 +10316,19 @@
> rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)> emit_move_insn
> (dest, gen_rtx_XOR (DImode, temp,>
> GEN_INT ((ud2 ^ 0xffff) << 16)));> }> + else if
> (can_be_built_by_li_and_rotldi (c, &shift, &mask))> + {> + temp =
> !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);> + unsigned
> HOST_WIDE_INT imm = (c | ~mask);> + imm = (imm >> shift) | (imm <<
> (HOST_BITS_PER_WIDE_INT - shift));> +> + emit_move_insn (temp, GEN_INT
> (imm));> + if (shift != 0)> + temp = gen_rtx_ROTATE (DImode, temp,
> GEN_INT (shift));> + if (mask != HOST_WIDE_INT_M1)
How is mask != HOST_WIDE_INT_M1? The call to
can_by_built_by_li_and_rotldi() set it
to that value and it is not modified in the interim statements.
> + temp = gen_rtx_AND (DImode, temp, GEN_INT (mask));> +
> emit_move_insn (dest, temp);> + }> else if (ud3 == 0 && ud4 == 0)>
> {> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
Thanks, David