<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[194969] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/194969">194969</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-13 11:33:02 -0800 (Wed, 13 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[JSC] Legalize Memory Offsets for ARM64 before lowering to Air
https://bugs.webkit.org/show_bug.cgi?id=153065

Patch by Benjamin Poulain &lt;bpoulain@apple.com&gt; on 2016-01-13
Reviewed by Mark Lam.
Reviewed by Filip Pizlo.

On ARM64, we cannot use signed 32bits offset for memory addressing.
There are two available addressing: signed 9bits and unsigned scaled 12bits.
Air already knows about it.

In this patch, the offsets are changed to something valid for ARM64
prior to lowering. When an offset is invalid, it is just computed
before the instruction and used as the base for addressing.

* JavaScriptCore.xcodeproj/project.pbxproj:
* b3/B3Generate.cpp:
(JSC::B3::generateToAir):
* b3/B3LegalizeMemoryOffsets.cpp: Added.
(JSC::B3::legalizeMemoryOffsets):
* b3/B3LegalizeMemoryOffsets.h: Added.
* b3/B3LowerToAir.cpp:
(JSC::B3::Air::LowerToAir::effectiveAddr): Deleted.
* b3/testb3.cpp:
(JSC::B3::testLoadWithOffsetImpl):
(JSC::B3::testLoadOffsetImm9Max):
(JSC::B3::testLoadOffsetImm9MaxPlusOne):
(JSC::B3::testLoadOffsetImm9MaxPlusTwo):
(JSC::B3::testLoadOffsetImm9Min):
(JSC::B3::testLoadOffsetImm9MinMinusOne):
(JSC::B3::testLoadOffsetScaledUnsignedImm12Max):
(JSC::B3::testLoadOffsetScaledUnsignedOverImm12Max):
(JSC::B3::run):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3Generatecpp">trunk/Source/JavaScriptCore/b3/B3Generate.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3LowerToAircpp">trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3testb3cpp">trunk/Source/JavaScriptCore/b3/testb3.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreb3B3LegalizeMemoryOffsetscpp">trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreb3B3LegalizeMemoryOffsetsh">trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (194968 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-01-13 19:22:28 UTC (rev 194968)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2016-01-13  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        [JSC] Legalize Memory Offsets for ARM64 before lowering to Air
+        https://bugs.webkit.org/show_bug.cgi?id=153065
+
+        Reviewed by Mark Lam.
+        Reviewed by Filip Pizlo.
+
+        On ARM64, we cannot use signed 32bits offset for memory addressing.
+        There are two available addressing: signed 9bits and unsigned scaled 12bits.
+        Air already knows about it.
+
+        In this patch, the offsets are changed to something valid for ARM64
+        prior to lowering. When an offset is invalid, it is just computed
+        before the instruction and used as the base for addressing.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * b3/B3Generate.cpp:
+        (JSC::B3::generateToAir):
+        * b3/B3LegalizeMemoryOffsets.cpp: Added.
+        (JSC::B3::legalizeMemoryOffsets):
+        * b3/B3LegalizeMemoryOffsets.h: Added.
+        * b3/B3LowerToAir.cpp:
+        (JSC::B3::Air::LowerToAir::effectiveAddr): Deleted.
+        * b3/testb3.cpp:
+        (JSC::B3::testLoadWithOffsetImpl):
+        (JSC::B3::testLoadOffsetImm9Max):
+        (JSC::B3::testLoadOffsetImm9MaxPlusOne):
+        (JSC::B3::testLoadOffsetImm9MaxPlusTwo):
+        (JSC::B3::testLoadOffsetImm9Min):
+        (JSC::B3::testLoadOffsetImm9MinMinusOne):
+        (JSC::B3::testLoadOffsetScaledUnsignedImm12Max):
+        (JSC::B3::testLoadOffsetScaledUnsignedOverImm12Max):
+        (JSC::B3::run):
+
</ins><span class="cx"> 2016-01-12  Per Arne Vollan  &lt;peavo@outlook.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [FTL][Win64] Compile error.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (194968 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2016-01-13 19:22:28 UTC (rev 194968)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -1152,6 +1152,8 @@
</span><span class="cx">                 43422A631C158E6D00E2EB98 /* B3ConstFloatValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 43422A611C15871B00E2EB98 /* B3ConstFloatValue.h */; };
</span><span class="cx">                 43422A661C16267500E2EB98 /* B3ReduceDoubleToFloat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43422A641C16221E00E2EB98 /* B3ReduceDoubleToFloat.cpp */; };
</span><span class="cx">                 43422A671C16267800E2EB98 /* B3ReduceDoubleToFloat.h in Headers */ = {isa = PBXBuildFile; fileRef = 43422A651C16221E00E2EB98 /* B3ReduceDoubleToFloat.h */; };
</span><ins>+                436E54531C468E7400B5AF73 /* B3LegalizeMemoryOffsets.h in Headers */ = {isa = PBXBuildFile; fileRef = 436E54521C468E5F00B5AF73 /* B3LegalizeMemoryOffsets.h */; };
+                436E54541C468E7700B5AF73 /* B3LegalizeMemoryOffsets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 436E54511C468E5F00B5AF73 /* B3LegalizeMemoryOffsets.cpp */; };
</ins><span class="cx">                 43AB26C61C1A535900D82AE6 /* B3MathExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 43AB26C51C1A52F700D82AE6 /* B3MathExtras.h */; };
</span><span class="cx">                 43AB26C71C1A535C00D82AE6 /* B3MathExtras.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43AB26C41C1A52F700D82AE6 /* B3MathExtras.cpp */; };
</span><span class="cx">                 43C392AB1C3BEB0500241F53 /* AssemblerCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 43C392AA1C3BEB0000241F53 /* AssemblerCommon.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -3260,6 +3262,8 @@
</span><span class="cx">                 43422A611C15871B00E2EB98 /* B3ConstFloatValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3ConstFloatValue.h; path = b3/B3ConstFloatValue.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 43422A641C16221E00E2EB98 /* B3ReduceDoubleToFloat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3ReduceDoubleToFloat.cpp; path = b3/B3ReduceDoubleToFloat.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 43422A651C16221E00E2EB98 /* B3ReduceDoubleToFloat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3ReduceDoubleToFloat.h; path = b3/B3ReduceDoubleToFloat.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                436E54511C468E5F00B5AF73 /* B3LegalizeMemoryOffsets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3LegalizeMemoryOffsets.cpp; path = b3/B3LegalizeMemoryOffsets.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                436E54521C468E5F00B5AF73 /* B3LegalizeMemoryOffsets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3LegalizeMemoryOffsets.h; path = b3/B3LegalizeMemoryOffsets.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 43AB26C41C1A52F700D82AE6 /* B3MathExtras.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3MathExtras.cpp; path = b3/B3MathExtras.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 43AB26C51C1A52F700D82AE6 /* B3MathExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3MathExtras.h; path = b3/B3MathExtras.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 43C392AA1C3BEB0000241F53 /* AssemblerCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AssemblerCommon.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -3372,8 +3376,8 @@
</span><span class="cx">                 7013CA8A1B491A9400CAE613 /* JSJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSJob.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7035587C1C418419004BD7BF /* MapPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = MapPrototype.js; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 7035587D1C418419004BD7BF /* SetPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = SetPrototype.js; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                7035587E1C418458004BD7BF /* MapPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MapPrototype.lut.h; path = MapPrototype.lut.h; sourceTree = &quot;&lt;group&gt;&quot;; };
-                7035587F1C418458004BD7BF /* SetPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SetPrototype.lut.h; path = SetPrototype.lut.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><ins>+                7035587E1C418458004BD7BF /* MapPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapPrototype.lut.h; sourceTree = &quot;&lt;group&gt;&quot;; };
+                7035587F1C418458004BD7BF /* SetPrototype.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SetPrototype.lut.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 704FD35305697E6D003DBED9 /* BooleanObject.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = BooleanObject.h; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; };
</span><span class="cx">                 705B41A31A6E501E00716757 /* Symbol.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Symbol.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 705B41A41A6E501E00716757 /* Symbol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Symbol.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -4710,6 +4714,8 @@
</span><span class="cx">                                 0FEC85B41BE1462F0080FF74 /* B3InsertionSet.cpp */,
</span><span class="cx">                                 0FEC85B51BE1462F0080FF74 /* B3InsertionSet.h */,
</span><span class="cx">                                 0FEC85B61BE1462F0080FF74 /* B3InsertionSetInlines.h */,
</span><ins>+                                436E54511C468E5F00B5AF73 /* B3LegalizeMemoryOffsets.cpp */,
+                                436E54521C468E5F00B5AF73 /* B3LegalizeMemoryOffsets.h */,
</ins><span class="cx">                                 0F338E191BF286EA0013C88F /* B3LowerMacros.cpp */,
</span><span class="cx">                                 0F338E1A1BF286EA0013C88F /* B3LowerMacros.h */,
</span><span class="cx">                                 4319DA011C1BE3C1001D260B /* B3LowerMacrosAfterOptimizations.cpp */,
</span><span class="lines">@@ -7937,6 +7943,7 @@
</span><span class="cx">                                 BCDE3AB80E6C82F5001453A7 /* Structure.h in Headers */,
</span><span class="cx">                                 7E4EE7090EBB7963005934AA /* StructureChain.h in Headers */,
</span><span class="cx">                                 2AAAA31218BD49D100394CC8 /* StructureIDBlob.h in Headers */,
</span><ins>+                                436E54531C468E7400B5AF73 /* B3LegalizeMemoryOffsets.h in Headers */,
</ins><span class="cx">                                 2AF7382D18BBBF92008A5A37 /* StructureIDTable.h in Headers */,
</span><span class="cx">                                 0FD2C92416D01EE900C7803F /* StructureInlines.h in Headers */,
</span><span class="cx">                                 C2FE18A416BAEC4000AF3061 /* StructureRareData.h in Headers */,
</span><span class="lines">@@ -8614,6 +8621,7 @@
</span><span class="cx">                                 0FEC85091BDACDAC0080FF74 /* B3Common.cpp in Sources */,
</span><span class="cx">                                 0FEC850B1BDACDAC0080FF74 /* B3Commutativity.cpp in Sources */,
</span><span class="cx">                                 0FEC850D1BDACDAC0080FF74 /* B3Const32Value.cpp in Sources */,
</span><ins>+                                436E54541C468E7700B5AF73 /* B3LegalizeMemoryOffsets.cpp in Sources */,
</ins><span class="cx">                                 0FEC850F1BDACDAC0080FF74 /* B3Const64Value.cpp in Sources */,
</span><span class="cx">                                 0FEC85111BDACDAC0080FF74 /* B3ConstDoubleValue.cpp in Sources */,
</span><span class="cx">                                 0FEC85131BDACDAC0080FF74 /* B3ControlValue.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3Generatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3Generate.cpp (194968 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3Generate.cpp        2016-01-13 19:22:28 UTC (rev 194968)
+++ trunk/Source/JavaScriptCore/b3/B3Generate.cpp        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &quot;AirGenerate.h&quot;
</span><span class="cx"> #include &quot;AirInstInlines.h&quot;
</span><span class="cx"> #include &quot;B3Common.h&quot;
</span><ins>+#include &quot;B3LegalizeMemoryOffsets.h&quot;
</ins><span class="cx"> #include &quot;B3LowerMacros.h&quot;
</span><span class="cx"> #include &quot;B3LowerMacrosAfterOptimizations.h&quot;
</span><span class="cx"> #include &quot;B3LowerToAir.h&quot;
</span><span class="lines">@@ -85,6 +86,8 @@
</span><span class="cx"> 
</span><span class="cx">     lowerMacrosAfterOptimizations(procedure);
</span><span class="cx"> 
</span><ins>+    legalizeMemoryOffsets(procedure);
+
</ins><span class="cx">     moveConstants(procedure);
</span><span class="cx"> 
</span><span class="cx">     if (shouldValidateIR())
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3LegalizeMemoryOffsetscpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.cpp (0 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.cpp                                (rev 0)
+++ trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.cpp        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -0,0 +1,92 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;B3LegalizeMemoryOffsets.h&quot;
+
+#if ENABLE(B3_JIT)
+
+#include &quot;AirArg.h&quot;
+#include &quot;B3InsertionSetInlines.h&quot;
+#include &quot;B3MemoryValue.h&quot;
+#include &quot;B3PhaseScope.h&quot;
+#include &quot;B3ProcedureInlines.h&quot;
+
+namespace JSC { namespace B3 {
+
+namespace {
+
+class LegalizeMemoryOffsets {
+public:
+    LegalizeMemoryOffsets(Procedure&amp; proc)
+        : m_proc(proc)
+        , m_insertionSet(proc)
+    {
+    }
+
+    void run()
+    {
+        if (!isARM64())
+            return;
+
+        for (BasicBlock* block : m_proc) {
+            for (unsigned index = 0; index &lt; block-&gt;size(); ++index) {
+                MemoryValue* memoryValue = block-&gt;at(index)-&gt;as&lt;MemoryValue&gt;();
+                if (!memoryValue)
+                    continue;
+
+                int32_t offset = memoryValue-&gt;offset();
+                Air::Arg::Width width = Air::Arg::widthForBytes(memoryValue-&gt;accessByteSize());
+                if (!Air::Arg::isValidAddrForm(offset, width)) {
+                    Value* base = memoryValue-&gt;lastChild();
+                    Value* offsetValue = m_insertionSet.insertIntConstant(index, memoryValue-&gt;origin(), pointerType(), offset);
+                    Value* resolvedAddress = m_proc.add&lt;Value&gt;(Add, memoryValue-&gt;origin(), base, offsetValue);
+                    m_insertionSet.insertValue(index, resolvedAddress);
+
+                    memoryValue-&gt;lastChild() = resolvedAddress;
+                    memoryValue-&gt;setOffset(0);
+                }
+            }
+            m_insertionSet.execute(block);
+        }
+    }
+
+    Procedure&amp; m_proc;
+    InsertionSet m_insertionSet;
+};
+
+} // anonymous namespace
+
+void legalizeMemoryOffsets(Procedure&amp; proc)
+{
+    PhaseScope phaseScope(proc, &quot;legalizeMemoryOffsets&quot;);
+    LegalizeMemoryOffsets legalizeMemoryOffsets(proc);
+    legalizeMemoryOffsets.run();
+}
+
+} } // namespace JSC::B3
+
+#endif // ENABLE(B3_JIT)
+
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3LegalizeMemoryOffsetsh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.h (0 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/b3/B3LegalizeMemoryOffsets.h        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef B3LegalizeMemoryOffsets_h
+#define B3LegalizeMemoryOffsets_h
+
+#if ENABLE(B3_JIT)
+
+namespace JSC { namespace B3 {
+
+class Procedure;
+
+// If the offsets of a MemoryValue cannot be represented in the target instruction set,
+// compute it explicitly.
+void legalizeMemoryOffsets(Procedure&amp;);
+
+} } // namespace JSC::B3
+
+#endif // ENABLE(B3_JIT)
+
+#endif // B3LegalizeMemoryOffsets_h
+
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3B3LowerToAircpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp (194968 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp        2016-01-13 19:22:28 UTC (rev 194968)
+++ trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -357,10 +357,6 @@
</span><span class="cx">     // This turns the given operand into an address.
</span><span class="cx">     Arg effectiveAddr(Value* address, int32_t offset, Arg::Width width)
</span><span class="cx">     {
</span><del>-        // B3 allows any memory operation to have a 32-bit offset. That's not how some architectures
-        // work. We solve this by requiring a just-before-lowering phase that legalizes offsets.
-        // FIXME: Implement such a legalization phase.
-        // https://bugs.webkit.org/show_bug.cgi?id=152530
</del><span class="cx">         ASSERT(Arg::isValidAddrForm(offset, width));
</span><span class="cx"> 
</span><span class="cx">         auto fallback = [&amp;] () -&gt; Arg {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreb3testb3cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/b3/testb3.cpp (194968 => 194969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/b3/testb3.cpp        2016-01-13 19:22:28 UTC (rev 194968)
+++ trunk/Source/JavaScriptCore/b3/testb3.cpp        2016-01-13 19:33:02 UTC (rev 194969)
</span><span class="lines">@@ -136,6 +136,77 @@
</span><span class="cx">     CHECK(compileAndRun&lt;int&gt;(proc) == 42);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void testLoadWithOffsetImpl(int32_t offset64, int32_t offset32)
+{
+    {
+        Procedure proc;
+        BasicBlock* root = proc.addBlock();
+        int64_t x = -42;
+        Value* base = root-&gt;appendNew&lt;ArgumentRegValue&gt;(proc, Origin(), GPRInfo::argumentGPR0);
+        root-&gt;appendNew&lt;ControlValue&gt;(
+            proc, Return, Origin(),
+            root-&gt;appendNew&lt;MemoryValue&gt;(
+                proc, Load, Int64, Origin(),
+                base,
+                offset64));
+
+        char* address = reinterpret_cast&lt;char*&gt;(&amp;x) - offset64;
+        CHECK(compileAndRun&lt;int64_t&gt;(proc, address) == -42);
+    }
+    {
+        Procedure proc;
+        BasicBlock* root = proc.addBlock();
+        int32_t x = -42;
+        Value* base = root-&gt;appendNew&lt;ArgumentRegValue&gt;(proc, Origin(), GPRInfo::argumentGPR0);
+        root-&gt;appendNew&lt;ControlValue&gt;(
+            proc, Return, Origin(),
+            root-&gt;appendNew&lt;MemoryValue&gt;(
+                proc, Load, Int32, Origin(),
+                base,
+                offset32));
+
+        char* address = reinterpret_cast&lt;char*&gt;(&amp;x) - offset32;
+        CHECK(compileAndRun&lt;int32_t&gt;(proc, address) == -42);
+    }
+}
+
+void testLoadOffsetImm9Max()
+{
+    testLoadWithOffsetImpl(255, 255);
+}
+
+void testLoadOffsetImm9MaxPlusOne()
+{
+    testLoadWithOffsetImpl(256, 256);
+}
+
+void testLoadOffsetImm9MaxPlusTwo()
+{
+    testLoadWithOffsetImpl(257, 257);
+}
+
+void testLoadOffsetImm9Min()
+{
+    testLoadWithOffsetImpl(-256, -256);
+}
+
+void testLoadOffsetImm9MinMinusOne()
+{
+    testLoadWithOffsetImpl(-257, -257);
+}
+
+void testLoadOffsetScaledUnsignedImm12Max()
+{
+    testLoadWithOffsetImpl(32760, 16380);
+}
+
+void testLoadOffsetScaledUnsignedOverImm12Max()
+{
+    testLoadWithOffsetImpl(32760, 32760);
+    testLoadWithOffsetImpl(32761, 16381);
+    testLoadWithOffsetImpl(32768, 16384);
+}
+
</ins><span class="cx"> void testArg(int argument)
</span><span class="cx"> {
</span><span class="cx">     Procedure proc;
</span><span class="lines">@@ -9288,6 +9359,13 @@
</span><span class="cx"> 
</span><span class="cx">     RUN(test42());
</span><span class="cx">     RUN(testLoad42());
</span><ins>+    RUN(testLoadOffsetImm9Max());
+    RUN(testLoadOffsetImm9MaxPlusOne());
+    RUN(testLoadOffsetImm9MaxPlusTwo());
+    RUN(testLoadOffsetImm9Min());
+    RUN(testLoadOffsetImm9MinMinusOne());
+    RUN(testLoadOffsetScaledUnsignedImm12Max());
+    RUN(testLoadOffsetScaledUnsignedOverImm12Max());
</ins><span class="cx">     RUN(testArg(43));
</span><span class="cx">     RUN(testReturnConst64(5));
</span><span class="cx">     RUN(testReturnConst64(-42));
</span></span></pre>
</div>
</div>

</body>
</html>