Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2453343002: [asmjs] Do constant folding for I32Asmjs(Div|Rem)S to avoid checks of constant divisors (Closed)
Patch Set: Add tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 Node* WasmGraphBuilder::BuildI32RemU(Node* left, Node* right, 1860 Node* WasmGraphBuilder::BuildI32RemU(Node* left, Node* right,
1861 wasm::WasmCodePosition position) { 1861 wasm::WasmCodePosition position) {
1862 MachineOperatorBuilder* m = jsgraph()->machine(); 1862 MachineOperatorBuilder* m = jsgraph()->machine();
1863 return graph()->NewNode( 1863 return graph()->NewNode(
1864 m->Uint32Mod(), left, right, 1864 m->Uint32Mod(), left, right,
1865 trap_->ZeroCheck32(wasm::kTrapRemByZero, right, position)); 1865 trap_->ZeroCheck32(wasm::kTrapRemByZero, right, position));
1866 } 1866 }
1867 1867
1868 Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) { 1868 Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) {
1869 MachineOperatorBuilder* m = jsgraph()->machine(); 1869 MachineOperatorBuilder* m = jsgraph()->machine();
1870
1871 Int32Matcher mr(right);
1872 if (mr.HasValue()) {
1873 if (mr.Value() == 0) {
1874 return jsgraph()->Int32Constant(0);
1875 } else if (mr.Value() == -1) {
1876 // The result is the negation of the left input.
1877 return graph()->NewNode(m->Int32Sub(), jsgraph()->Int32Constant(0), left);
1878 }
1879 return graph()->NewNode(m->Int32Div(), left, right, *control_);
1880 }
1881
1870 // asm.js semantics return 0 on divide or mod by zero. 1882 // asm.js semantics return 0 on divide or mod by zero.
1871 if (m->Int32DivIsSafe()) { 1883 if (m->Int32DivIsSafe()) {
1872 // The hardware instruction does the right thing (e.g. arm). 1884 // The hardware instruction does the right thing (e.g. arm).
1873 return graph()->NewNode(m->Int32Div(), left, right, graph()->start()); 1885 return graph()->NewNode(m->Int32Div(), left, right, graph()->start());
1874 } 1886 }
1875 1887
1876 // Check denominator for zero. 1888 // Check denominator for zero.
1877 Diamond z( 1889 Diamond z(
1878 graph(), jsgraph()->common(), 1890 graph(), jsgraph()->common(),
1879 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(0)), 1891 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(0)),
1880 BranchHint::kFalse); 1892 BranchHint::kFalse);
1881 1893
1882 // Check numerator for -1. (avoid minint / -1 case). 1894 // Check numerator for -1. (avoid minint / -1 case).
1883 Diamond n( 1895 Diamond n(
1884 graph(), jsgraph()->common(), 1896 graph(), jsgraph()->common(),
1885 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)), 1897 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)),
1886 BranchHint::kFalse); 1898 BranchHint::kFalse);
1887 1899
1888 Node* div = graph()->NewNode(m->Int32Div(), left, right, z.if_false); 1900 Node* div = graph()->NewNode(m->Int32Div(), left, right, z.if_false);
1889 Node* neg = 1901 Node* neg =
1890 graph()->NewNode(m->Int32Sub(), jsgraph()->Int32Constant(0), left); 1902 graph()->NewNode(m->Int32Sub(), jsgraph()->Int32Constant(0), left);
1891 1903
1892 return n.Phi( 1904 return n.Phi(
1893 MachineRepresentation::kWord32, neg, 1905 MachineRepresentation::kWord32, neg,
1894 z.Phi(MachineRepresentation::kWord32, jsgraph()->Int32Constant(0), div)); 1906 z.Phi(MachineRepresentation::kWord32, jsgraph()->Int32Constant(0), div));
1895 } 1907 }
1896 1908
1897 Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) { 1909 Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) {
1898 MachineOperatorBuilder* m = jsgraph()->machine(); 1910 MachineOperatorBuilder* m = jsgraph()->machine();
1911
1912 Int32Matcher mr(right);
1913 if (mr.HasValue()) {
1914 if (mr.Value() == 0) {
1915 return jsgraph()->Int32Constant(0);
1916 } else if (mr.Value() == -1) {
1917 return jsgraph()->Int32Constant(0);
1918 }
1919 return graph()->NewNode(m->Int32Mod(), left, right, *control_);
1920 }
1921
1899 // asm.js semantics return 0 on divide or mod by zero. 1922 // asm.js semantics return 0 on divide or mod by zero.
1900 // Explicit check for x % 0. 1923 // Explicit check for x % 0.
1901 Diamond z( 1924 Diamond z(
1902 graph(), jsgraph()->common(), 1925 graph(), jsgraph()->common(),
1903 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(0)), 1926 graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(0)),
1904 BranchHint::kFalse); 1927 BranchHint::kFalse);
1905 1928
1906 // Explicit check for x % -1. 1929 // Explicit check for x % -1.
1907 Diamond d( 1930 Diamond d(
1908 graph(), jsgraph()->common(), 1931 graph(), jsgraph()->common(),
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
3459 function_->code_start_offset), 3482 function_->code_start_offset),
3460 compile_ms); 3483 compile_ms);
3461 } 3484 }
3462 3485
3463 return code; 3486 return code;
3464 } 3487 }
3465 3488
3466 } // namespace compiler 3489 } // namespace compiler
3467 } // namespace internal 3490 } // namespace internal
3468 } // namespace v8 3491 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698