Bug 124869 - Optimize away OR with zero - a common ASM.js pattern.
Summary: Optimize away OR with zero - a common ASM.js pattern.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nadav Rotem
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-25 16:17 PST by Nadav Rotem
Modified: 2013-11-26 15:40 PST (History)
3 users (show)

See Also:


Attachments
Patch (1.37 KB, patch)
2013-11-25 16:17 PST, Nadav Rotem
no flags Details | Formatted Diff | Diff
Patch (1.37 KB, patch)
2013-11-25 16:20 PST, Nadav Rotem
no flags Details | Formatted Diff | Diff
Patch (1.84 KB, patch)
2013-11-25 22:58 PST, Nadav Rotem
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nadav Rotem 2013-11-25 16:17:38 PST
Optimize away OR with zero - a common ASM.js pattern.
Comment 1 Nadav Rotem 2013-11-25 16:17:55 PST
Created attachment 217843 [details]
Patch
Comment 2 Nadav Rotem 2013-11-25 16:20:03 PST
Created attachment 217844 [details]
Patch
Comment 3 Filip Pizlo 2013-11-25 16:56:01 PST
Comment on attachment 217844 [details]
Patch

This feels somewhat suboptimal - ideally we would allow for copy-propagation of y = (x|0), which this doesn't do.  I recommend doing this in the FixupPhase instead.  The way that you would do it is replace BitOr(x, 0) with Identity(x) ; Phantom(0).  The Phantom(0) is relevant because want to know that the constant zero was live up to that point.
Comment 4 Nadav Rotem 2013-11-25 20:17:53 PST
I also thought that it would be a good idea to peephole it earlier.   Should we also keep this one?
Comment 5 Filip Pizlo 2013-11-25 20:36:19 PST
(In reply to comment #4)
> I also thought that it would be a good idea to peephole it earlier.   Should we also keep this one?

Nah - in fact what I would do is have:

- An earlier peephole in FixupPhase.

- A "later" peephole in MacroAssemblerBlah.h, where Blah = x86_64 | ARMv7 | ARM64.  This would help the other JITs - including our regex JIT. ;-)
Comment 6 Nadav Rotem 2013-11-25 22:58:33 PST
Created attachment 217864 [details]
Patch
Comment 7 WebKit Commit Bot 2013-11-26 09:07:26 PST
Comment on attachment 217864 [details]
Patch

Clearing flags on attachment: 217864

Committed r159783: <http://trac.webkit.org/changeset/159783>
Comment 8 WebKit Commit Bot 2013-11-26 09:07:28 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Nadav Rotem 2013-11-26 15:40:44 PST
Filip, can we do this:

 void add32(TrustedImm32 imm, RegisterID dest)
 {   
         if (imm.m_value)                   <---------- this
             add32(imm, dest, dest);
 }


someone may be calling add32 just to use the flags.  When is it safe to optimize code in the emitter ?