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




JavaScript Engine
8 years ago
5 years ago


(Reporter: Igor Bukanov, Unassigned)


Firefox Tracking Flags

(Not tracked)




8 years ago
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.

Comment 1

8 years ago
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.

Comment 3

8 years ago
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.

Comment 4

8 years ago
(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.

Comment 5

8 years ago
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.




5 years ago
Last Resolved: 5 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.