Bug 67929 - [4.9/5/6 Regression][arm] Wrong code for FP mult-by-power-of-2 + int conversion
Summary: [4.9/5/6 Regression][arm] Wrong code for FP mult-by-power-of-2 + int conversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.4
Assignee: ktkachov
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-10-12 10:57 UTC by ktkachov
Modified: 2015-11-02 14:35 UTC (History)
1 user (show)

See Also:
Host:
Target: arm*
Build:
Known to work: 4.8.4
Known to fail: 4.9.4, 5.2.1, 6.0
Last reconfirmed: 2015-10-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ktkachov 2015-10-12 10:57:26 UTC
Testcase:

int
foo (float a)
{
  return a * 4.9f;
}


int
main (void)
{
  if (foo (10.0f) != 49)
    __builtin_abort ();

  return 0;
}

Compiled with -Ofast -mfpu=vfpv3 -mfloat-abi=hard -mcpu=cortex-a15 -fno-inline
aborts.

The problem is foo (10.0f) returns 40.
This is because the combine_vcvtf2i triggers where its predicate should have rejected 4.9f

The vfp3_const_double_for_bits function in arm.c is too liberal and accepts any FP constant that, when truncated, evaluates to a power of 2 FP constant.
Comment 1 ktkachov 2015-10-12 11:00:04 UTC
I have a fix
Comment 2 Ramana Radhakrishnan 2015-10-15 19:43:53 UTC
Confirmed.
Comment 3 ktkachov 2015-10-27 12:24:22 UTC
Author: ktkachov
Date: Tue Oct 27 12:23:51 2015
New Revision: 229436

URL: https://gcc.gnu.org/viewcvs?rev=229436&root=gcc&view=rev
Log:
[ARM] PR target/67929 Tighten vfp3_const_double_for_bits checks

	PR target/67929
	* config/arm/arm.c (vfp3_const_double_for_bits): Rewrite.
	* config/arm/constraints.md (Dp): Update callsite.
	* config/arm/predicates.md (const_double_vcvt_power_of_two): Likewise.

	* gcc.target/arm/pr67929_1.c: New test.


Added:
    trunk/gcc/testsuite/gcc.target/arm/pr67929_1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.c
    trunk/gcc/config/arm/constraints.md
    trunk/gcc/config/arm/predicates.md
    trunk/gcc/testsuite/ChangeLog
Comment 4 ktkachov 2015-10-27 13:46:47 UTC
Author: ktkachov
Date: Tue Oct 27 13:46:15 2015
New Revision: 229439

URL: https://gcc.gnu.org/viewcvs?rev=229439&root=gcc&view=rev
Log:
[ARM] PR target/67929 Tighten vfp3_const_double_for_bits checks

	PR target/67929
	* config/arm/arm.c (vfp3_const_double_for_bits): Rewrite.
	* config/arm/constraints.md (Dp): Update callsite.
	* config/arm/predicates.md (const_double_vcvt_power_of_two): Likewise.

	* gcc.target/arm/pr67929_1.c: New test.


Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.target/arm/pr67929_1.c
Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/config/arm/arm.c
    branches/gcc-5-branch/gcc/config/arm/constraints.md
    branches/gcc-5-branch/gcc/config/arm/predicates.md
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 5 ktkachov 2015-10-27 13:52:59 UTC
Author: ktkachov
Date: Tue Oct 27 13:52:27 2015
New Revision: 229441

URL: https://gcc.gnu.org/viewcvs?rev=229441&root=gcc&view=rev
Log:
[ARM] PR target/67929 Tighten vfp3_const_double_for_bits checks

	PR target/67929
	* config/arm/arm.c (vfp3_const_double_for_bits): Rewrite.
	* config/arm/constraints.md (Dp): Update callsite.
	* config/arm/predicates.md (const_double_vcvt_power_of_two): Likewise.

	* gcc.target/arm/pr67929_1.c: New test.


Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/arm/pr67929_1.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/config/arm/arm.c
    branches/gcc-4_9-branch/gcc/config/arm/constraints.md
    branches/gcc-4_9-branch/gcc/config/arm/predicates.md
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 6 ktkachov 2015-10-27 13:53:37 UTC
Fixed on trunk, GCC 5 and 4.9 branches
Comment 7 Christophe Lyon 2015-10-28 08:03:42 UTC
I think the testcase or check_effective_target_arm_vfp3_ok needs an adjustment: when GCC is configured for arm-none-linux-gnueabihf, since the test is compiled with -mfloat-abi=softfp, there is an error at link time because the crt*.o files are compiled with float-abi=hard, and thus conflict with pr67929_1.o.

This is because check_effective_target_arm_vfp3_ok only checks whether a *compilation* with -mfloat-abi=soffp works, and does not check that a link actually works.
Comment 8 ktkachov 2015-11-02 12:24:08 UTC
Author: ktkachov
Date: Mon Nov  2 12:23:36 2015
New Revision: 229657

URL: https://gcc.gnu.org/viewcvs?rev=229657&root=gcc&view=rev
Log:
Move gcc.target/arm/pr67929_1.c test to execute.exp

	PR target/67929
	* gcc.target/arm/pr67929_1.c: Move to...
	* gcc.c-torture/execute/pr67929_1.c: ... Here.
	Remove arm-specific directives.  Add noclone, noinline
	attributes.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr67929_1.c
Removed:
    trunk/gcc/testsuite/gcc.target/arm/pr67929_1.c
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 9 ktkachov 2015-11-02 12:27:11 UTC
Author: ktkachov
Date: Mon Nov  2 12:26:39 2015
New Revision: 229658

URL: https://gcc.gnu.org/viewcvs?rev=229658&root=gcc&view=rev
Log:
Move gcc.target/arm/pr67929_1.c test to execute.exp

	PR target/67929
	* gcc.target/arm/pr67929_1.c: Move to...
	* gcc.c-torture/execute/pr67929_1.c: ... Here.
	Remove arm-specific directives.  Add noclone, noinline
	attributes.

Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.c-torture/execute/pr67929_1.c
Removed:
    branches/gcc-5-branch/gcc/testsuite/gcc.target/arm/pr67929_1.c
Modified:
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 10 ktkachov 2015-11-02 12:30:03 UTC
Author: ktkachov
Date: Mon Nov  2 12:29:31 2015
New Revision: 229659

URL: https://gcc.gnu.org/viewcvs?rev=229659&root=gcc&view=rev
Log:
Move gcc.target/arm/pr67929_1.c test to execute.exp

	PR target/67929
	* gcc.target/arm/pr67929_1.c: Move to...
	* gcc.c-torture/execute/pr67929_1.c: ... Here.
	Remove arm-specific directives.  Add noclone, noinline
	attributes.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.c-torture/execute/pr67929_1.c
Removed:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/arm/pr67929_1.c
Modified:
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 11 ktkachov 2015-11-02 14:35:51 UTC
(In reply to Christophe Lyon from comment #7)
> This is because check_effective_target_arm_vfp3_ok only checks whether a
> *compilation* with -mfloat-abi=soffp works, and does not check that a link
> actually works.

Following some discussion on gcc-patches I've moved the test to gcc.c-torture/execute