RFR: 8324655: Identify integer minimum and maximum patterns created with if statements [v3]

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Wed Mar 20 02:10:31 UTC 2024


On Tue, 5 Mar 2024 11:14:51 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>>> You mean you would be matching for a `Cmp -> CMove` node pattern that is equivalent for `Min/Max`, rather than matching a `Cmp -> If -> Phi` pattern?
>> 
>> Yeah, I was thinking it might be better to let the CMove transform happen first, since the conditions guarding both transforms are aiming to do the same thing in essence. My thought was that if the regression in your `testCostDifference` was fixed, it would be better to not have to do that fix in two different locations, since it impacts `is_minmax` as well.
>> 
>>> BTW, I watched a fascinating talk about branch-predictors / branchless code yesterday
>> 
>> Thank you for linking this talk, it was really insightful! I also wonder if it would be possible to capture branch execution patterns somehow, to drive branch flattening optimizations. I figure it could be possible to keep track of the sequence of a branch's history of execution, and then compute some "entropy" value from that sequence to determine if there's a pattern, or if it's random and likely to be mispredicted. However, implementing that in practice sounds pretty difficult.
>> 
>> @eme64 I've pushed a commit that fixes the benchmarks and sets the loop iteration count to 10_000. Could you check if this lets it vectorize on your machine? Thanks!
>
> @jaskarth Why don't you first make the code change with starting from a `Cmp -> CMove` pattern rather than the `Cmp -> If -> Phi` pattern. Then I can look at both things together ;)

Thank you for the re-review @eme64! I've pushed a commit that should address your comments. I've also added an IR test that verifies that min/max vectorization and reduction is taking place, as requested.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/17574#issuecomment-2008563833


More information about the hotspot-compiler-dev mailing list