Closed Bug 465286 Opened 16 years ago Closed 15 years ago

TM: we don't constant fold math on doubles and ints

Categories

(Core :: JavaScript Engine, enhancement)

x86
macOS
enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: gal, Assigned: gal)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

      No description provided.
Attached patch patchSplinter Review
Assignee: general → gal
Attachment #348524 - Flags: review?(edwsmith)
This patch turns the if cascades into switch statements and adds folding for floating point math. Not very controversial. 

It also adds constant folding for integer math add/sub/mul, but only if no overflow occurs. This might be seen as controversial. Nanojit is supposed to be language agnostic. Other languages might have different overflow semantics. HOWEVER, we don't fold if its overflows. So worst case if you want to compile C via nanojit, you have to fold yourself upstream if it does overflow and thats safe in your language. So I would say this is fair game.

Ed?
IMHO a separate "folding without overflow" filter higher up in the pipeline would be better, so other projects could exclude it or use their own.

Though arguably TraceMonkey should be manually folding these so it can fold the overflow cases and eliminate the LIR_i2f like the add/sub patch does.
Its safe to fold this stuff in NJ. Its safe for JS but also for other languages like C. Its just not complete for C.
Comment on attachment 348524 [details] [diff] [review]
patch

I agree that not folding +, -, * if overflow occurs, is fine and safe for now.  (R+).

The abstract problem with NJ here is that overflow and other condition codes are not modelled precicely by LIR.  the "result" of + - * is not just 32 value bits, but also one overflow bit, on zero bit, etc.  If LIR could expression the def/use relationship of these additional bits, then it would be a simple matter of constant folding also creating constant OV, Z, etc bits to with the constant value.  

If we could model condition codes in a lightweight way, it would also help on PPC and ARM where each instruction has a choice of setting the CC's or not (based on whether the CC is needed).
Attachment #348524 - Flags: review?(edwsmith) → review+
What is the point of constant folding in the JIT, given that js bytecode has already undergone constant folding?
The jit sees a lot more opportunity on a trace than bytecode since we pin down the control flow.

a = 1;
if (b) {
  a++;
}

If we trace through that, a is constant 2.
Severity: normal → enhancement
http://hg.mozilla.org/tracemonkey/rev/311825fa36ae
Whiteboard: fixed-in-tracemonkey
http://hg.mozilla.org/mozilla-central/rev/311825fa36ae
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: