From 73ba6c712005892fbddb3e4dd7160d218e1b8c50 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 2 Mar 2019 09:05:10 +0100 Subject: [PATCH] re PR target/89506 (ICE: in decompose, at rtl.h:2266 with -Og -g) PR target/89506 * config/arm/arm.md (cmpsi2_addneg): Use trunc_int_for_mode (-INTVAL (...), SImode) instead of -INTVAL (...). If operands[2] is 0 or INT_MIN, force use of subs. (*compare_scc splitter): Use gen_int_mode. (*negscc): Likewise. * config/arm/thumb2.md (*thumb2_negscc): Likewise. * gcc.dg/pr89506.c: New test. From-SVN: r269339 --- gcc/ChangeLog | 10 ++++++++++ gcc/config/arm/arm.md | 24 ++++++++++++++++++------ gcc/config/arm/thumb2.md | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr89506.c | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr89506.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 96693d336fa..e9b681fb2eb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-03-02 Jakub Jelinek + + PR target/89506 + * config/arm/arm.md (cmpsi2_addneg): Use + trunc_int_for_mode (-INTVAL (...), SImode) instead of -INTVAL (...). + If operands[2] is 0 or INT_MIN, force use of subs. + (*compare_scc splitter): Use gen_int_mode. + (*negscc): Likewise. + * config/arm/thumb2.md (*thumb2_negscc): Likewise. + 2019-03-01 Kito Cheng Monk Chiang diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 8668937ac5a..7ee83a599f8 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -867,10 +867,21 @@ (set (match_operand:SI 0 "s_register_operand" "=r,r") (plus:SI (match_dup 1) (match_operand:SI 3 "arm_addimm_operand" "I,L")))] - "TARGET_32BIT && INTVAL (operands[2]) == -INTVAL (operands[3])" - "@ - adds%?\\t%0, %1, %3 - subs%?\\t%0, %1, #%n3" + "TARGET_32BIT + && (INTVAL (operands[2]) + == trunc_int_for_mode (-INTVAL (operands[3]), SImode))" +{ + /* For 0 and INT_MIN it is essential that we use subs, as adds + will result in different condition codes (like cmn rather than + like cmp). For other immediates, we should choose whatever + will have smaller encoding. */ + if (operands[2] == const0_rtx + || INTVAL (operands[2]) == -HOST_WIDE_INT_C (0x80000000) + || which_alternative == 1) + return "subs%?\\t%0, %1, #%n3"; + else + return "adds%?\\t%0, %1, %3"; +} [(set_attr "conds" "set") (set_attr "type" "alus_sreg")] ) @@ -9302,7 +9313,7 @@ (cond_exec (ne:CC (reg:CC CC_REGNUM) (const_int 0)) (set (match_dup 0) (const_int 1)))] { - operands[3] = GEN_INT (-INTVAL (operands[2])); + operands[3] = gen_int_mode (-INTVAL (operands[2]), SImode); }) (define_split @@ -10082,7 +10093,8 @@ /* Emit subs\\t%0, %1, %2\;mvnne\\t%0, #0 */ if (CONST_INT_P (operands[2])) emit_insn (gen_cmpsi2_addneg (operands[0], operands[1], operands[2], - GEN_INT (- INTVAL (operands[2])))); + gen_int_mode (-INTVAL (operands[2]), + SImode))); else emit_insn (gen_subsi3_compare (operands[0], operands[1], operands[2])); diff --git a/gcc/config/arm/thumb2.md b/gcc/config/arm/thumb2.md index 111692466d1..b283a7b6565 100644 --- a/gcc/config/arm/thumb2.md +++ b/gcc/config/arm/thumb2.md @@ -913,7 +913,8 @@ /* Emit subs\\t%0, %1, %2\;it\\tne\;mvnne\\t%0, #0 */ if (CONST_INT_P (operands[2])) emit_insn (gen_cmpsi2_addneg (operands[0], operands[1], operands[2], - GEN_INT (- INTVAL (operands[2])))); + gen_int_mode (-INTVAL (operands[2]), + SImode))); else emit_insn (gen_subsi3_compare (operands[0], operands[1], operands[2])); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 53da7a94ea0..8701bc1d642 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-02 Jakub Jelinek + + PR target/89506 + * gcc.dg/pr89506.c: New test. + 2019-03-01 Kito Cheng Monk Chiang diff --git a/gcc/testsuite/gcc.dg/pr89506.c b/gcc/testsuite/gcc.dg/pr89506.c new file mode 100644 index 00000000000..2ec4f32118a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr89506.c @@ -0,0 +1,14 @@ +/* PR target/89506 */ +/* { dg-do compile } */ +/* { dg-options "-Og -g -w" } */ + +long long a; +int c; + +int +foo (long long d, short e) +{ + __builtin_sub_overflow (0xffffffff, c, &a); + e >>= ~2147483647 != (int) a; + return d + e; +} -- 2.30.2