RFR: 8266480: Implicit null check optimization does not update control of hoisted memory operation
Tobias Hartmann
thartmann at openjdk.java.net
Tue May 18 14:26:03 UTC 2021
C2 replaces explicit null checks by hoisting a nearby memory operation to the null check and using it as implicit null check. In some cases, control of that memory operation is not updated correctly, leading to assert failures during `PhaseCFG::verify()` because a use is no longer dominated by its definition.
After matching, the graph looks like this:
<img src="https://user-images.githubusercontent.com/5312595/118652773-346fc280-b7e7-11eb-828a-eddb72b81d6e.png" width=50% height=50%>
`64 testP_reg` is an explicit null check and `78 loadD`, `73 storeD` and `77 storeImmI` are candidates for an implicit null check because they are operating on the same oop. `PhaseCFG::implicit_null_check` decides to hoist the `77 storeImmI` from the `not_null_block` B12 to the null check in B11/B13:
<img src="https://user-images.githubusercontent.com/5312595/118652778-36d21c80-b7e7-11eb-88d0-1c2c117a9450.png" width=50% height=50%>
Now the problem is that control of `77 storeImmI` was not updated and still points into the non-dominating block B15. The following code is supposed to fix this:
https://github.com/openjdk/jdk/blob/9d168e25d1e2e8b662dc7aa6cda7516c423cef7d/src/hotspot/share/opto/lcm.cpp#L413-L418
However, it does not trigger because control is not the `not_null_block->head()` but `59 MachProj` which is the control projection from `60 CallLeafDirect` emitted by a `drem`. The fix is to simply check `get_block_for_node(ctrl)` instead.
This is an old issue that was only caught by the assert recently introduced by [JDK-8263227](https://bugs.openjdk.java.net/browse/JDK-8263227).
Thanks,
Tobias
-------------
Commit messages:
- 8266480: Implicit null check optimization does not update control of hoisted memory operation
Changes: https://git.openjdk.java.net/jdk/pull/4093/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=4093&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8266480
Stats: 64 lines in 2 files changed: 63 ins; 0 del; 1 mod
Patch: https://git.openjdk.java.net/jdk/pull/4093.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/4093/head:pull/4093
PR: https://git.openjdk.java.net/jdk/pull/4093
More information about the hotspot-compiler-dev
mailing list