Bug 196371

Summary: B3 should reduce (integer) Sub(Neg(x), y) to Neg(Add(x, y))
Product: WebKit Reporter: Robin Morisset <rmorisset>
Component: JavaScriptCoreAssignee: Justin Michaud <justin_michaud>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ews-watchlist, justin_michaud, keith_miller, mark.lam, msaboff, saam, tzagallo, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=199203
Bug Depends on:    
Bug Blocks: 196361    
Attachments:
Description Flags
Patch none

Description Robin Morisset 2019-03-28 12:46:08 PDT
It does not reduce the number of operation, but is a useful canonicalization in a few ways:
- improves the chance for CSE to work
- floating the Neg outwards maximizes the chance it will get eliminated
- it is generally easier to optimize Add (which is associative on integers) than Sub.
Comment 1 Robin Morisset 2019-06-27 11:22:18 PDT
Other similar reduction rules that would be useful (look at https://bugs.webkit.org/show_bug.cgi?id=199203 for an example where rules 1 and 3 would allow a lot of simplifications):
Sub(Sub(a, b), c) => Sub(a, Add(b, c))
Sub(a, Sub(b, c)) => Sub(Add(a, c), b)
Sub(Add(a, b), c) => Add(a, Sub(b, c))
Comment 2 Justin Michaud 2019-07-11 20:11:57 PDT
Created attachment 373995 [details]
Patch
Comment 3 Keith Miller 2019-07-11 20:19:20 PDT
Comment on attachment 373995 [details]
Patch

r=me.
Comment 4 WebKit Commit Bot 2019-07-12 10:11:37 PDT
Comment on attachment 373995 [details]
Patch

Clearing flags on attachment: 373995

Committed r247390: <https://trac.webkit.org/changeset/247390>
Comment 5 WebKit Commit Bot 2019-07-12 10:11:38 PDT
All reviewed patches have been landed.  Closing bug.
Comment 6 Radar WebKit Bug Importer 2019-07-12 10:14:04 PDT
<rdar://problem/53014344>