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

Unified Diff: src/compiler/js-typed-lowering.cc

Issue 681223002: [turbofan] Improve typed lowering for JSToBoolean. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | « src/compiler/access-builder.cc ('k') | test/cctest/compiler/test-js-typed-lowering.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-typed-lowering.cc
diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc
index fb510e07ce941efcc831a2e82de599d652e7abc4..9c9a7d282e15e745eeba7224ae38ef68569765ff 100644
--- a/src/compiler/js-typed-lowering.cc
+++ b/src/compiler/js-typed-lowering.cc
@@ -546,7 +546,38 @@ Reduction JSTypedLowering::ReduceJSToBooleanInput(Node* input) {
Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp);
return ReplaceWith(inv);
}
- // TODO(turbofan): js-typed-lowering of ToBoolean(string)
+ if (input_type->Is(Type::String())) {
+ // JSToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0))
+ FieldAccess access = AccessBuilder::ForStringLength();
+ Node* length = graph()->NewNode(simplified()->LoadField(access), input,
+ graph()->start(), graph()->start());
+ Node* cmp = graph()->NewNode(simplified()->NumberEqual(), length,
+ jsgraph()->ZeroConstant());
+ Node* inv = graph()->NewNode(simplified()->BooleanNot(), cmp);
+ return ReplaceWith(inv);
+ }
+ if (input->opcode() == IrOpcode::kPhi && input_type->Is(Type::Primitive())) {
+ // JSToBoolean(phi(x1,...,xn):primitive)
+ // => phi(JSToBoolean(x1),...,JSToBoolean(xn))
+ int input_count = input->InputCount() - 1;
+ Node** inputs = zone()->NewArray<Node*>(input_count + 1);
+ for (int i = 0; i < input_count; ++i) {
+ Node* value = input->InputAt(i);
+ // Recursively try to reduce the value first.
+ Reduction result = ReduceJSToBooleanInput(value);
+ if (result.Changed()) {
+ inputs[i] = result.replacement();
+ } else {
+ inputs[i] = graph()->NewNode(javascript()->ToBoolean(), value,
+ jsgraph()->ZeroConstant(),
+ graph()->start(), graph()->start());
+ }
+ }
+ inputs[input_count] = input->InputAt(input_count);
+ Node* phi = graph()->NewNode(common()->Phi(kMachAnyTagged, input_count),
+ input_count + 1, inputs);
+ return ReplaceWith(phi);
+ }
return NoChange();
}
« no previous file with comments | « src/compiler/access-builder.cc ('k') | test/cctest/compiler/test-js-typed-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698