[v2,07/14] LoongArch: Fix signed 32-bit overflow for loongarch32 target

Message ID 20230809115325.3716347-8-c@jia.je
State Unresolved
Headers
Series LoongArch: Add loongarch32 and ilp32 abi |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jiajie Chen Aug. 9, 2023, 11:46 a.m. UTC
  When rhs equals to 0x7fffffff, adding 1 to rhs overflows SI, generating
invalid const_int.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_emit_int_compare):
	Call trunc_int_mode to ensure valid rhs.
---
 gcc/config/loongarch/loongarch.cc | 1 +
 1 file changed, 1 insertion(+)
  

Patch

diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index c980de98758..49df9509ba9 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -4284,6 +4284,7 @@  loongarch_emit_int_compare (enum rtx_code *code, rtx *op0, rtx *op1)
 		break;
 
 	      new_rhs = rhs + (increment ? 1 : -1);
+	      new_rhs = trunc_int_for_mode (new_rhs, GET_MODE (*op0));
 	      if (loongarch_integer_cost (new_rhs)
 		    < loongarch_integer_cost (rhs))
 		{