Closed Bug 510926 Opened 15 years ago Closed 11 years ago

tableswitch for "case x.y" where y is the const property of const object x

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: igor, Unassigned)

References

Details

My very initial prototyping of the JS-based deciompiler from the bug 485949 exposed that the emitter does not optimizes as the tableswitch the switch with case expressions that represents the const properties of const objects. That is, the following case uses condswitch, not tableswitch, in the following case:

const x = ...;

switch (value) {
  case x.a: ...
  case x.b: ...
...
}

where a, b, ... are const properties of the const object x. It would be nice to optimize this case.
Is this really frequent enough in web code? Const is already rare. That particular dispatch is even rarer. Have we ever seen this in web code or chrome code?
Well, the condswitch here is just the symptom. The fix wouldn't need to be `switch`-specific. This is really about constant propagation.
Generic constant propagation is anything but trivial since it requires name analysis and dominance analysis. Both of which we have to some degree now. The dominance analysis is very cheesy. If we improve that we could probably capture a lot of cases.
(In reply to comment #1)
> Is this really frequent enough in web code? 

This is not for the web but rather to simplify JS-based decompiler. Right now I cannot do the switch with code like "case JSOP.NAME" since that case translates into condswitch doing the linear lookup. That does not work when there are almost 256 cases.
I understand the use in the decompiler, but I was trying to find out whether the added complexity is worth it. We could also just use JSOP_NAME instead. Brendan has a #preprocessor approach in the jsasm.
Comment 5 anticipates what I wrote in bug 485949 comment 14.

We can do SSA in one pass [1], but that is a lot of work, it will use more cycles and memory than the current def/use chaining, and I would not commission starting that work with only this bug as motivation.

/be

[1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.4503
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.