Reviewers: titzer,

Description:
Lower simplified StringLessThan[OrEqual] to runtime call.

[email protected]
TEST=cctest/test-simplified-lowering/LowerStringOps_to_call_and_compare

Please review this at https://codereview.chromium.org/531093002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+49, -21 lines):
  M src/compiler/simplified-lowering.h
  M src/compiler/simplified-lowering.cc
  M test/cctest/compiler/test-simplified-lowering.cc


Index: src/compiler/simplified-lowering.cc
diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc index 06df207149cccaf3d71405360b3695cf8fd093d0..6071615676a793b022488b9abfa838525f24d755 100644
--- a/src/compiler/simplified-lowering.cc
+++ b/src/compiler/simplified-lowering.cc
@@ -513,12 +513,12 @@ class RepresentationSelector {
       }
       case IrOpcode::kStringLessThan: {
         VisitBinop(node, kMachAnyTagged, kRepBit);
-        // TODO(titzer): lower StringLessThan to stub/runtime call.
+        if (lower()) lowering->DoStringLessThan(node);
         break;
       }
       case IrOpcode::kStringLessThanOrEqual: {
         VisitBinop(node, kMachAnyTagged, kRepBit);
-        // TODO(titzer): lower StringLessThanOrEqual to stub/runtime call.
+        if (lower()) lowering->DoStringLessThanOrEqual(node);
         break;
       }
       case IrOpcode::kStringAdd: {
@@ -836,23 +836,44 @@ void SimplifiedLowering::DoStringAdd(Node* node) {
 }


-void SimplifiedLowering::DoStringEqual(Node* node) {
+Node* SimplifiedLowering::StringComparison(Node* node, bool requires_ordering) {
   CEntryStub stub(zone()->isolate(), 1);
-  ExternalReference ref(Runtime::kStringEquals, zone()->isolate());
+  Runtime::FunctionId f =
+      requires_ordering ? Runtime::kStringCompare : Runtime::kStringEquals;
+  ExternalReference ref(f, zone()->isolate());
   Operator::Properties props = node->op()->properties();
// TODO(mstarzinger): We should call StringCompareStub here instead, once an
   // interface descriptor is available for it.
-  CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
-      Runtime::kStringEquals, 2, props, zone());
-  Node* call = graph()->NewNode(common()->Call(desc),
-                                jsgraph()->HeapConstant(stub.GetCode()),
-                                NodeProperties::GetValueInput(node, 0),
-                                NodeProperties::GetValueInput(node, 1),
-                                jsgraph()->ExternalConstant(ref),
-                                jsgraph()->Int32Constant(2),
-                                jsgraph()->UndefinedConstant());
+ CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(f, 2, props, zone());
+  return graph()->NewNode(common()->Call(desc),
+                          jsgraph()->HeapConstant(stub.GetCode()),
+                          NodeProperties::GetValueInput(node, 0),
+                          NodeProperties::GetValueInput(node, 1),
+                          jsgraph()->ExternalConstant(ref),
+                          jsgraph()->Int32Constant(2),
+                          jsgraph()->UndefinedConstant());
+}
+
+
+void SimplifiedLowering::DoStringEqual(Node* node) {
   node->set_op(machine()->WordEqual());
-  node->ReplaceInput(0, call);
+  node->ReplaceInput(0, StringComparison(node, false));
+  node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
+}
+
+
+void SimplifiedLowering::DoStringLessThan(Node* node) {
+  node->set_op(machine()->is32() ? machine()->Int32LessThan()
+                                 : machine()->Int64LessThan());
+  node->ReplaceInput(0, StringComparison(node, true));
+  node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
+}
+
+
+void SimplifiedLowering::DoStringLessThanOrEqual(Node* node) {
+  node->set_op(machine()->is32() ? machine()->Int32LessThanOrEqual()
+                                 : machine()->Int64LessThanOrEqual());
+  node->ReplaceInput(0, StringComparison(node, true));
   node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
 }

Index: src/compiler/simplified-lowering.h
diff --git a/src/compiler/simplified-lowering.h b/src/compiler/simplified-lowering.h index 715bb40013693f62efd35f70bc00547880ffd8c1..94766f7d08119535381a47f2a0cbb1f61348fce7 100644
--- a/src/compiler/simplified-lowering.h
+++ b/src/compiler/simplified-lowering.h
@@ -29,6 +29,8 @@ class SimplifiedLowering {
   void DoStoreElement(Node* node);
   void DoStringAdd(Node* node);
   void DoStringEqual(Node* node);
+  void DoStringLessThan(Node* node);
+  void DoStringLessThanOrEqual(Node* node);

  private:
   JSGraph* jsgraph_;
@@ -39,6 +41,7 @@ class SimplifiedLowering {
   Node* Untag(Node* node);
   Node* OffsetMinusTagConstant(int32_t offset);
   Node* ComputeIndex(const ElementAccess& access, Node* index);
+  Node* StringComparison(Node* node, bool requires_ordering);

   friend class RepresentationSelector;

Index: test/cctest/compiler/test-simplified-lowering.cc
diff --git a/test/cctest/compiler/test-simplified-lowering.cc b/test/cctest/compiler/test-simplified-lowering.cc index ed0abe05db48775e1f12a906dea9b0639e988053..43fc1cc46fcd40a95016253b8cf7fd36d9b33b69 100644
--- a/test/cctest/compiler/test-simplified-lowering.cc
+++ b/test/cctest/compiler/test-simplified-lowering.cc
@@ -1051,15 +1051,19 @@ TEST(LowerReferenceEqual_to_wordeq) {
 }


-TEST(LowerStringOps_to_call_and_wordeq) {
+TEST(LowerStringOps_to_call_and_compare) {
   TestingGraph t(Type::String(), Type::String());
-  IrOpcode::Value opcode =
+  IrOpcode::Value compare_eq =
       static_cast<IrOpcode::Value>(t.machine()->WordEqual()->opcode());
-  t.CheckLoweringBinop(opcode, t.simplified()->StringEqual());
-  if (false) {  // TODO(titzer): lower StringOps to stub/runtime calls
-    t.CheckLoweringBinop(opcode, t.simplified()->StringLessThan());
-    t.CheckLoweringBinop(opcode, t.simplified()->StringLessThanOrEqual());
-  }
+  IrOpcode::Value compare_lt = static_cast<IrOpcode::Value>(
+      t.machine()->is32() ? t.machine()->Int32LessThan()->opcode()
+                          : t.machine()->Int64LessThan()->opcode());
+  IrOpcode::Value compare_le = static_cast<IrOpcode::Value>(
+      t.machine()->is32() ? t.machine()->Int32LessThanOrEqual()->opcode()
+                          : t.machine()->Int64LessThanOrEqual()->opcode());
+  t.CheckLoweringBinop(compare_eq, t.simplified()->StringEqual());
+  t.CheckLoweringBinop(compare_lt, t.simplified()->StringLessThan());
+ t.CheckLoweringBinop(compare_le, t.simplified()->StringLessThanOrEqual());
   t.CheckLoweringBinop(IrOpcode::kCall, t.simplified()->StringAdd());
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to