Bug 124869

Summary: Optimize away OR with zero - a common ASM.js pattern.
Product: WebKit Reporter: Nadav Rotem <nrotem>
Component: New BugsAssignee: Nadav Rotem <nrotem>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, fpizlo, ggaren
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

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 ?