]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rs6000: use lis;xoris to build constant
authorJiufu Guo <guojiufu@linux.ibm.com>
Sat, 10 Dec 2022 13:18:51 +0000 (21:18 +0800)
committerJiufu Guo <guojiufu@linux.ibm.com>
Wed, 17 May 2023 02:13:18 +0000 (10:13 +0800)
For constant C:
If '(c & 0xFFFFFFFF0000FFFFULL) == 0xFFFFFFFF00000000' or say:
32(1) || 1(0) || 15(x) || 16(0), we could use "lis; xoris" to build.

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.

Compare with previous version:
https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608292.html
This patch updates test function names only.

Bootstrap and regtest pass on ppc64{,le}.

PR target/106708

gcc/ChangeLog:

* config/rs6000/rs6000.cc (rs6000_emit_set_long_const): Support building
constants through "lis; xoris".

gcc/testsuite/ChangeLog:

* gcc.target/powerpc/pr106708.c: Add test function.

gcc/config/rs6000/rs6000.cc
gcc/testsuite/gcc.target/powerpc/pr106708.c

index 3f129ea37d2f6055b76fefde4e792ac47465287f..275fb813c8066a6c1b37dc43bcf6a861eee9ecb0 100644 (file)
@@ -10289,6 +10289,13 @@ 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 && !(ud2 & 0x8000) && ud1 == 0)
+    {
+      /* lis; xoris */
+      temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
+      emit_move_insn (temp, GEN_INT (sext_hwi ((ud2 | 0x8000) << 16, 32)));
+      emit_move_insn (dest, gen_rtx_XOR (DImode, temp, GEN_INT (0x80000000)));
+    }
   else if (ud4 == 0xffff && ud3 == 0xffff && (ud1 & 0x8000))
     {
       /* li; xoris */
index ddb9160d4b8e84e8a94bece3054d10a680432e45..b941b65e80de1a69a9109d9230610cb581428ed4 100644 (file)
@@ -4,7 +4,7 @@
 /* { dg-require-effective-target has_arch_ppc64 } */
 
 long long arr[]
-  = {0xffffffff7cdeab55LL, 0x98765432LL, 0xabcd0000LL};
+= {0xffffffff7cdeab55LL, 0x98765432LL, 0xabcd0000LL, 0xffffffff65430000LL};
 
 void __attribute__ ((__noipa__)) test_li_xoris (long long *arg)
 {
@@ -27,6 +27,13 @@ void __attribute__ ((__noipa__)) test_lis_rldicl (long long *arg)
 /* { dg-final { scan-assembler-times {\mlis .*,0xabcd\M} 1 } } */
 /* { dg-final { scan-assembler-times {\mrldicl .*,0,32\M} 1 } } */
 
+void __attribute__ ((__noipa__)) test_lis_xoris (long long *arg)
+{
+  *arg = 0xffffffff65430000LL;
+}
+/* { dg-final { scan-assembler-times {\mlis .*,0xe543\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxoris .*0x8000\M} 1 } } */
+
 int
 main ()
 {
@@ -35,6 +42,7 @@ main ()
   test_li_xoris (a);
   test_li_oris (a + 1);
   test_lis_rldicl (a + 2);
+  test_lis_xoris (a + 3);
   if (__builtin_memcmp (a, arr, sizeof (arr)) != 0)
     __builtin_abort ();
   return 0;