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

Optimize double negation elimination

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 17
    • Fix Version/s: 17
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b16
    • CPU:
      generic
    • OS:
      generic

      Description

      public static int neg(int i) {
             return -(-i);
      }

      For this simple test case above, c2 could reduce the redundant 'sub' through SubNode::Ideal. But every time when 'sub' be removed, there would generate two useless nodes.

      The Ideal first transform '0-(0-i)' into 'i - 0', which generated a new SubNode[1]. Then the generated 'i-0' continues to be replaced with 'i+(-0)', a new generated AddNode[2].

       

      Those generated and useless nodes would be removed by later phases, but perhaps it's better to optimize 0-(0-i) to i itself, without new node was generated. 

      There already have code to remove double negation[3], but never been used since they have been transformed to others in Ideal(), which happens before Identity.

      [1] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L238
      [2] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L181
      [3] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L55

       
       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              eliu Eric Liu
              Reporter:
              eliu Eric Liu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: