From bb6cf837aa20a456c72425a754853e3f7eed6a52 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 25 Jun 2018 19:34:55 +0200 Subject: [PATCH] backport: re PR target/84899 (ICE: in final_scan_insn_1, at final.c:3139 (error: could not split insn)) Backported from mainline 2018-03-16 Jakub Jelinek PR target/84899 * postreload.c (reload_combine_recognize_pattern): Perform INTVAL addition in unsigned HOST_WIDE_INT type to avoid UB and truncate_int_for_mode the result for the destination's mode. * gcc.dg/pr84899.c: New test. From-SVN: r262079 --- gcc/ChangeLog | 7 +++++++ gcc/postreload.c | 12 +++++++----- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr84899.c | 12 ++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr84899.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 070fee57a60b..7f3b127258d3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,13 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-16 Jakub Jelinek + + PR target/84899 + * postreload.c (reload_combine_recognize_pattern): Perform + INTVAL addition in unsigned HOST_WIDE_INT type to avoid UB and + truncate_int_for_mode the result for the destination's mode. + 2018-03-15 Jakub Jelinek PR c++/79085 diff --git a/gcc/postreload.c b/gcc/postreload.c index fb5913051b1f..50935d7ac16c 100644 --- a/gcc/postreload.c +++ b/gcc/postreload.c @@ -1166,11 +1166,13 @@ reload_combine_recognize_pattern (rtx_insn *insn) value in PREV, the constant loading instruction. */ validate_change (prev, &SET_DEST (prev_set), index_reg, 1); if (reg_state[regno].offset != const0_rtx) - validate_change (prev, - &SET_SRC (prev_set), - GEN_INT (INTVAL (SET_SRC (prev_set)) - + INTVAL (reg_state[regno].offset)), - 1); + { + HOST_WIDE_INT c + = trunc_int_for_mode (UINTVAL (SET_SRC (prev_set)) + + UINTVAL (reg_state[regno].offset), + GET_MODE (index_reg)); + validate_change (prev, &SET_SRC (prev_set), GEN_INT (c), 1); + } /* Now for every use of REG that we have recorded, replace REG with REG_SUM. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a37999339732..79f69dfc9276 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ Backported from mainline 2018-03-16 Jakub Jelinek + PR target/84899 + * gcc.dg/pr84899.c: New test. + PR c++/84874 * g++.dg/cpp1z/desig8.C: New test. diff --git a/gcc/testsuite/gcc.dg/pr84899.c b/gcc/testsuite/gcc.dg/pr84899.c new file mode 100644 index 000000000000..0706fecada39 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr84899.c @@ -0,0 +1,12 @@ +/* PR target/84899 */ +/* { dg-do compile } */ +/* { dg-options "-O -funroll-all-loops -fno-move-loop-invariants" } */ + +void +foo (int x) +{ + int a = 1 / x, b = 0; + + while ((a + b + 1) < x) + b = __INT_MAX__; +} -- 2.47.2