Index: src/compiler/mips64/code-generator-mips64.cc |
diff --git a/src/compiler/mips64/code-generator-mips64.cc b/src/compiler/mips64/code-generator-mips64.cc |
index 469824ecb37bdc9ada3c62625fe6e58361470223..95893aa92f106e42cfe0118e908fb13658d30281 100644 |
--- a/src/compiler/mips64/code-generator-mips64.cc |
+++ b/src/compiler/mips64/code-generator-mips64.cc |
@@ -1494,6 +1494,11 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
FPURegister scratch = kScratchDoubleReg; |
__ trunc_w_s(scratch, i.InputDoubleRegister(0)); |
__ mfc1(i.OutputRegister(), scratch); |
+ // Avoid INT32_MAX as an overflow indicator and use INT32_MIN instead, |
+ // because INT32_MIN allows easier out-of-bounds detection. |
+ __ addiu(kScratchReg, i.OutputRegister(), 1); |
+ __ slt(kScratchReg2, kScratchReg, i.OutputRegister()); |
+ __ Movn(i.OutputRegister(), kScratchReg, kScratchReg2); |
break; |
} |
case kMips64TruncLS: { |
@@ -1562,6 +1567,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( |
FPURegister scratch = kScratchDoubleReg; |
// TODO(plind): Fix wrong param order of Trunc_uw_d() macro-asm function. |
__ Trunc_uw_s(i.InputDoubleRegister(0), i.OutputRegister(), scratch); |
+ // Avoid UINT32_MAX as an overflow indicator and use 0 instead, |
+ // because 0 allows easier out-of-bounds detection. |
+ __ addiu(kScratchReg, i.OutputRegister(), 1); |
+ __ Movz(i.OutputRegister(), zero_reg, kScratchReg); |
break; |
} |
case kMips64TruncUlS: { |