RVM
  1. RVM
  2. RVM-313

Optimize branch "x < 0 || x >= limit" into unsigned "x >= limit"

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 1000
    • Component/s: Compiler: Optimizing
    • Labels:
      None
    • Number of attachments :
      0

      Description

      In code such as java.nio.Buffer.checkIndex exceptions are thrown based on the condition "x < 0 || x >= limit" which could be more simply expressed as "x >= limit" where the >= test is unsigned. Added bonus on Intel is that unsigned compares get fused with their prior compare.

      Here's the simplified HIR:

      -13 LABEL0 Frequency: 1.0
      -2 EG ir_prologue l0psa(Ljava/nio/Buffer;,x,d), l2psi(I,d) =
      0 G yieldpoint_prologue
      1 int_ifcmp t3sv(GUARD) = l2psi(I,d), 0, <, LABEL2, Probability: 0.0
      -1 bbend BB0 (ENTRY)
      4 LABEL1 Frequency: 1.0
      1 getfield t8si(I) = l0psa(Ljava/nio/Buffer;,x,d), Addr 0x00000000, <mem loc: Ljava/nio/Buffer;.limit>, <TRUEGUARD>
      9 int_ifcmp t11sv(GUARD) = l2psi(I,d), t8si(I), <, LABEL3, Probability: 1.0
      -1 bbend BB1
      12 LABEL2 (Infrequent) Frequency: 0.0
      12 EG new t12sa(Ljava/lang/IndexOutOfBoundsException;,p) = java.lang.IndexOutOfBoundsException
      16 EG call AF CF OF PF SF ZF = Addr 0x0000f2c0, special_exact"< BootstrapCL, Ljava/lang/IndexOutOfBoundsException; >.<init> ()V", <TRUEGUARD>,
      t12sa(Ljava/lang/IndexOutOfBoundsException;,p)
      -10 G yieldpoint_epilogue
      19 EG athrow t12sa(Ljava/lang/IndexOutOfBoundsException;,p)
      -1 bbend BB2
      20 LABEL3 Frequency: 1.0
      -10 G yieldpoint_epilogue
      -3 return <unused>
      -1 bbend BB3

      there's no null check on the limit getfield as we know this must be extant. The >= test has been flipped to <.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Ian Rogers
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: