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

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

Issue 9156001: Improved range analysis for bitwise operations. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 6 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 return ConvertAndSetOverflow(result, overflow); 278 return ConvertAndSetOverflow(result, overflow);
279 } 279 }
280 280
281 281
282 static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) { 282 static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) {
283 int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b); 283 int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b);
284 return ConvertAndSetOverflow(result, overflow); 284 return ConvertAndSetOverflow(result, overflow);
285 } 285 }
286 286
287 287
288 int32_t Range::Mask() const { 288 void Range::ToBitRange(BitRange* bits) const {
289 if (lower_ == upper_) return lower_; 289 BitRange::SetFromRange(bits, lower_, upper_);
290 if (lower_ >= 0) {
291 int32_t res = 1;
292 while (res < upper_) {
293 res = (res << 1) | 1;
294 }
295 return res;
296 }
297 return 0xffffffff;
298 } 290 }
299 291
300 292
301 void Range::AddConstant(int32_t value) { 293 void Range::AddConstant(int32_t value) {
302 if (value == 0) return; 294 if (value == 0) return;
303 bool may_overflow = false; // Overflow is ignored here. 295 bool may_overflow = false; // Overflow is ignored here.
304 lower_ = AddWithoutOverflow(lower_, value, &may_overflow); 296 lower_ = AddWithoutOverflow(lower_, value, &may_overflow);
305 upper_ = AddWithoutOverflow(upper_, value, &may_overflow); 297 upper_ = AddWithoutOverflow(upper_, value, &may_overflow);
306 #ifdef DEBUG 298 #ifdef DEBUG
307 Verify(); 299 Verify();
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 2332
2341 void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) { 2333 void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) {
2342 ASSERT(CheckFlag(kFlexibleRepresentation)); 2334 ASSERT(CheckFlag(kFlexibleRepresentation));
2343 Representation new_rep = RepresentationFromInputs(); 2335 Representation new_rep = RepresentationFromInputs();
2344 UpdateRepresentation(new_rep, h_infer, "inputs"); 2336 UpdateRepresentation(new_rep, h_infer, "inputs");
2345 // Do not care about uses. 2337 // Do not care about uses.
2346 } 2338 }
2347 2339
2348 2340
2349 Range* HBitwise::InferRange(Zone* zone) { 2341 Range* HBitwise::InferRange(Zone* zone) {
2342 /*
2350 if (op() == Token::BIT_XOR) { 2343 if (op() == Token::BIT_XOR) {
2351 if (left()->HasRange() && right()->HasRange()) { 2344 if (left()->HasRange() && right()->HasRange()) {
2352 // The maximum value has the high bit, and all bits below, set: 2345 // The maximum value has the high bit, and all bits below, set:
2353 // (1 << high) - 1. 2346 // (1 << high) - 1.
2354 // If the range can be negative, the minimum int is a negative number with 2347 // If the range can be negative, the minimum int is a negative number with
2355 // the high bit, and all bits below, unset: 2348 // the high bit, and all bits below, unset:
2356 // -(1 << high). 2349 // -(1 << high).
2357 // If it cannot be negative, conservatively choose 0 as minimum int. 2350 // If it cannot be negative, conservatively choose 0 as minimum int.
2358 int64_t left_upper = left()->range()->upper(); 2351 int64_t left_upper = left()->range()->upper();
2359 int64_t left_lower = left()->range()->lower(); 2352 int64_t left_lower = left()->range()->lower();
(...skipping 24 matching lines...) Expand all
2384 : kDefaultMask; 2377 : kDefaultMask;
2385 int32_t right_mask = (right()->range() != NULL) 2378 int32_t right_mask = (right()->range() != NULL)
2386 ? right()->range()->Mask() 2379 ? right()->range()->Mask()
2387 : kDefaultMask; 2380 : kDefaultMask;
2388 int32_t result_mask = (op() == Token::BIT_AND) 2381 int32_t result_mask = (op() == Token::BIT_AND)
2389 ? left_mask & right_mask 2382 ? left_mask & right_mask
2390 : left_mask | right_mask; 2383 : left_mask | right_mask;
2391 return (result_mask >= 0) 2384 return (result_mask >= 0)
2392 ? new(zone) Range(0, result_mask) 2385 ? new(zone) Range(0, result_mask)
2393 : HValue::InferRange(zone); 2386 : HValue::InferRange(zone);
2387 */
fschneider 2013/06/11 10:22:37 Remove commented code.
sra1 2013/06/12 00:12:24 Done.
2388 if (representation().IsInteger32()) {
2389 BitRange left_bits, right_bits;
2390
2391 if (left()->range() != NULL)
Toon Verwaest 2013/06/11 12:47:46 if (left()->HasRange()) { ... }
sra1 2013/06/12 00:12:24 Done.
2392 left()->range()->ToBitRange(&left_bits);
2393
2394 if (right()->range() != NULL)
2395 right()->range()->ToBitRange(&right_bits);
2396
2397 BitRange result;
2398 switch (op()) {
2399 case Token::BIT_AND:
2400 result = BitRange::And(left_bits, right_bits);
2401 break;
2402 case Token::BIT_OR:
2403 result = BitRange::Or(left_bits, right_bits);
2404 break;
2405 case Token::BIT_XOR:
2406 result = BitRange::Xor(left_bits, right_bits);
2407 break;
2408 default:
2409 UNREACHABLE();
2410 }
2411
2412 int32_t lower = kMaxInt, upper = kMinInt; // 'empty' range.
2413 result.ExtendRange(&lower, &upper);
2414 return new(zone) Range(lower, upper);
2415 } else {
2416 return HValue::InferRange(zone);
2417 }
2394 } 2418 }
2395 2419
2396 2420
2397 Range* HSar::InferRange(Zone* zone) { 2421 Range* HSar::InferRange(Zone* zone) {
2398 if (right()->IsConstant()) { 2422 if (right()->IsConstant()) {
2399 HConstant* c = HConstant::cast(right()); 2423 HConstant* c = HConstant::cast(right());
2400 if (c->HasInteger32Value()) { 2424 if (c->HasInteger32Value()) {
2401 Range* result = (left()->range() != NULL) 2425 Range* result = (left()->range() != NULL)
2402 ? left()->range()->Copy(zone) 2426 ? left()->range()->Copy(zone)
2403 : new(zone) Range(); 2427 : new(zone) Range();
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
3839 case kBackingStore: 3863 case kBackingStore:
3840 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); 3864 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
3841 stream->Add("[backing-store]"); 3865 stream->Add("[backing-store]");
3842 break; 3866 break;
3843 } 3867 }
3844 3868
3845 stream->Add("@%d", offset()); 3869 stream->Add("@%d", offset());
3846 } 3870 }
3847 3871
3848 } } // namespace v8::internal 3872 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698