RFR: 8307513: C2: intrinsify Math.max(long,long) and Math.min(long,long) [v12]

Galder Zamarreño galder at openjdk.org
Thu Feb 20 10:56:58 UTC 2025


On Thu, 20 Feb 2025 06:50:07 GMT, Galder Zamarreño <galder at openjdk.org> wrote:

> There is something very intriguing happening here, which I don't know it's due to min itself or int vs long.


Benchmark                              (probability)  (size)   Mode  Cnt  -min/-max  +min/+max   Units
MinMaxVector.intReductionMultiplyMax             100    2048  thrpt    4    876.867    407.905  ops/ms (-53%)
MinMaxVector.intReductionMultiplyMin             100    2048  thrpt    4    407.963    407.956  ops/ms (1)
MinMaxVector.longReductionMultiplyMax            100    2048  thrpt    4    838.845    405.371  ops/ms (-51%)
MinMaxVector.longReductionMultiplyMin            100    2048  thrpt    4    825.602    414.757  ops/ms (-49%)
MinMaxVector.intReductionSimpleMax               100    2048  thrpt    4   1032.561    460.486  ops/ms (-55%)
MinMaxVector.intReductionSimpleMin               100    2048  thrpt    4    460.530    460.490  ops/ms (2)
MinMaxVector.longReductionSimpleMax              100    2048  thrpt    4   1017.560    460.436  ops/ms (-54%)
MinMaxVector.longReductionSimpleMin              100    2048  thrpt    4    959.507    459.197  ops/ms (-52%)


 (1) (2) It seems it's a combination of both int AND min reduction operations and disabling the intrinsic. The rest of reduction operations seems to use cmp+mov in that situation but not int+min, which uses cmov. Maybe this is intentional or maybe it's a bug, but it's interesting to notice.

`intReductionMultiplyMin` -min:

# VM options: -Djava.library.path=/home/vagrant/1/jdk-intrinsify-max-min-long/build/release-linux-x86_64/images/test/micro/native -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_min -XX:-UseSuperWord
# Benchmark: org.openjdk.bench.java.lang.MinMaxVector.intReductionMultiplyMin
# Parameters: (probability = 100, size = 2048)
...
   2.29%  │││    │   0x00007f4aa40f5835:   cmpl		%edi, %r10d
   4.25%  │││    │   0x00007f4aa40f5838:   cmovgl		%edi, %r10d         ;*ireturn {reexecute=0 rethrow=0 return_oop=0}
          │││    │                                                             ; - java.lang.Math::min at 10 (line 2119)
          │││    │                                                             ; - org.openjdk.bench.java.lang.MinMaxVector::intReductionMultiplyMin at 26 (line 202)
          │││    │                                                             ; - org.openjdk.bench.java.lang.jmh_generated.MinMaxVector_intReductionMultiplyMin_jmhTest::intReductionMultiplyMin_thrpt_jmhStub at 19 (line 124)


`intReductionMultiplyMin` +min:

# VM options: -Djava.library.path=/home/vagrant/1/jdk-intrinsify-max-min-long/build/release-linux-x86_64/images/test/micro/native -XX:-UseSuperWord
# Benchmark: org.openjdk.bench.java.lang.MinMaxVector.intReductionMultiplyMin
# Parameters: (probability = 100, size = 2048)
...
   2.06%  │││    │   0x00007ff8ec0f4c35:   cmpl		%edi, %r10d
   4.31%  │││    │   0x00007ff8ec0f4c38:   cmovgl		%edi, %r10d         ;*invokestatic min {reexecute=0 rethrow=0 return_oop=0}
          │││    │                                                             ; - org.openjdk.bench.java.lang.MinMaxVector::intReductionMultiplyMin at 26 (line 202)
          │││    │                                                             ; - org.openjdk.bench.java.lang.jmh_generated.MinMaxVector_intReductionMultiplyMin_jmhTest::intReductionMultiplyMin_thrpt_jmhStub at 19 (line 124)


`longReductionMultiplyMin` -min:

# VM options: -Djava.library.path=/home/vagrant/1/jdk-intrinsify-max-min-long/build/release-linux-x86_64/images/test/micro/native -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_minL -XX:-UseSuperWord
# Benchmark: org.openjdk.bench.java.lang.MinMaxVector.longReductionMultiplyMin
# Parameters: (probability = 100, size = 2048)
...
   0.01%  │            │   ││ │ ││  0x00007ff9d80f7609:   imulq		$0xb, 0x10(%r12, %r10, 8), %rbp
          │            │   ││ │ ││                                                            ;*lmul {reexecute=0 rethrow=0 return_oop=0}
          │            │   ││ │ ││                                                            ; - org.openjdk.bench.java.lang.MinMaxVector::longReductionMultiplyMin at 24 (line 265)
          │            │   ││ │ ││                                                            ; - org.openjdk.bench.java.lang.jmh_generated.MinMaxVector_longReductionMultiplyMin_jmhTest::longReductionMultiplyMin_thrpt_jmhStub at 19 (line 124)
          │            │   ││ │ ││  0x00007ff9d80f760f:   testq		%rbp, %rbp
          │            │   ││╭│ ││  0x00007ff9d80f7612:   jge		0x7ff9d80f7646      ;*lreturn {reexecute=0 rethrow=0 return_oop=0}
          │            │   ││││ ││                                                            ; - java.lang.Math::min at 11 (line 2134)
          │            │   ││││ ││                                                            ; - org.openjdk.bench.java.lang.MinMaxVector::longReductionMultiplyMin at 30 (line 266)
          │            │   ││││ ││                                                            ; - org.openjdk.bench.java.lang.jmh_generated.MinMaxVector_longReductionMultiplyMin_jmhTest::longReductionMultiplyMin_thrpt_jmhStub at 19 (line 124)


`longReductionMultiplyMin` +min:

# VM options: -Djava.library.path=/home/vagrant/1/jdk-intrinsify-max-min-long/build/release-linux-x86_64/images/test/micro/native -XX:-UseSuperWord
# Benchmark: org.openjdk.bench.java.lang.MinMaxVector.longReductionMultiplyMin
# Parameters: (probability = 100, size = 2048)
...
   0.01%  │   ││  0x00007f83400f7d76:   cmpq		%r13, %rdx
   0.12%  │   ││  0x00007f83400f7d79:   cmovlq		%rdx, %r13          ;*invokestatic min {reexecute=0 rethrow=0 return_oop=0}
          │   ││                                                            ; - org.openjdk.bench.java.lang.MinMaxVector::longReductionMultiplyMin at 30 (line 266)
          │   ││                                                            ; - org.openjdk.bench.java.lang.jmh_generated.MinMaxVector_longReductionMultiplyMin_jmhTest::longReductionMultiplyMin_thrpt_jmhStub at 19 (line 124)

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

PR Comment: https://git.openjdk.org/jdk/pull/20098#issuecomment-2671144644


More information about the core-libs-dev mailing list