- 
                Notifications
    
You must be signed in to change notification settings  - Fork 6.1k
 
8341781: Improve Min/Max node identities #21439
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
Conversation
| 
          
 👋 Welcome back jkarthikeyan! A progress list of the required criteria for merging this PR into   | 
    
| 
           @jaskarth 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: 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 733 new commits pushed to the  
 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   | 
    
          
Webrevs
  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments, otherwise, looks good to me.
        
          
                test/hotspot/jtreg/compiler/c2/irTests/TestMinMaxIdentities.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | 
           Your new test fails on Linux with  Looks like we do not emit  jdk/src/hotspot/cpu/x86/x86.ad Lines 1542 to 1549 in 1604255 
 You can probably just update your tests to exclude IR matching for this setup. Maybe you also want to double check the other architectures.  | 
    
| 
           Thanks for the suggestions and testing, @liach and @chhagedorn! I've taken a look at the backend implementations, and it seems that aarch64 and RISC-V unconditionally support floating point Min/Max while x64 only supports them with   | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for the update! I'll give this another spinning in our testing.
| 
           Testing passed!  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive-by comments. Generally looks reasonable, nice work.
I have 2 comments below.
| 
               | 
          ||
| Node* MaxINode::Identity(PhaseGVN* phase) { | ||
| const TypeInt* t1 = phase->type(in(1))->is_int(); | ||
| const TypeInt* t2 = phase->type(in(2))->is_int(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could any input be TOP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can't encounter TOP here because we run Value() before Identity(), so if TOP is returned by Value() the idealization process exits to return the top node before running Identity().
| * @bug 8341781 | ||
| * @summary Test identities of MinNodes and MaxNodes. | ||
| * @key randomness | ||
| * @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx.*") | os.arch == "aarch64" | os.arch == "riscv64" | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a chance we can add these requires to the @IR rules instead? That way we can still do the result verification on all other platforms, which could be valuable on its own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding this isn't possible as-is since CPU features seem to be checked regardless of whether the architecture supports it or not, so we can't simply check for AVX because that would fail on aarch64 and riscv64. I think we could work around this with applyIfCPUFeatureOr = {"avx", "true", "asimd", "true", "rvv", "true"} to force a check for all 3 platforms but it'd be filtering more platforms than strictly necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which platforms would be filtered "more platforms than strictly necessary"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the workaround to check for CPU features on all 3 platforms, we'd be not checking the IR when asimd = false or rvv = false, but the IR check should pass with those features too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your tags are actually available, with applyIfPlatform. Look at irTestingPlatforms in https://github.com/openjdk/jdk/blame/master/test/hotspot/jtreg/compiler/lib/ir_framework/test/IREncodingPrinter.java#L69
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of these is quite rare - usually we focus more on the CPU features, and not the platform tags ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was meaning that with applyIfPlatformOr = {"x64", "true", "aarch64", "true", "riscv64", "true"} we would still need at least applyIfCPUFeature = {"avx", true"} because on x86 we only make Min/MaxF and Min/MaxD with AVX. But that applyIfCPUFeature will check for AVX on aarch64 and riscv64 as well, but will fail because it's not available for those platforms. That's why I suggested the workaround of checking the other CPU features, to make the test at least run on the other platforms. It'd be nice to be able to express platform and CPU feature combinations like with @requires, but the use-case here is pretty niche.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First: yes, I'm fine with just using CPU features - it will IR test it on fewer platforms than maybe desired, but that is ok, I think.
I guess the issue with @IR is that it only allows AND or OR clauses ... and not the more complicated mix of & and | from @requires. But in theory, you can just have multiple @IR rules (that simulates the OR):
- One for 
x64(applyIfPlatform) andavx(applyIfCPUFeature) - One IR rule for each of: 
aarch64andriscv64(applyIfPlatform) 
But again, I'm ok with only checking for CPU features... it is more simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chhagedorn you may be interested in this conversation as well ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't considered using multiple IR checks, that would definitely work as well. I've pushed a commit that just uses the CPU features, to keep it simple. Let me know what you think!
| // As JDK-8307513 adds intrinsics for the methods, the Long tests are disabled until then. | ||
| 
               | 
          ||
| @Test | ||
| // @IR(applyIfPlatform = { "riscv64", "false" }, phase = { CompilePhase.BEFORE_MACRO_EXPANSION }, counts = { IRNode.MIN_L, "1" }) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say you should make them negative for now, i.e. make them failOn. Otherwise we won't catch these cases when JDK-8307513 gets integrated ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I've pushed a commit that makes the tests pass now but fail when 8307513 is integrated.
| 
           The IR rules look ok to me. Nice progress :)  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IR rule updates look good. Maybe you want to wait with integrating this until after the fork next Thursday. So, this only goes into JDK 25.
| 
           Thanks for the re-review! I think that's a good idea, I'll integrate it after JDK 24 is forked.  | 
    
| 
           Since it's after the fork, I'll integrate it now. Thanks again for the reviews everyone!  | 
    
| 
          
 Going to push as commit 29d648c. 
 Your commit was automatically rebased without conflicts.  | 
    
Hi all,
This patch implements some missing identities for Min/Max nodes. It adds static type-based operand choosing for MinI/MaxI, such as the ones that MinL/MaxL use. In addition, it adds simplification for patterns such as
Max(A, Max(A, B))toMax(A, B)andMax(A, Min(A, B))toA. These simplifications stem from the lattice identity rules. The main place I've seen this pattern is with MinL/MaxL nodes created during loop optimizations. Some examples of where this occurs include BigInteger addition/subtraction, and regex code. I've run some of the existing benchmarks and found some nice improvements:I've added some IR tests, and tier 1 testing passes on my linux machine. Reviews would be appreciated!
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21439/head:pull/21439$ git checkout pull/21439Update a local copy of the PR:
$ git checkout pull/21439$ git pull https://git.openjdk.org/jdk.git pull/21439/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21439View PR using the GUI difftool:
$ git pr show -t 21439Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21439.diff
Using Webrev
Link to Webrev Comment