Bug 67218 - Combine incorrectly folds (double) (float) (unsigned)
Summary: Combine incorrectly folds (double) (float) (unsigned)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: rsandifo@gcc.gnu.org
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-08-14 15:19 UTC by rsandifo@gcc.gnu.org
Modified: 2015-08-18 19:11 UTC (History)
0 users

See Also:
Host:
Target: aarch64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-08-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rsandifo@gcc.gnu.org 2015-08-14 15:19:11 UTC
simplify-rtx.c folds (double) (float) (some-int) into
(double) (some-int) if it can prove that the intermediate
(float) doesn't have any effect.  This check is based on
the number of known "sign bit copies", which inherently assumes
a signed interpretation of (some-int) and is therefore only
valid for FLOAT.  For UNSIGNED_FLOAT we can end up treating a
large unsigned value as fitting in a float.

The following test case fails at -O and above on aarch64-linux-gnu
because of this:

extern void abort (void) __attribute__ ((noreturn));

double __attribute__ ((noinline, noclone))
foo (unsigned int x)
{
  return (double) (float) (x | 0xffff0000);
}

int
main ()
{
  if (foo (1) != 0x1.fffep31)
    abort ();
  return 0;
}
Comment 1 rsandifo@gcc.gnu.org 2015-08-18 19:05:12 UTC
Author: rsandifo
Date: Tue Aug 18 19:04:41 2015
New Revision: 226987

URL: https://gcc.gnu.org/viewcvs?rev=226987&root=gcc&view=rev
Log:
gcc/
	PR rtl-optimization/67218
	* simplify-rtx.c (exact_int_to_float_conversion_p): New function.
	(simplify_unary_operation_1): Use it.

gcc/testsuite/
	PR rtl-optimization/67218
	* gcc.c-torture/execute/ieee/pr67218.c,
	gcc.target/aarch64/fcvt_int_float_double1.c,
	gcc.target/aarch64/fcvt_int_float_double2.c,
	gcc.target/aarch64/fcvt_int_float_double3.c,
	gcc.target/aarch64/fcvt_int_float_double4.c,
	gcc.target/aarch64/fcvt_uint_float_double1.c,
	gcc.target/aarch64/fcvt_uint_float_double2.c,
	gcc.target/aarch64/fcvt_uint_float_double3.c,
	gcc.target/aarch64/fcvt_uint_float_double4.c: New tests.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/ieee/pr67218.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_int_float_double1.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_int_float_double2.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_int_float_double3.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_int_float_double4.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_uint_float_double1.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_uint_float_double2.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_uint_float_double3.c
    trunk/gcc/testsuite/gcc.target/aarch64/fcvt_uint_float_double4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/simplify-rtx.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 rsandifo@gcc.gnu.org 2015-08-18 19:11:10 UTC
Patch applied to trunk.  It turned out to be a gcc 6 regression,
so no backports are needed.