-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8356760: VectorAPI: Optimize VectorMask.fromLong for all-true/all-false cases #25793
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
Closed
+1,093
−13
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
38664b0
8356760: VectorAPI: Optimize VectorMask.fromLong for all-true/all-fal…
erifan 830e65a
Merge branch 'master' into JDK-8356760
erifan 791e0ab
Address some review comments
erifan 9f07d5c
Simplify the test code
erifan 3913aaa
Merge branch 'master' into JDK-8356760
erifan 8ebe5e5
Refactor the implementation
erifan 738c90e
Merge branch 'master' into JDK-8356760
erifan 6ae43e1
Add JMH benchmarks for cast chain transformation
erifan 4ffc8d9
Add an assertion
erifan 8418ebd
Move the assertion to the beginning of the code block
erifan b1a768e
Set default warm up to 10000 for JTReg tests
erifan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
test/hotspot/jtreg/compiler/vectorapi/VectorMaskCastIdentityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| /* | ||
| * @test | ||
| * @bug 8356760 | ||
| * @library /test/lib / | ||
| * @summary Optimize VectorMask.fromLong for all-true/all-false cases | ||
| * @modules jdk.incubator.vector | ||
| * | ||
| * @run driver compiler.vectorapi.VectorMaskCastIdentityTest | ||
| */ | ||
|
|
||
| package compiler.vectorapi; | ||
|
|
||
| import compiler.lib.ir_framework.*; | ||
| import java.util.Random; | ||
| import jdk.incubator.vector.*; | ||
| import jdk.test.lib.Asserts; | ||
| import jdk.test.lib.Utils; | ||
|
|
||
| public class VectorMaskCastIdentityTest { | ||
| private static final boolean[] mr = new boolean[128]; // 128 is large enough | ||
| private static final Random rd = Utils.getRandomInstance(); | ||
| static { | ||
| for (int i = 0; i < mr.length; i++) { | ||
| mr[i] = rd.nextBoolean(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @IR(counts = { IRNode.VECTOR_MASK_CAST, "= 2" }, applyIfCPUFeatureOr = {"asimd", "true"}) | ||
| public static int testTwoCastToDifferentType() { | ||
| // The types before and after the two casts are not the same, so the cast cannot be eliminated. | ||
| VectorMask<Float> mFloat64 = VectorMask.fromArray(FloatVector.SPECIES_64, mr, 0); | ||
| VectorMask<Double> mDouble128 = mFloat64.cast(DoubleVector.SPECIES_128); | ||
| VectorMask<Integer> mInt64 = mDouble128.cast(IntVector.SPECIES_64); | ||
| return mInt64.trueCount(); | ||
| } | ||
|
|
||
| @Run(test = "testTwoCastToDifferentType") | ||
| public static void testTwoCastToDifferentType_runner() { | ||
| int count = testTwoCastToDifferentType(); | ||
| VectorMask<Float> mFloat64 = VectorMask.fromArray(FloatVector.SPECIES_64, mr, 0); | ||
| Asserts.assertEquals(count, mFloat64.trueCount()); | ||
| } | ||
|
|
||
| @Test | ||
| @IR(counts = { IRNode.VECTOR_MASK_CAST, "= 2" }, applyIfCPUFeatureOr = {"avx2", "true"}) | ||
| public static int testTwoCastToDifferentType2() { | ||
| // The types before and after the two casts are not the same, so the cast cannot be eliminated. | ||
| VectorMask<Integer> mInt128 = VectorMask.fromArray(IntVector.SPECIES_128, mr, 0); | ||
| VectorMask<Double> mDouble256 = mInt128.cast(DoubleVector.SPECIES_256); | ||
| VectorMask<Short> mShort64 = mDouble256.cast(ShortVector.SPECIES_64); | ||
| return mShort64.trueCount(); | ||
| } | ||
|
|
||
| @Run(test = "testTwoCastToDifferentType2") | ||
| public static void testTwoCastToDifferentType2_runner() { | ||
| int count = testTwoCastToDifferentType2(); | ||
| VectorMask<Integer> mInt128 = VectorMask.fromArray(IntVector.SPECIES_128, mr, 0); | ||
| Asserts.assertEquals(count, mInt128.trueCount()); | ||
| } | ||
|
|
||
| @Test | ||
| @IR(counts = { IRNode.VECTOR_MASK_CAST, "= 0" }, applyIfCPUFeatureOr = {"avx2", "true", "asimd", "true"}) | ||
| public static int testTwoCastToSameType() { | ||
| // The types before and after the two casts are the same, so the cast will be eliminated. | ||
| VectorMask<Integer> mInt128 = VectorMask.fromArray(IntVector.SPECIES_128, mr, 0); | ||
| VectorMask<Float> mFloat128 = mInt128.cast(FloatVector.SPECIES_128); | ||
| VectorMask<Integer> mInt128_2 = mFloat128.cast(IntVector.SPECIES_128); | ||
| return mInt128_2.trueCount(); | ||
| } | ||
|
|
||
| @Run(test = "testTwoCastToSameType") | ||
| public static void testTwoCastToSameType_runner() { | ||
| int count = testTwoCastToSameType(); | ||
| VectorMask<Integer> mInt128 = VectorMask.fromArray(IntVector.SPECIES_128, mr, 0); | ||
| Asserts.assertEquals(count, mInt128.trueCount()); | ||
| } | ||
|
|
||
| @Test | ||
| @IR(counts = { IRNode.VECTOR_MASK_CAST, "= 1" }, applyIfCPUFeatureOr = {"avx2", "true", "asimd", "true"}) | ||
| public static int testOneCastToDifferentType() { | ||
| // The types before and after the only cast are different, the cast will not be eliminated. | ||
| VectorMask<Float> mFloat128 = VectorMask.fromArray(FloatVector.SPECIES_128, mr, 0).not(); | ||
| VectorMask<Integer> mInt128 = mFloat128.cast(IntVector.SPECIES_128); | ||
| return mInt128.trueCount(); | ||
| } | ||
|
|
||
| @Run(test = "testOneCastToDifferentType") | ||
| public static void testOneCastToDifferentType_runner() { | ||
| int count = testOneCastToDifferentType(); | ||
| VectorMask<Float> mInt128 = VectorMask.fromArray(FloatVector.SPECIES_128, mr, 0).not(); | ||
| Asserts.assertEquals(count, mInt128.trueCount()); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| TestFramework testFramework = new TestFramework(); | ||
| testFramework.setDefaultWarmup(10000) | ||
| .addFlags("--add-modules=jdk.incubator.vector") | ||
| .start(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.