xtensa: Minor fix for FP constant synthesis
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Wed, 13 Jul 2022 11:40:13 +0000 (20:40 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Thu, 14 Jul 2022 07:03:35 +0000 (00:03 -0700)
This patch fixes an non-fatal issue about negative constant values derived
from FP constant synthesis on hosts whose 'long' is wider than 'int32_t'.

And also replaces the dedicated code in FP constant synthesis split
pattern with the appropriate existing function call.

gcc/ChangeLog:

* config/xtensa/xtensa.md:
In FP constant synthesis split pattern, subcontract to
avoid_constant_pool_reference() as in the case of integer,
because it can handle well too.  And cast to int32_t before
calling xtensa_constantsynth() in order to ignore upper 32-bit.

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/constsynth_double.c:
Modify in order to catch the issue.

gcc/config/xtensa/xtensa.md
gcc/testsuite/gcc.target/xtensa/constsynth_double.c

index 9d99858..6a58d3e 100644 (file)
   "! optimize_debug && reload_completed"
   [(const_int 0)]
 {
-  int i = 0;
-  rtx x = XEXP (operands[1], 0);
-  long l[2];
-  if (SYMBOL_REF_P (x)
-      && CONSTANT_POOL_ADDRESS_P (x))
-    x = get_pool_constant (x);
-  else if (GET_CODE (x) == CONST)
-    {
-      x = XEXP (x, 0);
-      gcc_assert (GET_CODE (x) == PLUS
-                 && SYMBOL_REF_P (XEXP (x, 0))
-                 && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))
-                 && CONST_INT_P (XEXP (x, 1)));
-      i = INTVAL (XEXP (x, 1));
-      gcc_assert (i == 0 || i == 4);
-      i /= 4;
-      x = get_pool_constant (XEXP (x, 0));
-    }
-  else
-    gcc_unreachable ();
-  if (GET_MODE (x) == SFmode)
-    REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l[0]);
-  else if (GET_MODE (x) == DFmode)
-    REAL_VALUE_TO_TARGET_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), l);
-  else
+  rtx x = avoid_constant_pool_reference (operands[1]);
+  long l;
+  HOST_WIDE_INT value;
+  if (! CONST_DOUBLE_P (x) || GET_MODE (x) != SFmode)
     FAIL;
+  REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), l);
   x = gen_rtx_REG (SImode, REGNO (operands[0]));
-  if (! xtensa_constantsynth (x, l[i]))
-    emit_move_insn (x, GEN_INT (l[i]));
+  value = (int32_t)l;
+  if (! xtensa_constantsynth (x, value))
+    emit_move_insn (x, GEN_INT (value));
   DONE;
 })
 
index 890ca50..5fba6a9 100644 (file)
@@ -5,7 +5,7 @@ void test(unsigned int count, double array[])
 {
   unsigned int i;
   for (i = 0; i < count; ++i)
-    array[i] = 1.0;
+    array[i] = 8.988474246316506e+307;
 }
 
 /* { dg-final { scan-assembler-not "l32r" } } */