Bug 66731 - vnmul, fnmul patterns incorrect for -frounding-math
Summary: vnmul, fnmul patterns incorrect for -frounding-math
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: nsz
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-07-01 21:44 UTC by Joseph S. Myers
Modified: 2015-08-05 09:02 UTC (History)
2 users (show)

See Also:
Host:
Target: arm*-*-* aarch64*-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-07-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph S. Myers 2015-07-01 21:44:13 UTC
config/arm/vfp.md has patterns:

(define_insn "*mulsf3negsf_vfp"
  [(set (match_operand:SF                  0 "s_register_operand" "=t")
        (mult:SF (neg:SF (match_operand:SF 1 "s_register_operand" "t"))
                 (match_operand:SF         2 "s_register_operand" "t")))]
  "TARGET_32BIT && TARGET_HARD_FLOAT && TARGET_VFP"
  "vnmul%?.f32\\t%0, %1, %2"
  [(set_attr "predicable" "yes")
   (set_attr "predicable_short_it" "no")
   (set_attr "type" "fmuls")]
)

(define_insn "*muldf3negdf_vfp"
  [(set (match_operand:DF                  0 "s_register_operand" "=w")
        (mult:DF (neg:DF (match_operand:DF 1 "s_register_operand" "w"))
                 (match_operand:DF         2 "s_register_operand" "w")))]
  "TARGET_32BIT && TARGET_HARD_FLOAT && TARGET_VFP_DOUBLE"
  "vnmul%?.f64\\t%P0, %P1, %P2"
  [(set_attr "predicable" "yes")
   (set_attr "predicable_short_it" "no")
   (set_attr "type" "fmuld")]
)

These describe the vnmul instruction as (-a) * b.  It's actually -(a * b).  The two are different in round-upwards and round-downwards modes.  This is resulting in miscompilation of tgamma from current glibc git (which uses (-a) * b, expecting that actual multiplication), and consequent test failures.  On inspection, AArch64 fnmul is similarly misdescribed, although I haven't done any testing there.
Comment 1 nsz 2015-07-06 11:00:38 UTC
Author: nsz
Date: Mon Jul  6 11:00:03 2015
New Revision: 225450

URL: https://gcc.gnu.org/viewcvs?rev=225450&root=gcc&view=rev
Log:
[AArch64] PR target/66731 Fix fnmul insn with -frounding-math

gcc/Changelog:

2015-07-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.md (fnmul<mode>3): Handle -frounding-math.

gcc/testsuite/Changelog:

2015-07-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	* gcc.target/aarch64/fnmul-1.c: New.
	* gcc.target/aarch64/fnmul-2.c: New.
	* gcc.target/aarch64/fnmul-3.c: New.
	* gcc.target/aarch64/fnmul-4.c: New.


Added:
    trunk/gcc/testsuite/gcc.target/aarch64/fnmul-1.c
    trunk/gcc/testsuite/gcc.target/aarch64/fnmul-2.c
    trunk/gcc/testsuite/gcc.target/aarch64/fnmul-3.c
    trunk/gcc/testsuite/gcc.target/aarch64/fnmul-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/aarch64/aarch64.md
    trunk/gcc/testsuite/ChangeLog
Comment 2 nsz 2015-07-15 09:03:46 UTC
Author: nsz
Date: Wed Jul 15 09:03:15 2015
New Revision: 225810

URL: https://gcc.gnu.org/viewcvs?rev=225810&root=gcc&view=rev
Log:
Add missing PR target/66731 to gcc/testsuite/Changelog

Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 3 Ramana Radhakrishnan 2015-07-22 15:13:48 UTC
Confirmed.
Comment 4 nsz 2015-08-03 11:12:32 UTC
Author: nsz
Date: Mon Aug  3 11:12:00 2015
New Revision: 226496

URL: https://gcc.gnu.org/viewcvs?rev=226496&root=gcc&view=rev
Log:
[ARM] PR target/66731 Fix vnmul insn with -frounding-math

gcc:

	PR target/66731
	* config/arm/vfp.md (negmuldf3_vfp): Add new pattern.
	(negmulsf3_vfp): Likewise.
	(muldf3negdf_vfp): Disable for -frounding-math.
	(mulsf3negsf_vfp): Likewise.
	* config/arm/arm.c (arm_new_rtx_costs): Fix NEG cost for VNMUL,
	fix MULT cost with -frounding-math.

gcc/testsuite:

	PR target/66731
	* gcc.target/arm/vnmul-1.c: New.
	* gcc.target/arm/vnmul-2.c: New.
	* gcc.target/arm/vnmul-3.c: New.
	* gcc.target/arm/vnmul-4.c: New.


Added:
    trunk/gcc/testsuite/gcc.target/arm/vnmul-1.c
    trunk/gcc/testsuite/gcc.target/arm/vnmul-2.c
    trunk/gcc/testsuite/gcc.target/arm/vnmul-3.c
    trunk/gcc/testsuite/gcc.target/arm/vnmul-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.c
    trunk/gcc/config/arm/vfp.md
    trunk/gcc/testsuite/ChangeLog
Comment 5 nsz 2015-08-03 14:28:15 UTC
Author: nsz
Date: Mon Aug  3 14:27:43 2015
New Revision: 226507

URL: https://gcc.gnu.org/viewcvs?rev=226507&root=gcc&view=rev
Log:
Backport form mainline r226496.

gcc:

	Backport form mainline r226496.
	2015-08-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/arm/vfp.md (negmuldf3_vfp): Add new pattern.
	(negmulsf3_vfp): Likewise.
	(muldf3negdf_vfp): Disable for -frounding-math.
	(mulsf3negsf_vfp): Likewise.
	* config/arm/arm.c (arm_new_rtx_costs): Fix NEG cost for VNMUL,
	fix MULT cost with -frounding-math.

gcc/testsuite:

	Backport form mainline r226496.
	2015-08-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* gcc.target/arm/vnmul-1.c: New.
	* gcc.target/arm/vnmul-2.c: New.
	* gcc.target/arm/vnmul-3.c: New.
	* gcc.target/arm/vnmul-4.c: New.


Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.target/arm/vnmul-1.c
    branches/gcc-5-branch/gcc/testsuite/gcc.target/arm/vnmul-2.c
    branches/gcc-5-branch/gcc/testsuite/gcc.target/arm/vnmul-3.c
    branches/gcc-5-branch/gcc/testsuite/gcc.target/arm/vnmul-4.c
Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/config/arm/arm.c
    branches/gcc-5-branch/gcc/config/arm/vfp.md
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 6 nsz 2015-08-03 17:05:01 UTC
Author: nsz
Date: Mon Aug  3 17:04:29 2015
New Revision: 226519

URL: https://gcc.gnu.org/viewcvs?rev=226519&root=gcc&view=rev
Log:
Backport form mainline r226496.

gcc:

	Backport form mainline r226496.
	2015-08-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/arm/vfp.md (negmuldf3_vfp): Add new pattern.
	(negmulsf3_vfp): Likewise.
	(muldf3negdf_vfp): Disable for -frounding-math.
	(mulsf3negsf_vfp): Likewise.
	* config/arm/arm.c (arm_new_rtx_costs): Fix NEG cost for VNMUL,
	fix MULT cost with -frounding-math.

gcc/testsuite:

	Backport form mainline r226496.
	2015-08-03  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* gcc.target/arm/vnmul-1.c: New.
	* gcc.target/arm/vnmul-2.c: New.
	* gcc.target/arm/vnmul-3.c: New.
	* gcc.target/arm/vnmul-4.c: New.


Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/arm/vnmul-1.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/arm/vnmul-2.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/arm/vnmul-3.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/arm/vnmul-4.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/vfp.md
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 7 nsz 2015-08-04 16:23:04 UTC
Author: nsz
Date: Tue Aug  4 16:22:32 2015
New Revision: 226586

URL: https://gcc.gnu.org/viewcvs?rev=226586&root=gcc&view=rev
Log:
[AArch64] PR target/66731 Fix fnmul insn with -frounding-math (rtx costs)

2015-08-04  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.c (aarch64_rtx_costs): Fix NEG cost for FNMUL.
	(aarch64_rtx_mult_cost): Fix MULT cost with -frounding-math.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/aarch64/aarch64.c
Comment 8 nsz 2015-08-04 16:44:18 UTC
Author: nsz
Date: Tue Aug  4 16:43:46 2015
New Revision: 226587

URL: https://gcc.gnu.org/viewcvs?rev=226587&root=gcc&view=rev
Log:
gcc:

	Backport from mainline:
	2015-08-04  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.c (aarch64_rtx_costs): Fix NEG cost for FNMUL.
	(aarch64_rtx_mult_cost): Fix MULT cost with -frounding-math.

	2015-07-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.md (fnmul<mode>3): Handle -frounding-math.

gcc/testsuite:

	Backport from mainline r225450:
	2015-07-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* gcc.target/aarch64/fnmul-1.c: New.
	* gcc.target/aarch64/fnmul-2.c: New.
	* gcc.target/aarch64/fnmul-3.c: New.
	* gcc.target/aarch64/fnmul-4.c: New.


Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.target/aarch64/fnmul-1.c
    branches/gcc-5-branch/gcc/testsuite/gcc.target/aarch64/fnmul-2.c
    branches/gcc-5-branch/gcc/testsuite/gcc.target/aarch64/fnmul-3.c
    branches/gcc-5-branch/gcc/testsuite/gcc.target/aarch64/fnmul-4.c
Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/config/aarch64/aarch64.c
    branches/gcc-5-branch/gcc/config/aarch64/aarch64.md
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 9 nsz 2015-08-04 16:50:25 UTC
Author: nsz
Date: Tue Aug  4 16:49:54 2015
New Revision: 226588

URL: https://gcc.gnu.org/viewcvs?rev=226588&root=gcc&view=rev
Log:
Fix broken backport patch.

gcc:

	Backport from mainline:
	2015-08-04  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.c (aarch64_rtx_costs): Fix NEG cost for FNMUL.
	(aarch64_rtx_mult_cost): Fix MULT cost with -frounding-math.


Modified:
    branches/gcc-5-branch/gcc/config/aarch64/aarch64.c
Comment 10 nsz 2015-08-04 17:42:37 UTC
Author: nsz
Date: Tue Aug  4 17:42:05 2015
New Revision: 226592

URL: https://gcc.gnu.org/viewcvs?rev=226592&root=gcc&view=rev
Log:
gcc:
	Backport from mainline:
	2015-07-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* config/aarch64/aarch64.md (fnmul<mode>3): Handle -frounding-math.

gcc/testsuite:

	Backport from mainline r225450:
	2015-07-06  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	PR target/66731
	* gcc.target/aarch64/fnmul-1.c: New.
	* gcc.target/aarch64/fnmul-2.c: New.
	* gcc.target/aarch64/fnmul-3.c: New.
	* gcc.target/aarch64/fnmul-4.c: New.


Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/aarch64/fnmul-1.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/aarch64/fnmul-2.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/aarch64/fnmul-3.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/aarch64/fnmul-4.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/config/aarch64/aarch64.md
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 11 nsz 2015-08-05 08:57:11 UTC
both arm and aarch64 should be fixed now (fix is backported to 4.9 and 5 branches)
Comment 12 Ramana Radhakrishnan 2015-08-05 09:02:48 UTC
Fixed for 4.9.4