From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2063) id 6B44A3858D1E; Tue, 20 Jun 2023 08:24:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B44A3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687249483; bh=Hcoy171Q8sZkHwIzguR9oRU8nF0mI1mYC0EJqyiBgyQ=; h=From:To:Subject:Date:From; b=qyKgCTciaNcn2yAmOso1coqGXLgog42orv4cZKu39xm3hMPS9CmWqnPJi+nOt4UZq Kzg+fGWb72A5cn/1bs3EiidR795xR6g+yNasq3j9xJtXQc18yR4W2451dsasO2MJuW gNCNS+FcdAX2ePkCg6is2Y/FhEIAMFAYA9TsiP0M= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kewen Lin To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10865] rs6000: Don't use TFmode for 128 bits fp constant in toc [PR110011] X-Act-Checkin: gcc X-Git-Author: Kewen Lin X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 9856b87fa399ad1e2cbc5c708f4c5faf444f460a X-Git-Newrev: bccc9960eb728bfd890c9388593bd166efcd0591 Message-Id: <20230620082443.6B44A3858D1E@sourceware.org> Date: Tue, 20 Jun 2023 08:24:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bccc9960eb728bfd890c9388593bd166efcd0591 commit r11-10865-gbccc9960eb728bfd890c9388593bd166efcd0591 Author: Kewen Lin Date: Mon Jun 12 01:07:52 2023 -0500 rs6000: Don't use TFmode for 128 bits fp constant in toc [PR110011] As PR110011 shows, when encoding 128 bits fp constant into toc, we adopts REAL_VALUE_TO_TARGET_LONG_DOUBLE which is to find the first float mode with LONG_DOUBLE_TYPE_SIZE bits of precision, it would be TFmode here. But the 128 bits fp constant can be with mode IFmode or KFmode, which doesn't necessarily have the same underlying float format as the one of TFmode, like this PR exposes, with option -mabi=ibmlongdouble TFmode has ibm_extended_format while KFmode has ieee_quad_format, mixing up the formats (the encoding/decoding ways) would cause unexpected results. This patch is to make it use constant's own mode instead of TFmode for real_to_target call. PR target/110011 gcc/ChangeLog: * config/rs6000/rs6000.c (output_toc): Use the mode of the 128-bit floating constant itself for real_to_target call. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr110011.c: New test. (cherry picked from commit 388809f2afde874180da0669c669e241037eeba0) Diff: --- gcc/config/rs6000/rs6000.c | 2 +- gcc/testsuite/gcc.target/powerpc/pr110011.c | 42 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index c3854a931da..ade91e213d4 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -17042,7 +17042,7 @@ output_toc (FILE *file, rtx x, int labelno, machine_mode mode) if (DECIMAL_FLOAT_MODE_P (GET_MODE (x))) REAL_VALUE_TO_TARGET_DECIMAL128 (*CONST_DOUBLE_REAL_VALUE (x), k); else - REAL_VALUE_TO_TARGET_LONG_DOUBLE (*CONST_DOUBLE_REAL_VALUE (x), k); + real_to_target (k, CONST_DOUBLE_REAL_VALUE (x), GET_MODE (x)); if (TARGET_64BIT) { diff --git a/gcc/testsuite/gcc.target/powerpc/pr110011.c b/gcc/testsuite/gcc.target/powerpc/pr110011.c new file mode 100644 index 00000000000..5b04d3e298a --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr110011.c @@ -0,0 +1,42 @@ +/* { dg-do run } */ +/* { dg-require-effective-target float128_runtime } */ +/* Force long double to be with IBM format here, to verify + _Float128 constant still uses its own format (IEEE) for + encoding rather than IBM format. */ +/* { dg-options "-mfp-in-toc -mabi=ibmlongdouble" } */ +/* { dg-add-options float128 } */ + +#define MPFR_FLOAT128_MAX 0x1.ffffffffffffffffffffffffffffp+16383f128 + +__attribute__ ((noipa)) +_Float128 f128_max () +{ + return MPFR_FLOAT128_MAX; +} + +typedef union +{ + int w[4]; + _Float128 f128; +} U; + +int main () +{ + + U umax; + umax.f128 = f128_max (); + /* ieee float128 max: + 7ffeffff ffffffff ffffffff ffffffff. */ + if (umax.w[1] != 0xffffffff || umax.w[2] != 0xffffffff) + __builtin_abort (); +#ifdef __LITTLE_ENDIAN__ + if (umax.w[0] != 0xffffffff || umax.w[3] != 0x7ffeffff) + __builtin_abort (); +#else + if (umax.w[3] != 0xffffffff || umax.w[0] != 0x7ffeffff) + __builtin_abort (); +#endif + + return 0; +} +