Open Bug 1116807 Opened 9 years ago Updated 1 year ago

IonMonkey: Form unsigned comparisons with array.length

Categories

(Core :: JavaScript Engine: JIT, enhancement, P5)

enhancement

Tracking

()

People

(Reporter: sunfish, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf, Whiteboard: [lang=c++])

This code, run with --ion-eager, could be optimized with an unsigned comparison:

function foo(a, i) {
  if ((i>>>0) < a.length) 
      return a[i];
  else
      return 3;
}

x=[34,54,56,65];
print(foo(x, 2));
print(foo(x, 1));
print(foo(x, 0));
print(foo(x, 4));

It's probably just a matter of teaching MustBeUInt32 that MArrayLength and MTypedArrayLength are unsigned.
Keywords: perf
For details about why MArrayLength and friends can be considered unsigned, see the comment in MArrayLength::computeRange. There are several other *Length operators there which could benefit from unsigned comparisons too.
Whiteboard: [lang=c++]
Blocks: jsperf
Priority: -- → P5
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.