Hi,
For constant C:
If '(c & 0xFFFFFFFF00008000ULL) == 0xFFFFFFFF00008000ULL' or say:
32(1) || 16(x) || 1(1) || 15(x), using "li; xoris" would be ok.
If '(c & 0xFFFFFFFF80008000ULL) == 0x80000000ULL' or say:
32(0) || 1(1) || 15(x) || 1(0) || 15(x), we could use "li; oris" to
build constant 'C'.
Here N(M) means N continuous bit M, x for M means it is ok for either
1 or 0; '||' means concatenation.
This patch update rs6000_emit_set_long_const to support those constants.
Bootstrap and regtest pass on ppc64{,le}.
Is this ok for trunk?
BR,
Jeff (Jiufu)
PR target/106708
gcc/ChangeLog:
* config/rs6000/rs6000.cc (rs6000_emit_set_long_const): Add building
constants through "li; x?oris".
gcc/testsuite/ChangeLog:
* gcc.target/powerpc/pr106708.c: Add test functions.
---
gcc/config/rs6000/rs6000.cc | 34 ++++++++++++++++++---
gcc/testsuite/gcc.target/powerpc/pr106708.c | 27 +++++++++++++++-
2 files changed, 56 insertions(+), 5 deletions(-)
@@ -10251,6 +10251,14 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)
if (ud1 != 0)
emit_move_insn (dest, gen_rtx_IOR (DImode, temp, GEN_INT (ud1)));
}
+ else if (ud4 == 0xffff && ud3 == 0xffff && (ud1 & 0x8000))
+ {
+ /* li; xoris */
+ temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
+ emit_move_insn (temp, GEN_INT (sext_hwi (ud1, 16)));
+ emit_move_insn (dest, gen_rtx_XOR (DImode, temp,
+ GEN_INT ((ud2 ^ 0xffff) << 16)));
+ }
else if (ud4 == 0xffff && ud3 == 0xffff && !(ud2 & 0x8000) && ud1 == 0)
{
/* lis; xoris */
@@ -10263,10 +10271,28 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)
temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
gcc_assert (ud2 & 0x8000);
- emit_move_insn (temp, GEN_INT (sext_hwi (ud2 << 16, 32)));
- if (ud1 != 0)
- emit_move_insn (temp, gen_rtx_IOR (DImode, temp, GEN_INT (ud1)));
- emit_move_insn (dest, gen_rtx_AND (DImode, temp, GEN_INT (0xffffffff)));
+
+ if (ud1 == 0)
+ {
+ /* lis; rldicl */
+ emit_move_insn (temp, GEN_INT (sext_hwi (ud2 << 16, 32)));
+ emit_move_insn (dest,
+ gen_rtx_AND (DImode, temp, GEN_INT (0xffffffff)));
+ }
+ else if (!(ud1 & 0x8000))
+ {
+ /* li; oris */
+ emit_move_insn (temp, GEN_INT (ud1));
+ emit_move_insn (dest,
+ gen_rtx_IOR (DImode, temp, GEN_INT (ud2 << 16)));
+ }
+ else
+ {
+ emit_move_insn (temp, GEN_INT (sext_hwi (ud2 << 16, 32)));
+ emit_move_insn (temp, gen_rtx_IOR (DImode, temp, GEN_INT (ud1)));
+ emit_move_insn (dest,
+ gen_rtx_AND (DImode, temp, GEN_INT (0xffffffff)));
+ }
}
else if (ud1 == ud3 && ud2 == ud4)
{
@@ -3,7 +3,8 @@
/* { dg-options "-O2 -mno-prefixed -save-temps" } */
/* { dg-require-effective-target has_arch_ppc64 } */
-long long arr[] = {0xffffffff65430000LL};
+long long arr[]
+ = {0xffffffff65430000LL, 0xffffffff7cdeab55LL, 0x98765432LL, 0xabcd0000LL};
void __attribute__ ((__noipa__)) lisxoris (long long *arg)
{
*arg = 0xffffffff65430000LL;
@@ -11,12 +12,36 @@ void __attribute__ ((__noipa__)) lisxoris (long long *arg)
/* { dg-final { scan-assembler-times {\mlis .*,0xe543\M} 1 } } */
/* { dg-final { scan-assembler-times {\mxoris .*0x8000\M} 1 } } */
+void __attribute__ ((__noipa__)) lixoris (long long *arg)
+{
+ *arg = 0xffffffff7cdeab55LL;
+}
+/* { dg-final { scan-assembler-times {\mli .*,-21675\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxoris .*0x8321\M} 1 } } */
+
+void __attribute__ ((__noipa__)) lioris (long long *arg)
+{
+ *arg = 0x98765432LL;
+}
+/* { dg-final { scan-assembler-times {\mli .*,21554\M} 1 } } */
+/* { dg-final { scan-assembler-times {\moris .*0x9876\M} 1 } } */
+
+void __attribute__ ((__noipa__)) lisrldicl (long long *arg)
+{
+ *arg = 0xabcd0000LL;
+}
+/* { dg-final { scan-assembler-times {\mlis .*,0xabcd\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mrldicl .*,0,32\M} 1 } } */
+
int
main ()
{
long long a[sizeof (arr) / sizeof (arr[0])];
lisxoris (a);
+ lixoris (a + 1);
+ lioris (a + 2);
+ lisrldicl (a + 3);
if (__builtin_memcmp (a, arr, sizeof (arr)) != 0)
__builtin_abort ();
return 0;