Index: src/compiler/arm64/code-generator-arm64.cc |
diff --git a/src/compiler/arm64/code-generator-arm64.cc b/src/compiler/arm64/code-generator-arm64.cc |
index 73837a40e72646b420d13932dfec5e97fab28726..62c7278416e2da15f2cfa2c7e36cf452ede9f581 100644 |
--- a/src/compiler/arm64/code-generator-arm64.cc |
+++ b/src/compiler/arm64/code-generator-arm64.cc |
@@ -1358,12 +1358,21 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
break; |
case kArm64Float32ToInt32: |
__ Fcvtzs(i.OutputRegister32(), i.InputFloat32Register(0)); |
+ // Avoid INT32_MAX as an overflow indicator and use INT32_MIN instead, |
+ // because INT32_MIN allows easier out-of-bounds detection. |
+ __ Cmn(i.OutputRegister32(), 1); |
+ __ Csinc(i.OutputRegister32(), i.OutputRegister32(), i.OutputRegister32(), |
+ vc); |
break; |
case kArm64Float64ToInt32: |
__ Fcvtzs(i.OutputRegister32(), i.InputDoubleRegister(0)); |
break; |
case kArm64Float32ToUint32: |
__ Fcvtzu(i.OutputRegister32(), i.InputFloat32Register(0)); |
+ // Avoid UINT32_MAX as an overflow indicator and use 0 instead, |
+ // because 0 allows easier out-of-bounds detection. |
+ __ Cmn(i.OutputRegister32(), 1); |
+ __ Adc(i.OutputRegister32(), i.OutputRegister32(), Operand(0)); |
break; |
case kArm64Float64ToUint32: |
__ Fcvtzu(i.OutputRegister32(), i.InputDoubleRegister(0)); |