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

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

Issue 16268009: Infer the range of Math.abs (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Jakob's comments 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') | no next file » | 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 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 case kMathExp: return "exp"; 1301 case kMathExp: return "exp";
1302 case kMathSqrt: return "sqrt"; 1302 case kMathSqrt: return "sqrt";
1303 case kMathPowHalf: return "pow-half"; 1303 case kMathPowHalf: return "pow-half";
1304 default: 1304 default:
1305 UNREACHABLE(); 1305 UNREACHABLE();
1306 return NULL; 1306 return NULL;
1307 } 1307 }
1308 } 1308 }
1309 1309
1310 1310
1311 Range* HUnaryMathOperation::InferRange(Zone* zone) {
1312 Representation r = representation();
1313 if (r.IsSmiOrInteger32() && value()->HasRange()) {
1314 if (op() == kMathAbs) {
1315 int upper = value()->range()->upper();
1316 int lower = value()->range()->lower();
1317 bool spans_zero = value()->range()->CanBeZero();
1318 // Math.abs(kMinInt) overflows its representation, on which the
1319 // instruction deopts. Hence clamp it to kMaxInt.
1320 int abs_lower = lower == kMinInt ? kMaxInt : abs(kMinInt);
Jakob Kummerow 2013/06/07 09:02:33 I think you need to do this same trick for abs_upp
1321 Range* result =
1322 new(zone) Range(spans_zero ? 0 : Min(abs_lower, abs(upper)),
1323 Max(abs_lower, abs(upper)));
1324 // In case of Smi representation, clamp Math.abs(Smi::kMinValue) to
1325 // Smi::kMaxValue.
1326 if (r.IsSmi()) result->ClampToSmi();
1327 return result;
1328 }
1329 }
1330 return HValue::InferRange(zone);
1331 }
1332
1333
1311 void HUnaryMathOperation::PrintDataTo(StringStream* stream) { 1334 void HUnaryMathOperation::PrintDataTo(StringStream* stream) {
1312 const char* name = OpName(); 1335 const char* name = OpName();
1313 stream->Add("%s ", name); 1336 stream->Add("%s ", name);
1314 value()->PrintNameTo(stream); 1337 value()->PrintNameTo(stream);
1315 } 1338 }
1316 1339
1317 1340
1318 void HUnaryOperation::PrintDataTo(StringStream* stream) { 1341 void HUnaryOperation::PrintDataTo(StringStream* stream) {
1319 value()->PrintNameTo(stream); 1342 value()->PrintNameTo(stream);
1320 } 1343 }
(...skipping 2483 matching lines...) Expand 10 before | Expand all | Expand 10 after
3804 case kBackingStore: 3827 case kBackingStore:
3805 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); 3828 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
3806 stream->Add("[backing-store]"); 3829 stream->Add("[backing-store]");
3807 break; 3830 break;
3808 } 3831 }
3809 3832
3810 stream->Add("@%d", offset()); 3833 stream->Add("@%d", offset());
3811 } 3834 }
3812 3835
3813 } } // namespace v8::internal 3836 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698