RFR: 8278114: New addnode ideal optimization: converting "x + x" into "x << 1" [v6]
Zhiqiang Zang
duke at openjdk.java.net
Sat Dec 18 18:19:25 UTC 2021
On Sat, 18 Dec 2021 12:14:06 GMT, Quan Anh Mai <duke at openjdk.java.net> wrote:
> Alternatively, you could use `-XX:CompileCommand=print,*AddIdeal_XPlusX_LShiftC.testInt` which will print every detail about compilation including opto assembly. In this case, you could use `-XX:-TieredCompilation` to not receive details regarding C1 compiled method. Note that without `hsdis` the JVM will only output machine code which is very hard to analyse.
It seems `make install-hsdis` does not install `hsdis` into the correct place. In my case, I have to manually copy it from `build/cov/jdk/lib` to the right place which is `build/cov/images/jdk/lib/server` so it can work. I don't know if this is some bug in makefile.
This is the output what I got, given `@Fork(value = 1, jvmArgsAppend = {"-XX:-TieredCompilation", "-XX:CompileCommand=print,*AddIdeal_XPlusX_LShiftC.helper"})`. I have two questions:
- The assmbly looks weird to me because I did not see any shift instruction?
- Why did it print at and **only** at the first warmup iteration? I did not expect c2 compilation to happen so early.
Thanks in advance.
Running test 'micro:AddIdeal_XPlusX_LShiftC'
# JMH version: 1.33
# VM version: JDK 19-internal, OpenJDK 64-Bit Server VM, 19-internal+0-adhoc..my-jdk
# VM invoker: /home/zzq/jog/testing/my-jdk/build/cov/images/jdk/bin/java
# VM options: -Djava.library.path=/home/zzq/jog/testing/my-jdk/build/cov/images/test/micro/native -XX:-TieredCompilation -XX:CompileCommand=print,*AddIdeal_XPlusX_LShiftC.helper
# Blackhole mode: full + dont-inline hint (default, use -Djmh.blackhole.autoDetect=true to auto-detect)
# Warmup: 20 iterations, 1 s each
# Measurement: 20 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC.testInt
# Run progress: 0.00% complete, ETA 00:00:40
# Fork: 1 of 1
CompileCommand: print *AddIdeal_XPlusX_LShiftC.helper bool print = true
# Warmup Iteration 1:
============================= C2-compiled nmethod ==============================
----------------------- MetaData before Compile_id = 188 ------------------------
{method}
- this oop: 0x00007f977c476548
- method holder: 'org/openjdk/bench/vm/compiler/AddIdeal_XPlusX_LShiftC'
- constants: 0x00007f977c475f18 constant pool [76] {0x00007f977c475f18} for 'org/openjdk/bench/vm/compiler/AddIdeal_XPlusX_LShiftC' cache=0x00007f977c4ab6e0
- access: 0x8100000a private static
- name: 'helper'
- signature: '(I)I'
- max stack: 3
- max locals: 1
- size of params: 1
- method size: 13
- vtable index: -2
- i2i entry: 0x00007f97b92f9c00
- adapters: AHE at 0x00007f97c41125b0: 0xa i2c: 0x00007f97b9406660 c2i: 0x00007f97b9406719 c2iUV: 0x00007f97b94066e3 c2iNCI: 0x00007f97b9406756
- compiled entry 0x00007f97b9406719
- code size: 10
- code start: 0x00007f977c476520
- code end (excl): 0x00007f977c47652a
- method data: 0x00007f977c4b4418
- checked ex length: 0
- linenumber start: 0x00007f977c47652a
- localvar length: 1
- localvar start: 0x00007f977c476532
------------------------ OptoAssembly for Compile_id = 188 -----------------------
#
# int ( int )
#
#r018 rsi : parm 0: int
# -- Old rsp -- Framesize: 32 --
#r591 rsp+28: in_preserve
#r590 rsp+24: return address
#r589 rsp+20: in_preserve
#r588 rsp+16: saved fp register
#r587 rsp+12: pad2, stack alignment
#r586 rsp+ 8: pad2, stack alignment
#r585 rsp+ 4: Fixed slot 1
#r584 rsp+ 0: Fixed slot 0
#
000 N1: # out( B1 ) <- in( B1 ) Freq: 1
000 B1: # out( N1 ) <- BLOCK HEAD IS JUNK Freq: 1
000 # stack bang (96 bytes)
pushq rbp # Save rbp
subq rsp, #16 # Create frame
00c movl RAX, RSI # spill
00e andl RAX, #2097151 # int
014 addq rsp, 16 # Destroy frame
popq rbp
cmpq rsp, poll_offset[r15_thread]
ja #safepoint_stub # Safepoint: poll for GC
026 ret
--------------------------------------------------------------------------------
----------------------------------- Assembly -----------------------------------
Compiled method (c2) 1974 188 org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper (10 bytes)
total in heap [0x00007f97b9418c10,0x00007f97b9418e60] = 592
relocation [0x00007f97b9418d80,0x00007f97b9418d90] = 16
main code [0x00007f97b9418da0,0x00007f97b9418de0] = 64
stub code [0x00007f97b9418de0,0x00007f97b9418df8] = 24
oops [0x00007f97b9418df8,0x00007f97b9418e00] = 8
metadata [0x00007f97b9418e00,0x00007f97b9418e08] = 8
scopes data [0x00007f97b9418e08,0x00007f97b9418e18] = 16
scopes pcs [0x00007f97b9418e18,0x00007f97b9418e58] = 64
dependencies [0x00007f97b9418e58,0x00007f97b9418e60] = 8
[Disassembly]
--------------------------------------------------------------------------------
[Constant Pool (empty)]
--------------------------------------------------------------------------------
[Verified Entry Point]
# {method} {0x00007f977c476548} 'helper' '(I)I' in 'org/openjdk/bench/vm/compiler/AddIdeal_XPlusX_LShiftC'
# parm0: rsi = int
# [sp+0x20] (sp of caller)
;; N1: # out( B1 ) <- in( B1 ) Freq: 1
;; B1: # out( N1 ) <- BLOCK HEAD IS JUNK Freq: 1
0x00007f97b9418da0: mov %eax,-0x16000(%rsp)
0x00007f97b9418da7: push %rbp
0x00007f97b9418da8: sub $0x10,%rsp ;*synchronization entry
; - org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper at -1 (line 98)
0x00007f97b9418dac: mov %esi,%eax
0x00007f97b9418dae: and $0x1fffff,%eax ;*iushr {reexecute=0 rethrow=0 return_oop=0}
; - org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper at 8 (line 98)
0x00007f97b9418db4: add $0x10,%rsp
0x00007f97b9418db8: pop %rbp
0x00007f97b9418db9: cmp 0x388(%r15),%rsp ; {poll_return}
0x00007f97b9418dc0: ja 0x00007f97b9418dc7
0x00007f97b9418dc6: ret
0x00007f97b9418dc7: movabs $0x7f97b9418db9,%r10 ; {internal_word}
0x00007f97b9418dd1: mov %r10,0x3a0(%r15)
0x00007f97b9418dd8: jmp 0x00007f97b9408120 ; {runtime_call SafepointBlob}
0x00007f97b9418ddd: hlt
0x00007f97b9418dde: hlt
0x00007f97b9418ddf: hlt
[Exception Handler]
0x00007f97b9418de0: jmp 0x00007f97b936a6a0 ; {no_reloc}
[Deopt Handler Code]
0x00007f97b9418de5: call 0x00007f97b9418dea
0x00007f97b9418dea: subq $0x5,(%rsp)
0x00007f97b9418def: jmp 0x00007f97b9407240 ; {runtime_call DeoptimizationBlob}
0x00007f97b9418df4: hlt
0x00007f97b9418df5: hlt
0x00007f97b9418df6: hlt
0x00007f97b9418df7: hlt
--------------------------------------------------------------------------------
[/Disassembly]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Oops:
0x00007f97b9418df8: 0x00000007ff755d38 a 'jdk/internal/loader/ClassLoaders$AppClassLoader'{0x00000007ff755d38}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Metadata:
0x00007f97b9418e00: 0x00007f977c476548 {method} {0x00007f977c476548} 'helper' '(I)I' in 'org/openjdk/bench/vm/compiler/AddIdeal_XPlusX_LShiftC'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pc-bytecode offsets:
PcDesc(pc=0x00007f97b9418d9f offset=ffffffff bits=0):
PcDesc(pc=0x00007f97b9418dac offset=c bits=0):
org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper at -1 (line 98)
PcDesc(pc=0x00007f97b9418db4 offset=14 bits=0):
org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper at 8 (line 98)
PcDesc(pc=0x00007f97b9418df9 offset=59 bits=0):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
oop maps:ImmutableOopMapSet contains 0 OopMaps
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
scopes:
ScopeDesc(pc=0x00007f97b9418dac offset=c):
org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper at -1 (line 98)
ScopeDesc(pc=0x00007f97b9418db4 offset=14):
org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper at 8 (line 98)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
relocations:
@0x00007f97b9418d80: b019
relocInfo at 0x00007f97b9418d80 [type=11(poll_return) addr=0x00007f97b9418db9 offset=25]
@0x00007f97b9418d82: f00e800e
relocInfo at 0x00007f97b9418d84 [type=8(internal_word) addr=0x00007f97b9418dc7 offset=14 data=14] | [target=0x00007f97b9418db9]
@0x00007f97b9418d86: 6411
relocInfo at 0x00007f97b9418d86 [type=6(runtime_call) addr=0x00007f97b9418dd8 offset=17 format=1] | [destination=0x00007f97b9408120]
@0x00007f97b9418d88: 0008
relocInfo at 0x00007f97b9418d88 [type=0(none) addr=0x00007f97b9418de0 offset=8]
@0x00007f97b9418d8a: 6400
relocInfo at 0x00007f97b9418d8a [type=6(runtime_call) addr=0x00007f97b9418de0 offset=0 format=1] | [destination=0x00007f97b936a6a0]
@0x00007f97b9418d8c: 640f
relocInfo at 0x00007f97b9418d8c [type=6(runtime_call) addr=0x00007f97b9418def offset=15 format=1] | [destination=0x00007f97b9407240]
@0x00007f97b9418d8e: 0000
relocInfo at 0x00007f97b9418d8e [type=0(none) addr=0x00007f97b9418def offset=0]
@0x00007f97b9418d90:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dependencies:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExceptionHandlerTable (size = 0 bytes)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ImplicitExceptionTable is empty
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Recorded oops:
#0: 0x0000000000000000 NULL-oop
#1: 0x00000007ff755d38 a 'jdk/internal/loader/ClassLoaders$AppClassLoader'{0x00000007ff755d38}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Recorded metadata:
#0: 0x0000000000000000 NULL-oop
#1: 0x00007f977c476548 {method} {0x00007f977c476548} 'helper' '(I)I' in 'org/openjdk/bench/vm/compiler/AddIdeal_XPlusX_LShiftC'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3.711 ns/op
# Warmup Iteration 2: 3.515 ns/op
# Warmup Iteration 3: 3.313 ns/op
# Warmup Iteration 4: 3.433 ns/op
# Warmup Iteration 5: 3.526 ns/op
# Warmup Iteration 6: 3.458 ns/op
# Warmup Iteration 7: 3.446 ns/op
# Warmup Iteration 8: 3.497 ns/op
# Warmup Iteration 9: 3.471 ns/op
# Warmup Iteration 10: 3.461 ns/op
# Warmup Iteration 11: 3.429 ns/op
# Warmup Iteration 12: 3.533 ns/op
# Warmup Iteration 13: 3.545 ns/op
# Warmup Iteration 14: 3.613 ns/op
# Warmup Iteration 15: 3.534 ns/op
# Warmup Iteration 16: 3.495 ns/op
# Warmup Iteration 17: 3.567 ns/op
# Warmup Iteration 18: 3.466 ns/op
# Warmup Iteration 19: 3.310 ns/op
# Warmup Iteration 20: 3.305 ns/op
Iteration 1: 3.285 ns/op
Iteration 2: 3.368 ns/op
Iteration 3: 3.315 ns/op
Iteration 4: 3.304 ns/op
Iteration 5: 3.359 ns/op
Iteration 6: 3.340 ns/op
Iteration 7: 3.330 ns/op
Iteration 8: 3.331 ns/op
Iteration 9: 3.447 ns/op
Iteration 10: 3.370 ns/op
Iteration 11: 3.389 ns/op
Iteration 12: 3.342 ns/op
Iteration 13: 3.332 ns/op
Iteration 14: 3.349 ns/op
Iteration 15: 3.344 ns/op
Iteration 16: 3.330 ns/op
Iteration 17: 3.327 ns/op
Iteration 18: 3.419 ns/op
Iteration 19: 3.341 ns/op
Iteration 20: 3.346 ns/op
------------------------------------------------------------------------
static org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC::helper(I)I
interpreter_invocation_count: 93898
invocation_counter: 93898
backedge_counter: 0
decompile_count: 0
mdo size: 392 bytes
0 iload_0
1 iload_0
2 iadd
3 bipush 10
5 ishl
6 bipush 11
8 iushr
9 ireturn
------------------------------------------------------------------------
Total MDO size: 392 bytes
Result "org.openjdk.bench.vm.compiler.AddIdeal_XPlusX_LShiftC.testInt":
3.348 ±(99.9%) 0.032 ns/op [Average]
(min, avg, max) = (3.285, 3.348, 3.447), stdev = 0.037
CI (99.9%): [3.316, 3.381] (assumes normal distribution)
# Run complete. Total time: 00:00:42
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
AddIdeal_XPlusX_LShiftC.testInt avgt 20 3.348 ± 0.032 ns/op
Finished running test 'micro:AddIdeal_XPlusX_LShiftC'
-------------
PR: https://git.openjdk.java.net/jdk/pull/6675
More information about the hotspot-compiler-dev
mailing list