Skip to content

Instantly share code, notes, and snippets.

@syg
Created February 25, 2013 21:04
Show Gist options
  • Save syg/5033287 to your computer and use it in GitHub Desktop.
Save syg/5033287 to your computer and use it in GitHub Desktop.
diff --git a/js/src/ion/MCallOptimize.cpp b/js/src/ion/MCallOptimize.cpp
index 02f4ca5..ae32a22 100644
--- a/js/src/ion/MCallOptimize.cpp
+++ b/js/src/ion/MCallOptimize.cpp
@@ -470,15 +470,23 @@ IonBuilder::inlineMathAbs(CallInfo &callInfo)
MIRType argType = getInlineArgType(callInfo, 0);
if (argType != MIRType_Int32 && argType != MIRType_Double)
return InliningStatus_NotInlined;
- if (argType != returnType)
- return InliningStatus_NotInlined;
+
+ // It is impossible for Math.abs to promote to a double on an int input,
+ // but possible to get an int output with a double input.
+ JS_ASSERT_IF(argType != returnType, returnType == MIRType_Int32);
callInfo.unwrapArgs();
- MAbs *ins = MAbs::New(callInfo.getArg(0), returnType);
+ MInstruction *ins = MAbs::New(callInfo.getArg(0), argType);
current->add(ins);
- current->push(ins);
+ if (argType != returnType) {
+ MToInt32 *toInt = MToInt32::New(ins);
+ current->add(toInt);
+ ins = toInt;
+ }
+
+ current->push(ins);
return InliningStatus_Inlined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment