From e9273332eff74121adf6895f138cd700e29e7d78 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Fri, 28 Feb 2014 13:07:10 +0000 Subject: [PATCH] Fixed constant folding for Math.clz32. LOG=y BUG=347906 R=yangguo@chromium.org Review URL: https://codereview.chromium.org/184353002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19609 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen-instructions.cc | 2 +- test/mjsunit/regress/regress-347906.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/mjsunit/regress/regress-347906.js diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 29d4e73cba..a35134952d 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -3955,7 +3955,7 @@ HInstruction* HUnaryMathOperation::New( case kMathFloor: return H_CONSTANT_DOUBLE(std::floor(d)); case kMathClz32: { - uint32_t i = static_cast(constant->Integer32Value()); + uint32_t i = DoubleToUint32(d); return H_CONSTANT_INT( (i == 0) ? 32 : CompilerIntrinsics::CountLeadingZeros(i)); } diff --git a/test/mjsunit/regress/regress-347906.js b/test/mjsunit/regress/regress-347906.js new file mode 100644 index 0000000000..c751618928 --- /dev/null +++ b/test/mjsunit/regress/regress-347906.js @@ -0,0 +1,14 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax --harmony + +function foo() { + return Math.clz32(12.34); +} + +foo(); +foo(); +%OptimizeFunctionOnNextCall(foo); +foo();