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

C2: Delay Mod/Div by constant transformation

XMLWordPrintable

      C2 employs optimizations to replace ModI/L DivI/L by a row of shifts, additions, multiplications, and subtractions if the divisor is a constant that isn't a power of 2. This is great for performance, but prevents some other optimizations:

      - CmpUNode::sub() uses CmpUNode::is_index_range_check() to optimize ((X ModI Y) CmpU Y) patterns (for appropriate input ranges). As the ModI gets replaced too early, the range check is not eliminated if the size of an array is known to be constant.
      - After JDK-8356813, ModI will provide better type information. But as Value() is only called after Ideal() in GVN, we don't call ModINode::Value() if the node is replaced beforehand. The replacement provides less precise type information, also preventing other (range check) optimizations.

      Therefore I suggest delaying the transformation so other optimizations depending on finding a Mod node or on precise type information.

      I'm not sure what the best way is there, so I'll leave this for someone else.

            Unassigned Unassigned
            hgreule Hannes Greule
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: