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

Side by Side Diff: test/cctest/compiler/test-simplified-lowering.cc

Issue 1919513002: [turbofan] Introduce TruncateTaggedToWord32 simplified operator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 <limits> 5 #include <limits>
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/compiler/access-builder.h" 8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/change-lowering.h" 9 #include "src/compiler/change-lowering.h"
10 #include "src/compiler/control-builders.h" 10 #include "src/compiler/control-builders.h"
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 TEST(LowerNumberToInt32_to_ChangeTaggedToInt32) { 1039 TEST(LowerNumberToInt32_to_ChangeTaggedToInt32) {
1040 // NumberToInt32(x: kRepTagged | kTypeInt32) used as kRepWord32 1040 // NumberToInt32(x: kRepTagged | kTypeInt32) used as kRepWord32
1041 TestingGraph t(Type::Signed32()); 1041 TestingGraph t(Type::Signed32());
1042 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), t.p0); 1042 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), t.p0);
1043 Node* use = t.Use(trunc, MachineType::Int32()); 1043 Node* use = t.Use(trunc, MachineType::Int32());
1044 t.Return(use); 1044 t.Return(use);
1045 t.Lower(); 1045 t.Lower();
1046 CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p0, use->InputAt(0)); 1046 CheckChangeOf(IrOpcode::kChangeTaggedToInt32, t.p0, use->InputAt(0));
1047 } 1047 }
1048 1048
1049 1049 TEST(LowerNumberToInt32_to_TruncateFloat64ToWord32) {
1050 TEST(LowerNumberToInt32_to_TruncateFloat64ToInt32) {
1051 // NumberToInt32(x: kRepFloat64) used as MachineType::Int32() 1050 // NumberToInt32(x: kRepFloat64) used as MachineType::Int32()
1052 TestingGraph t(Type::Number()); 1051 TestingGraph t(Type::Number());
1053 Node* p0 = t.ExampleWithOutput(MachineType::Float64()); 1052 Node* p0 = t.ExampleWithOutput(MachineType::Float64());
1054 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), p0); 1053 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), p0);
1055 Node* use = t.Use(trunc, MachineType::Int32()); 1054 Node* use = t.Use(trunc, MachineType::Int32());
1056 t.Return(use); 1055 t.Return(use);
1057 t.Lower(); 1056 t.Lower();
1058 CheckChangeOf(IrOpcode::kTruncateFloat64ToInt32, p0, use->InputAt(0)); 1057 CheckChangeOf(IrOpcode::kTruncateFloat64ToWord32, p0, use->InputAt(0));
1059 } 1058 }
1060 1059
1061 1060 TEST(LowerNumberToInt32_to_TruncateTaggedToWord32) {
1062 TEST(LowerNumberToInt32_to_TruncateFloat64ToInt32_with_change) {
1063 // NumberToInt32(x: kTypeNumber | kRepTagged) used as MachineType::Int32() 1061 // NumberToInt32(x: kTypeNumber | kRepTagged) used as MachineType::Int32()
1064 TestingGraph t(Type::Number()); 1062 TestingGraph t(Type::Number());
1065 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), t.p0); 1063 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), t.p0);
1066 Node* use = t.Use(trunc, MachineType::Int32()); 1064 Node* use = t.Use(trunc, MachineType::Int32());
1067 t.Return(use); 1065 t.Return(use);
1068 t.Lower(); 1066 t.Lower();
1069 Node* node = use->InputAt(0); 1067 CheckChangeOf(IrOpcode::kTruncateTaggedToWord32, t.p0, use->InputAt(0));
1070 CHECK_EQ(IrOpcode::kTruncateFloat64ToInt32, node->opcode());
1071 Node* of = node->InputAt(0);
1072 CHECK_EQ(IrOpcode::kChangeTaggedToFloat64, of->opcode());
1073 CHECK_EQ(t.p0, of->InputAt(0));
1074 } 1068 }
1075 1069
1076 1070
1077 TEST(LowerNumberToUint32_to_ChangeTaggedToUint32) { 1071 TEST(LowerNumberToUint32_to_ChangeTaggedToUint32) {
1078 // NumberToUint32(x: kRepTagged | kTypeUint32) used as kRepWord32 1072 // NumberToUint32(x: kRepTagged | kTypeUint32) used as kRepWord32
1079 TestingGraph t(Type::Unsigned32()); 1073 TestingGraph t(Type::Unsigned32());
1080 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), t.p0); 1074 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), t.p0);
1081 Node* use = t.Use(trunc, MachineType::Uint32()); 1075 Node* use = t.Use(trunc, MachineType::Uint32());
1082 t.Return(use); 1076 t.Return(use);
1083 t.Lower(); 1077 t.Lower();
1084 CheckChangeOf(IrOpcode::kChangeTaggedToUint32, t.p0, use->InputAt(0)); 1078 CheckChangeOf(IrOpcode::kChangeTaggedToUint32, t.p0, use->InputAt(0));
1085 } 1079 }
1086 1080
1087 1081 TEST(LowerNumberToUint32_to_TruncateFloat64ToWord32) {
1088 TEST(LowerNumberToUint32_to_TruncateFloat64ToInt32) {
1089 // NumberToUint32(x: kRepFloat64) used as MachineType::Uint32() 1082 // NumberToUint32(x: kRepFloat64) used as MachineType::Uint32()
1090 TestingGraph t(Type::Number()); 1083 TestingGraph t(Type::Number());
1091 Node* p0 = t.ExampleWithOutput(MachineType::Float64()); 1084 Node* p0 = t.ExampleWithOutput(MachineType::Float64());
1092 // TODO(titzer): run the typer here, or attach machine type to param. 1085 // TODO(titzer): run the typer here, or attach machine type to param.
1093 NodeProperties::SetType(p0, Type::Number()); 1086 NodeProperties::SetType(p0, Type::Number());
1094 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), p0); 1087 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), p0);
1095 Node* use = t.Use(trunc, MachineType::Uint32()); 1088 Node* use = t.Use(trunc, MachineType::Uint32());
1096 t.Return(use); 1089 t.Return(use);
1097 t.Lower(); 1090 t.Lower();
1098 CheckChangeOf(IrOpcode::kTruncateFloat64ToInt32, p0, use->InputAt(0)); 1091 CheckChangeOf(IrOpcode::kTruncateFloat64ToWord32, p0, use->InputAt(0));
1099 } 1092 }
1100 1093
1101 1094 TEST(LowerNumberToUint32_to_TruncateTaggedToWord32) {
1102 TEST(LowerNumberToUint32_to_TruncateFloat64ToInt32_with_change) {
1103 // NumberToInt32(x: kTypeNumber | kRepTagged) used as MachineType::Uint32() 1095 // NumberToInt32(x: kTypeNumber | kRepTagged) used as MachineType::Uint32()
1104 TestingGraph t(Type::Number()); 1096 TestingGraph t(Type::Number());
1105 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), t.p0); 1097 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), t.p0);
1106 Node* use = t.Use(trunc, MachineType::Uint32()); 1098 Node* use = t.Use(trunc, MachineType::Uint32());
1107 t.Return(use); 1099 t.Return(use);
1108 t.Lower(); 1100 t.Lower();
1109 Node* node = use->InputAt(0); 1101 CheckChangeOf(IrOpcode::kTruncateTaggedToWord32, t.p0, use->InputAt(0));
1110 CHECK_EQ(IrOpcode::kTruncateFloat64ToInt32, node->opcode());
1111 Node* of = node->InputAt(0);
1112 CHECK_EQ(IrOpcode::kChangeTaggedToFloat64, of->opcode());
1113 CHECK_EQ(t.p0, of->InputAt(0));
1114 } 1102 }
1115 1103
1116 1104 TEST(LowerNumberToUint32_to_TruncateFloat64ToWord32_uint32) {
1117 TEST(LowerNumberToUint32_to_TruncateFloat64ToInt32_uint32) {
1118 // NumberToUint32(x: kRepFloat64) used as kRepWord32 1105 // NumberToUint32(x: kRepFloat64) used as kRepWord32
1119 TestingGraph t(Type::Unsigned32()); 1106 TestingGraph t(Type::Unsigned32());
1120 Node* input = t.ExampleWithOutput(MachineType::Float64()); 1107 Node* input = t.ExampleWithOutput(MachineType::Float64());
1121 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), input); 1108 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), input);
1122 Node* use = t.Use(trunc, MachineType::RepWord32()); 1109 Node* use = t.Use(trunc, MachineType::RepWord32());
1123 t.Return(use); 1110 t.Return(use);
1124 t.Lower(); 1111 t.Lower();
1125 CheckChangeOf(IrOpcode::kTruncateFloat64ToInt32, input, use->InputAt(0)); 1112 CheckChangeOf(IrOpcode::kTruncateFloat64ToWord32, input, use->InputAt(0));
1126 } 1113 }
1127 1114
1128 1115
1129 TEST(LowerReferenceEqual_to_wordeq) { 1116 TEST(LowerReferenceEqual_to_wordeq) {
1130 TestingGraph t(Type::Any(), Type::Any()); 1117 TestingGraph t(Type::Any(), Type::Any());
1131 IrOpcode::Value opcode = 1118 IrOpcode::Value opcode =
1132 static_cast<IrOpcode::Value>(t.machine()->WordEqual()->opcode()); 1119 static_cast<IrOpcode::Value>(t.machine()->WordEqual()->opcode());
1133 t.CheckLoweringBinop(opcode, t.simplified()->ReferenceEqual(Type::Any())); 1120 t.CheckLoweringBinop(opcode, t.simplified()->ReferenceEqual(Type::Any()));
1134 } 1121 }
1135 1122
1136 void CheckChangeInsertion(IrOpcode::Value expected, MachineType from, 1123 void CheckChangeInsertion(IrOpcode::Value expected, MachineType from,
1137 MachineType to, Type* type = Type::Any()) { 1124 MachineType to, Type* type = Type::Any()) {
1138 TestingGraph t(Type::Any()); 1125 TestingGraph t(Type::Any());
1139 Node* in = t.ExampleWithOutput(from); 1126 Node* in = t.ExampleWithOutput(from);
1140 NodeProperties::SetType(in, type); 1127 NodeProperties::SetType(in, type);
1141 Node* use = t.Use(in, to); 1128 Node* use = t.Use(in, to);
1142 t.Return(use); 1129 t.Return(use);
1143 t.Lower(); 1130 t.Lower();
1144 CHECK_EQ(expected, use->InputAt(0)->opcode()); 1131 CHECK_EQ(expected, use->InputAt(0)->opcode());
1145 CHECK_EQ(in, use->InputAt(0)->InputAt(0)); 1132 CHECK_EQ(in, use->InputAt(0)->InputAt(0));
1146 } 1133 }
1147 1134
1148 TEST(InsertBasicChanges) { 1135 TEST(InsertBasicChanges) {
1149 CheckChangeInsertion(IrOpcode::kChangeFloat64ToInt32, MachineType::Float64(), 1136 CheckChangeInsertion(IrOpcode::kChangeFloat64ToInt32, MachineType::Float64(),
1150 MachineType::Int32(), Type::Signed32()); 1137 MachineType::Int32(), Type::Signed32());
1151 CheckChangeInsertion(IrOpcode::kChangeFloat64ToUint32, MachineType::Float64(), 1138 CheckChangeInsertion(IrOpcode::kChangeFloat64ToUint32, MachineType::Float64(),
1152 MachineType::Uint32(), Type::Unsigned32()); 1139 MachineType::Uint32(), Type::Unsigned32());
1153 CheckChangeInsertion(IrOpcode::kTruncateFloat64ToInt32, 1140 CheckChangeInsertion(IrOpcode::kTruncateFloat64ToWord32,
1154 MachineType::Float64(), MachineType::Uint32(), 1141 MachineType::Float64(), MachineType::Uint32(),
1155 Type::Integral32()); 1142 Type::Integral32());
1156 CheckChangeInsertion(IrOpcode::kChangeTaggedToInt32, MachineType::AnyTagged(), 1143 CheckChangeInsertion(IrOpcode::kChangeTaggedToInt32, MachineType::AnyTagged(),
1157 MachineType::Int32(), Type::Signed32()); 1144 MachineType::Int32(), Type::Signed32());
1158 CheckChangeInsertion(IrOpcode::kChangeTaggedToUint32, 1145 CheckChangeInsertion(IrOpcode::kChangeTaggedToUint32,
1159 MachineType::AnyTagged(), MachineType::Uint32(), 1146 MachineType::AnyTagged(), MachineType::Uint32(),
1160 Type::Unsigned32()); 1147 Type::Unsigned32());
1161 1148
1162 CheckChangeInsertion(IrOpcode::kChangeFloat64ToTagged, MachineType::Float64(), 1149 CheckChangeInsertion(IrOpcode::kChangeFloat64ToTagged, MachineType::Float64(),
1163 MachineType::AnyTagged()); 1150 MachineType::AnyTagged());
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 t.Return(use); 1929 t.Return(use);
1943 t.Lower(); 1930 t.Lower();
1944 1931
1945 CHECK_EQ(d.expected, PhiRepresentationOf(phi->op())); 1932 CHECK_EQ(d.expected, PhiRepresentationOf(phi->op()));
1946 } 1933 }
1947 } 1934 }
1948 1935
1949 } // namespace compiler 1936 } // namespace compiler
1950 } // namespace internal 1937 } // namespace internal
1951 } // namespace v8 1938 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698