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

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

Issue 17093005: Revert "Improved range analysis for bitwise operations." (Closed) Base URL: https://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
« no previous file with comments | « src/hydrogen-instructions.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return ConvertAndSetOverflow(result, overflow); 282 return ConvertAndSetOverflow(result, overflow);
283 } 283 }
284 284
285 285
286 static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) { 286 static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) {
287 int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b); 287 int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b);
288 return ConvertAndSetOverflow(result, overflow); 288 return ConvertAndSetOverflow(result, overflow);
289 } 289 }
290 290
291 291
292 void Range::ToBitRange(BitRange* bits) const { 292 int32_t Range::Mask() const {
293 BitRange::SetFromRange(bits, lower_, upper_); 293 if (lower_ == upper_) return lower_;
294 if (lower_ >= 0) {
295 int32_t res = 1;
296 while (res < upper_) {
297 res = (res << 1) | 1;
298 }
299 return res;
300 }
301 return 0xffffffff;
294 } 302 }
295 303
296 304
297 void Range::AddConstant(int32_t value) { 305 void Range::AddConstant(int32_t value) {
298 if (value == 0) return; 306 if (value == 0) return;
299 bool may_overflow = false; // Overflow is ignored here. 307 bool may_overflow = false; // Overflow is ignored here.
300 lower_ = AddWithoutOverflow(lower_, value, &may_overflow); 308 lower_ = AddWithoutOverflow(lower_, value, &may_overflow);
301 upper_ = AddWithoutOverflow(upper_, value, &may_overflow); 309 upper_ = AddWithoutOverflow(upper_, value, &may_overflow);
302 #ifdef DEBUG 310 #ifdef DEBUG
303 Verify(); 311 Verify();
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2367 2375
2368 void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) { 2376 void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) {
2369 ASSERT(CheckFlag(kFlexibleRepresentation)); 2377 ASSERT(CheckFlag(kFlexibleRepresentation));
2370 Representation new_rep = RepresentationFromInputs(); 2378 Representation new_rep = RepresentationFromInputs();
2371 UpdateRepresentation(new_rep, h_infer, "inputs"); 2379 UpdateRepresentation(new_rep, h_infer, "inputs");
2372 // Do not care about uses. 2380 // Do not care about uses.
2373 } 2381 }
2374 2382
2375 2383
2376 Range* HBitwise::InferRange(Zone* zone) { 2384 Range* HBitwise::InferRange(Zone* zone) {
2377 if (representation().IsInteger32()) { 2385 if (op() == Token::BIT_XOR) {
2378 BitRange left_bits, right_bits; 2386 if (left()->HasRange() && right()->HasRange()) {
2387 // The maximum value has the high bit, and all bits below, set:
2388 // (1 << high) - 1.
2389 // If the range can be negative, the minimum int is a negative number with
2390 // the high bit, and all bits below, unset:
2391 // -(1 << high).
2392 // If it cannot be negative, conservatively choose 0 as minimum int.
2393 int64_t left_upper = left()->range()->upper();
2394 int64_t left_lower = left()->range()->lower();
2395 int64_t right_upper = right()->range()->upper();
2396 int64_t right_lower = right()->range()->lower();
2379 2397
2380 if (left()->HasRange()) { 2398 if (left_upper < 0) left_upper = ~left_upper;
2381 left()->range()->ToBitRange(&left_bits); 2399 if (left_lower < 0) left_lower = ~left_lower;
2400 if (right_upper < 0) right_upper = ~right_upper;
2401 if (right_lower < 0) right_lower = ~right_lower;
2402
2403 int high = MostSignificantBit(
2404 static_cast<uint32_t>(
2405 left_upper | left_lower | right_upper | right_lower));
2406
2407 int64_t limit = 1;
2408 limit <<= high;
2409 int32_t min = (left()->range()->CanBeNegative() ||
2410 right()->range()->CanBeNegative())
2411 ? static_cast<int32_t>(-limit) : 0;
2412 return new(zone) Range(min, static_cast<int32_t>(limit - 1));
2382 } 2413 }
2383
2384 if (right()->HasRange()) {
2385 right()->range()->ToBitRange(&right_bits);
2386 }
2387
2388 BitRange result;
2389 switch (op()) {
2390 case Token::BIT_AND:
2391 result = BitRange::And(left_bits, right_bits);
2392 break;
2393 case Token::BIT_OR:
2394 result = BitRange::Or(left_bits, right_bits);
2395 break;
2396 case Token::BIT_XOR:
2397 result = BitRange::Xor(left_bits, right_bits);
2398 break;
2399 default:
2400 UNREACHABLE();
2401 }
2402
2403 int32_t lower = kMaxInt, upper = kMinInt; // 'empty' range.
2404 result.ExtendRange(&lower, &upper);
2405 return new(zone) Range(lower, upper);
2406 } else {
2407 return HValue::InferRange(zone); 2414 return HValue::InferRange(zone);
2408 } 2415 }
2416 const int32_t kDefaultMask = static_cast<int32_t>(0xffffffff);
2417 int32_t left_mask = (left()->range() != NULL)
2418 ? left()->range()->Mask()
2419 : kDefaultMask;
2420 int32_t right_mask = (right()->range() != NULL)
2421 ? right()->range()->Mask()
2422 : kDefaultMask;
2423 int32_t result_mask = (op() == Token::BIT_AND)
2424 ? left_mask & right_mask
2425 : left_mask | right_mask;
2426 return (result_mask >= 0)
2427 ? new(zone) Range(0, result_mask)
2428 : HValue::InferRange(zone);
2409 } 2429 }
2410 2430
2411 2431
2412 Range* HSar::InferRange(Zone* zone) { 2432 Range* HSar::InferRange(Zone* zone) {
2413 if (right()->IsConstant()) { 2433 if (right()->IsConstant()) {
2414 HConstant* c = HConstant::cast(right()); 2434 HConstant* c = HConstant::cast(right());
2415 if (c->HasInteger32Value()) { 2435 if (c->HasInteger32Value()) {
2416 Range* result = (left()->range() != NULL) 2436 Range* result = (left()->range() != NULL)
2417 ? left()->range()->Copy(zone) 2437 ? left()->range()->Copy(zone)
2418 : new(zone) Range(); 2438 : new(zone) Range();
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 case kBackingStore: 3866 case kBackingStore:
3847 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); 3867 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
3848 stream->Add("[backing-store]"); 3868 stream->Add("[backing-store]");
3849 break; 3869 break;
3850 } 3870 }
3851 3871
3852 stream->Add("@%d", offset()); 3872 stream->Add("@%d", offset());
3853 } 3873 }
3854 3874
3855 } } // namespace v8::internal 3875 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | test/cctest/cctest.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698