Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8343067

C2: revisit constant-offset AddP chains after successful input idealizations

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 24
    • hotspot

      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)

        1. draft.patch
          0.8 kB
        2. TestAddPChain.java
          0.2 kB
        3. unoptimized-subgraph.pdf
          2 kB

            rcastanedalo Roberto Castaneda Lozano
            rcastanedalo Roberto Castaneda Lozano
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: