Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8319705: RISC-V: signumF/D intrinsics fails compiler/intrinsics/math/TestSignumIntrinsic.java #16557

Closed
wants to merge 6 commits into from

Conversation

Hamlin-Li
Copy link

@Hamlin-Li Hamlin-Li commented Nov 8, 2023

Hi,
Can you review the patch to fix the bug introduced by JDK-8317971 which implemented signumF/D intrinsics.
But seems the intrinsics failed since day 1 (I checkouted the commit to verify it.)
Thanks

## Test
hotspot tests:

test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java
test/hotspot/jtreg/compiler/c2/PolynomialRoot.java

other jdk tests contains Math.signum(...):

test/jdk/java/math/BigInteger/BigIntegerTest.java 
test/jdk/java/math/BigInteger/largeMemory/DivisionOverflow.java
test/jdk/java/math/BigInteger/SerializationTests.java
test/jdk/java/math/BigInteger/ModInvTime.java
test/jdk/java/math/BigDecimal/SquareRootTests.java
test/jdk/java/math/BigDecimal/DivideTests.java
test/jdk/java/lang/Math/IeeeRecommendedTests.java
test/jdk/java/lang/Math/IeeeRemainderTests.java

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8319705: RISC-V: signumF/D intrinsics fails compiler/intrinsics/math/TestSignumIntrinsic.java (Bug - P2)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16557/head:pull/16557
$ git checkout pull/16557

Update a local copy of the PR:
$ git checkout pull/16557
$ git pull https://git.openjdk.org/jdk.git pull/16557/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16557

View PR using the GUI difftool:
$ git pr show -t 16557

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16557.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 8, 2023

👋 Welcome back mli! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 8, 2023
@openjdk
Copy link

openjdk bot commented Nov 8, 2023

@Hamlin-Li The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Nov 8, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 8, 2023

Webrevs

@RealFYang
Copy link
Member

Do you have more details about the problem? Those tests are passing on hifive unmatched board using today's jdk master.

@Hamlin-Li
Copy link
Author

I ran it via qemu, triggered the test with Xcomp to make sure the intrinsic is installed.
It just failed with fastdebug version, no special config.

@VladimirKempik
Copy link

So maybe the test compiler/intrinsics/math/TestSignumIntrinsic.java doesn't test anything on risc-v in default mode ?

@VladimirKempik
Copy link

it's not clear what's wrong with original version
instead of using t0 as temp register inside signumFD, you explicetly requested tmp register from C2

but t0 is not allocatable ( by c2 reg alloc) register and often used freely.

I don't get it what failed and why it doesn't fail anymore

@RealFYang
Copy link
Member

RealFYang commented Nov 9, 2023

OK. I can now reproduce the bug with following command on sifive unmatched board:

make test TEST="./test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java" JTREG="VM_OPTIONS=-XX:-TieredCompilation"

Error message:

java.lang.RuntimeException: Unexpected double result from 123.4: expected 1.0 to equal 123.4
        at jdk.test.lib.Asserts.fail(Asserts.java:634)
        at jdk.test.lib.Asserts.assertEquals(Asserts.java:205)
        at jdk.test.lib.Asserts.assertEQ(Asserts.java:178)
        at compiler.intrinsics.math.TestSignumIntrinsic.doubleTest(TestSignumIntrinsic.java:114)
        at compiler.intrinsics.math.TestSignumIntrinsic.main(TestSignumIntrinsic.java:91)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
        at java.base/java.lang.Thread.run(Thread.java:1570)

JavaTest Message: Test threw exception: java.lang.RuntimeException: Unexpected double result from 123.4: expected 1.0 to equal 123.4

But it does not always reproduce as I think it depends on C2 register allocation.
For C2_MacroAssembler::signum_fp, it has three FP registers: dst, src, and one. And it is possible (and I have verified) that dst and one could be assigned the same FP register. This will be a problem after change [1]. This change copies src to dst on entry, thus modifies one in that case. This is erroneous as one is still alive here and will be used later by fsgnj_d/s when src is not NaN or +/-0.0.

[1] 867d6e8

void C2_MacroAssembler::signum_fp(FloatRegister dst, FloatRegister src, FloatRegister one, bool is_double) {
Register tmp1 = t0;

void C2_MacroAssembler::signum_fp(FloatRegister dst, FloatRegister one, Register tmp, bool is_double) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could still make use of scratch register t0 in this function. That will save us one GP register.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it make sense.

instruct signumD_reg(fRegD dst, fRegD src, immD zero, fRegD one) %{
match(Set dst (SignumD src (Binary zero one)));
format %{ "signumD $dst, $src" %}
instruct signumD_reg(fRegD dst, immD zero, fRegD one, iRegLNoSp tmp) %{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to reserve tmp here. See my previous comment.

instruct signumF_reg(fRegF dst, fRegF src, immF zero, fRegF one) %{
match(Set dst (SignumF src (Binary zero one)));
format %{ "signumF $dst, $src" %}
instruct signumF_reg(fRegF dst, immF zero, fRegF one, iRegLNoSp tmp) %{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to reserve tmp here. See my previous comment.

@VladimirKempik
Copy link

it's not clear what's wrong with original version instead of using t0 as temp register inside signumFD, you explicetly requested tmp register from C2

but t0 is not allocatable ( by c2 reg alloc) register and often used freely.

I don't get it what failed and why it doesn't fail anymore

I see now, when dst register is the same as register one, we've got the issue, and we can provoke such behaviour from RegAlloc only when disabling C1. test needs to be modified as well

@Hamlin-Li
Copy link
Author

@RealFYang Thank you for exploring and sharing the information.

@openjdk
Copy link

openjdk bot commented Nov 9, 2023

@Hamlin-Li This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8319705: RISC-V: signumF/D intrinsics fails compiler/intrinsics/math/TestSignumIntrinsic.java

Reviewed-by: fyang, vkempik

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 20 new commits pushed to the master branch:

  • f57b78c: 8319726: Parallel GC: Re-use object in object-iterator
  • 4451a92: 8319748: [JVMCI] TestUseCompressedOopsFlagsWithUlimit.java crashes on libgraal
  • 7d8adfa: 8316746: Top of lock-stack does not match the unlocked object
  • dd9eab1: 8310886: C2 SuperWord: Two nodes should be isomorphic if they are loop invariant but pinned at different nodes outside the loop
  • 7e4cb2f: 8318962: Update ProcessTools javadoc with suggestions in 8315097
  • 0b58bde: 8319104: GtestWrapper crashes with SIGILL in AsyncLogTest::test_asynclog_raw on AIX opt
  • b0fc808: 8319725: G1: Subtracting virtual time from wall time after JDK-8319204
  • a26f7c0: 6928542: Chinese characters in RTF are not decoded
  • 4e8c036: 8319665: [macOS] Obsolete imports of <Carbon/Carbon.h> in java.desktop
  • f4ab952: 8319253: [BACKOUT] Change LockingMode default from LM_LEGACY to LM_LIGHTWEIGHT
  • ... and 10 more: https://git.openjdk.org/jdk/compare/1e687b4529ae695d991623dc13796faecd6be7da...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 9, 2023
@VladimirKempik
Copy link

Please don' integrate until testcase update info is clear, we are working on it

@Hamlin-Li
Copy link
Author

Please don' integrate until testcase update info is clear, we are working on it

Sure, thanks!

@Ilyagavrilin
Copy link

Hi, could you, please, add this small update to jtreg: hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java:

diff --git a/test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java b/test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java
index 65d261bb8e2..a5546ba9e5c 100644
--- a/test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java
+++ b/test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java
@@ -35,6 +35,10 @@
  *      -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  *      -XX:-UseSignumIntrinsic -XX:+UseCopySignIntrinsic
  *      compiler.intrinsics.math.TestSignumIntrinsic
+ * @run main/othervm
+ *      -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
+ *      -Xcomp -XX:+UseSignumIntrinsic
+ *      compiler.intrinsics.math.TestSignumIntrinsic
  */
 
 package compiler.intrinsics.math;

@Hamlin-Li
Copy link
Author

Thanks @Ilyagavrilin @VladimirKempik, test modified.

@VladimirKempik
Copy link

@Hamlin-Li do you have GHA enabled for your repo ? It would be nice to let tier1 in gha pass to check updated test on all x86 platforms

@Hamlin-Li
Copy link
Author

@Hamlin-Li do you have GHA enabled for your repo ? It would be nice to let tier1 in gha pass to check updated test on all x86 platforms

Yes, I think so.

@Hamlin-Li
Copy link
Author

/integrate

Thanks @RealFYang @VladimirKempik @Ilyagavrilin for your review.

@openjdk
Copy link

openjdk bot commented Nov 9, 2023

Going to push as commit 7b971c1.
Since your change was applied there have been 22 commits pushed to the master branch:

  • f939542: 8319324: FFM: Reformat javadocs
  • a3f1b33: 8319664: IGV always output on PhaseRemoveUseless
  • f57b78c: 8319726: Parallel GC: Re-use object in object-iterator
  • 4451a92: 8319748: [JVMCI] TestUseCompressedOopsFlagsWithUlimit.java crashes on libgraal
  • 7d8adfa: 8316746: Top of lock-stack does not match the unlocked object
  • dd9eab1: 8310886: C2 SuperWord: Two nodes should be isomorphic if they are loop invariant but pinned at different nodes outside the loop
  • 7e4cb2f: 8318962: Update ProcessTools javadoc with suggestions in 8315097
  • 0b58bde: 8319104: GtestWrapper crashes with SIGILL in AsyncLogTest::test_asynclog_raw on AIX opt
  • b0fc808: 8319725: G1: Subtracting virtual time from wall time after JDK-8319204
  • a26f7c0: 6928542: Chinese characters in RTF are not decoded
  • ... and 12 more: https://git.openjdk.org/jdk/compare/1e687b4529ae695d991623dc13796faecd6be7da...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 9, 2023
@openjdk openjdk bot closed this Nov 9, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 9, 2023
@openjdk
Copy link

openjdk bot commented Nov 9, 2023

@Hamlin-Li Pushed as commit 7b971c1.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@Hamlin-Li Hamlin-Li deleted the fix-signum branch February 27, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
4 participants