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

Side by Side Diff: src/hydrogen-instructions.cc

Issue 22184004: Desugar bitwise negation into XOR and kill all UnaryOp stuff. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Feedback. Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 } 1148 }
1149 1149
1150 1150
1151 void HLoadFieldByIndex::PrintDataTo(StringStream* stream) { 1151 void HLoadFieldByIndex::PrintDataTo(StringStream* stream) {
1152 object()->PrintNameTo(stream); 1152 object()->PrintNameTo(stream);
1153 stream->Add(" "); 1153 stream->Add(" ");
1154 index()->PrintNameTo(stream); 1154 index()->PrintNameTo(stream);
1155 } 1155 }
1156 1156
1157 1157
1158 static bool MatchLeftIsOnes(HValue* l, HValue* r, HValue** negated) {
1159 if (!l->EqualsInteger32Constant(~0)) return false;
1160 *negated = r;
1161 return true;
1162 }
1163
1164
1165 static bool MatchNegationViaXor(HValue* instr, HValue** negated) {
1166 if (!instr->IsBitwise()) return false;
1167 HBitwise* b = HBitwise::cast(instr);
1168 return (b->op() == Token::BIT_XOR) &&
1169 (MatchLeftIsOnes(b->left(), b->right(), negated) ||
1170 MatchLeftIsOnes(b->right(), b->left(), negated));
1171 }
1172
1173
1174 static bool MatchDoubleNegation(HValue* instr, HValue** arg) {
1175 HValue* negated;
1176 return MatchNegationViaXor(instr, &negated) &&
1177 MatchNegationViaXor(negated, arg);
1178 }
1179
1180
1158 HValue* HBitwise::Canonicalize() { 1181 HValue* HBitwise::Canonicalize() {
1159 if (!representation().IsSmiOrInteger32()) return this; 1182 if (!representation().IsSmiOrInteger32()) return this;
1160 // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x. 1183 // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x.
1161 int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0; 1184 int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0;
1162 if (left()->EqualsInteger32Constant(nop_constant) && 1185 if (left()->EqualsInteger32Constant(nop_constant) &&
1163 !right()->CheckFlag(kUint32)) { 1186 !right()->CheckFlag(kUint32)) {
1164 return right(); 1187 return right();
1165 } 1188 }
1166 if (right()->EqualsInteger32Constant(nop_constant) && 1189 if (right()->EqualsInteger32Constant(nop_constant) &&
1167 !left()->CheckFlag(kUint32)) { 1190 !left()->CheckFlag(kUint32)) {
1168 return left(); 1191 return left();
1169 } 1192 }
1170 return this; 1193 // Optimize double negation, a common pattern used for ToInt32(x).
1171 } 1194 HValue* arg;
1172 1195 if (MatchDoubleNegation(this, &arg) && !arg->CheckFlag(kUint32)) {
1173 1196 return arg;
1174 HValue* HBitNot::Canonicalize() {
1175 // Optimize ~~x, a common pattern used for ToInt32(x).
1176 if (value()->IsBitNot()) {
1177 HValue* result = HBitNot::cast(value())->value();
1178 ASSERT(result->representation().IsInteger32());
1179 if (!result->CheckFlag(kUint32)) {
1180 return result;
1181 }
1182 } 1197 }
1183 return this; 1198 return this;
1184 } 1199 }
1185 1200
1186 1201
1187 static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { 1202 static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) {
1188 return arg1->representation().IsSpecialization() && 1203 return arg1->representation().IsSpecialization() &&
1189 arg2->EqualsInteger32Constant(identity); 1204 arg2->EqualsInteger32Constant(identity);
1190 } 1205 }
1191 1206
(...skipping 2928 matching lines...) Expand 10 before | Expand all | Expand 10 after
4120 break; 4135 break;
4121 case kExternalMemory: 4136 case kExternalMemory:
4122 stream->Add("[external-memory]"); 4137 stream->Add("[external-memory]");
4123 break; 4138 break;
4124 } 4139 }
4125 4140
4126 stream->Add("@%d", offset()); 4141 stream->Add("@%d", offset());
4127 } 4142 }
4128 4143
4129 } } // namespace v8::internal 4144 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698