MemBarAcquire does not get removed because Precedent input gets folded to a constant

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • tbd
    • Affects Version/s: 26
    • Component/s: hotspot

      While investigating JDK-8367627 (valhalla issue), I noticed that in some cases we miss out on optimizing MemBar nodes. In the attached reproducer, we have a volatile load that results in a MemBarAcquire with a LoadL node has its Precedent input. The LoadL node gets folded to a constant at the very first IGVN pass, and this prevents the MemBar node from being removed, as MemBarNode::Ideal relies on having a memory node as Precedent input to replace its projections by its inputs.

      By artificially delaying the optimization on the LoadL node we can force the MemBar node to eventually get removed, which shows that it is most likely correct to do so.

      This can be reproduced as follows:
      java -Xcomp -XX:-TieredCompilation -Xbatch -XX:CompileCommand=compileonly,*Test::test Test.java

        1. Test.java
          0.3 kB
          Benoît Maillard
        2. Screenshot from 2025-11-06 10-38-04.png
          88 kB
          Benoît Maillard

            Assignee:
            Benoît Maillard
            Reporter:
            Benoît Maillard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: