A successful idealization of the offset input of an AddP node n might replace n->in(AddPNode::Offset) with a constant, potentially enabling further optimization by AddPNode::Ideal() if n is used by another AddP node m with a constant offset. To enable this within an IGVN run, this pattern should be detected and m pushed into the IGVN worklist in PhaseIterGVN::add_users_of_use_to_worklist().
The attached TestAddPChain.java file (extracted from a mainline test case) illustrates the missing optimization. When running it with:
java -Xcomp -XX:CompileOnly=TestAddPChain::test TestAddPChain.java
we get subgraphs like StoreL(AddP(AddP(ConL), ConL)) (see unoptimized-subgraph.pdf), which in x64 requires materializing one of the constants in a register:
movl $0x4, %r9d
...
movq %rcx, 0x14(%rsi,%r9)
If the pattern is detected and the lowest AddP node is added to IGVN's working list (see draft patch attached), after AddPNode::Ideal() we get the expected StoreL(AddP(ConL)) subgraph, which in x64 can be implemented as part of the store's address computation:
movq %r8, 0x18(%rbx)
The attached TestAddPChain.java file (extracted from a mainline test case) illustrates the missing optimization. When running it with:
java -Xcomp -XX:CompileOnly=TestAddPChain::test TestAddPChain.java
we get subgraphs like StoreL(AddP(AddP(ConL), ConL)) (see unoptimized-subgraph.pdf), which in x64 requires materializing one of the constants in a register:
movl $0x4, %r9d
...
movq %rcx, 0x14(%rsi,%r9)
If the pattern is detected and the lowest AddP node is added to IGVN's working list (see draft patch attached), after AddPNode::Ideal() we get the expected StoreL(AddP(ConL)) subgraph, which in x64 can be implemented as part of the store's address computation:
movq %r8, 0x18(%rbx)
- relates to
-
JDK-8339303 C2: dead node after failing to match cloned address expression
- In Progress
-
JDK-8298951 Umbrella: improve CCP and IGVN verification
- Open