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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index 7ea4b2088f2d2626da747378f4feaab559ee55e6..e1c3aa7dca94c7d3a6ac1e7c04bb201f95c4cc55 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -1867,6 +1867,18 @@ Node* WasmGraphBuilder::BuildI32RemU(Node* left, Node* right,
Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) {
MachineOperatorBuilder* m = jsgraph()->machine();
+
+ Int32Matcher mr(right);
+ if (mr.HasValue()) {
+ if (mr.Value() == 0) {
+ return jsgraph()->Int32Constant(0);
+ } else if (mr.Value() == -1) {
+ // The result is the negation of the left input.
+ return graph()->NewNode(m->Int32Sub(), jsgraph()->Int32Constant(0), left);
+ }
+ return graph()->NewNode(m->Int32Div(), left, right, *control_);
+ }
+
// asm.js semantics return 0 on divide or mod by zero.
if (m->Int32DivIsSafe()) {
// The hardware instruction does the right thing (e.g. arm).
@@ -1896,6 +1908,17 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) {
Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) {
MachineOperatorBuilder* m = jsgraph()->machine();
+
+ Int32Matcher mr(right);
+ if (mr.HasValue()) {
+ if (mr.Value() == 0) {
+ return jsgraph()->Int32Constant(0);
+ } else if (mr.Value() == -1) {
+ return jsgraph()->Int32Constant(0);
+ }
+ return graph()->NewNode(m->Int32Mod(), left, right, *control_);
+ }
+
// asm.js semantics return 0 on divide or mod by zero.
// Explicit check for x % 0.
Diamond z(
« 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