Revision: 23653
Author:   [email protected]
Date:     Wed Sep  3 12:43:41 2014 UTC
Log:      Lower simplified StringLessThan[OrEqual] to runtime call.

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

Review URL: https://codereview.chromium.org/531093002
https://code.google.com/p/v8/source/detail?r=23653

Modified:
 /branches/bleeding_edge/src/compiler/machine-operator.h
 /branches/bleeding_edge/src/compiler/simplified-lowering.cc
 /branches/bleeding_edge/src/compiler/simplified-lowering.h
 /branches/bleeding_edge/test/cctest/cctest.status
 /branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc

=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator.h Thu Aug 28 13:17:38 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator.h Wed Sep 3 12:43:41 2014 UTC
@@ -60,6 +60,7 @@
 #define UNOP(name) SIMPLE(name, Operator::kPure, 1, 1)

 #define WORD_SIZE(x) return is64() ? Word64##x() : Word32##x()
+#define INT_SIZE(x) return is64() ? Int64##x() : Int32##x()

   Operator* Load(MachineType rep) {  // load [base + index]
     OP1(Load, MachineType, rep, Operator::kNoWrite, 2, 1);
@@ -120,6 +121,11 @@
   Operator* Int64UMod() { BINOP(Int64UMod); }
   Operator* Int64LessThan() { BINOP(Int64LessThan); }
   Operator* Int64LessThanOrEqual() { BINOP(Int64LessThanOrEqual); }
+
+ // Signed comparison of word-sized integer values, translates to int32/int64
+  // comparisons depending on the word-size of the machine.
+  Operator* IntLessThan() { INT_SIZE(LessThan); }
+  Operator* IntLessThanOrEqual() { INT_SIZE(LessThanOrEqual); }

   // Convert representation of integers between float64 and int32/uint32.
// The precise rounding mode and handling of out of range inputs are *not*
@@ -157,6 +163,7 @@
   inline MachineType word() const { return word_; }

 #undef WORD_SIZE
+#undef INT_SIZE
 #undef UNOP
 #undef BINOP
 #undef OP1
=======================================
--- /branches/bleeding_edge/src/compiler/simplified-lowering.cc Wed Sep 3 11:30:05 2014 UTC +++ /branches/bleeding_edge/src/compiler/simplified-lowering.cc Wed Sep 3 12:43:41 2014 UTC
@@ -526,12 +526,12 @@
       }
       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: {
@@ -855,23 +855,42 @@
 }


-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()->IntLessThan());
+  node->ReplaceInput(0, StringComparison(node, true));
+  node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
+}
+
+
+void SimplifiedLowering::DoStringLessThanOrEqual(Node* node) {
+  node->set_op(machine()->IntLessThanOrEqual());
+  node->ReplaceInput(0, StringComparison(node, true));
   node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
 }

=======================================
--- /branches/bleeding_edge/src/compiler/simplified-lowering.h Tue Sep 2 13:26:52 2014 UTC +++ /branches/bleeding_edge/src/compiler/simplified-lowering.h Wed Sep 3 12:43:41 2014 UTC
@@ -29,6 +29,8 @@
   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 @@
   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;

=======================================
--- /branches/bleeding_edge/test/cctest/cctest.status Tue Sep 2 19:42:05 2014 UTC +++ /branches/bleeding_edge/test/cctest/cctest.status Wed Sep 3 12:43:41 2014 UTC
@@ -300,7 +300,7 @@
   'test-serialize/DeserializeFromSecondSerialization': [SKIP],

   # Test requires turbofan:
-  'test-simplified-lowering/LowerStringOps_to_call_and_wordeq': [SKIP],
+  'test-simplified-lowering/LowerStringOps_to_call_and_compare': [SKIP],
 }],  # 'arch == mipsel or arch == mips'

##############################################################################
@@ -319,7 +319,7 @@
   'test-serialize/DeserializeFromSecondSerialization': [SKIP],

   # Test requires turbofan:
-  'test-simplified-lowering/LowerStringOps_to_call_and_wordeq': [SKIP],
+  'test-simplified-lowering/LowerStringOps_to_call_and_compare': [SKIP],
 }],  # 'arch == mips64el'

##############################################################################
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc Tue Sep 2 13:26:52 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc Wed Sep 3 12:43:41 2014 UTC
@@ -1051,15 +1051,17 @@
 }


-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()->IntLessThan()->opcode());
+  IrOpcode::Value compare_le =
+ static_cast<IrOpcode::Value>(t.machine()->IntLessThanOrEqual()->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