From: Jeff Law Date: Tue, 29 Sep 2015 16:41:38 +0000 (-0600) Subject: [PATCH] Fix undefined behaviour in SH port X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e3ed8bb71018bc92b495c1ee3f897d1a3b7ff886;p=gcc.git [PATCH] Fix undefined behaviour in SH port * config/sh/sh.c (gen_shl_and): Fix undefined left shift behaviour. (gen_shl_sext): Likewise. * config/sh/sh.md (divsi3): Likewise. (imm->ext_dest_operand splitter): Likewise. From-SVN: r228257 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 49932412919..87de440f2a8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-09-29 Jeff Law + + * config/sh/sh.c (gen_shl_and): Fix undefined left shift + behaviour. + (gen_shl_sext): Likewise. + * config/sh/sh.md (divsi3): Likewise. + (imm->ext_dest_operand splitter): Likewise. + 2015-09-29 Sebastian Pop Aditya Kumar diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c index 16fb57595d2..904201b22b0 100644 --- a/gcc/config/sh/sh.c +++ b/gcc/config/sh/sh.c @@ -4342,7 +4342,7 @@ gen_shl_and (rtx dest, rtx left_rtx, rtx mask_rtx, rtx source) that don't matter. This way, we might be able to get a shorter signed constant. */ if (mask & ((HOST_WIDE_INT) 1 << (31 - total_shift))) - mask |= (HOST_WIDE_INT) ~0 << (31 - total_shift); + mask |= (HOST_WIDE_INT) ((HOST_WIDE_INT_M1U) << (31 - total_shift)); case 2: /* Don't expand fine-grained when combining, because that will make the pattern fail. */ @@ -4626,7 +4626,7 @@ gen_shl_sext (rtx dest, rtx left_rtx, rtx size_rtx, rtx source) } emit_insn (gen_andsi3 (dest, source, GEN_INT ((1 << insize) - 1))); emit_insn (gen_xorsi3 (dest, dest, GEN_INT (1 << (insize - 1)))); - emit_insn (gen_addsi3 (dest, dest, GEN_INT (-1 << (insize - 1)))); + emit_insn (gen_addsi3 (dest, dest, GEN_INT (HOST_WIDE_INT_M1U << (insize - 1)))); operands[0] = dest; operands[2] = kind == 7 ? GEN_INT (left + 1) : left_rtx; gen_shifty_op (ASHIFT, operands); diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md index 8a388bc6b69..d758e3bf5f8 100644 --- a/gcc/config/sh/sh.md +++ b/gcc/config/sh/sh.md @@ -3052,7 +3052,7 @@ tab_base = force_reg (DImode, tab_base); } if (TARGET_DIVIDE_INV20U) - i2p27 = force_reg (DImode, GEN_INT (-2 << 27)); + i2p27 = force_reg (DImode, GEN_INT ((unsigned HOST_WIDE_INT)-2 << 27)); else i2p27 = GEN_INT (0); if (TARGET_DIVIDE_INV20U || TARGET_DIVIDE_INV20L) @@ -7875,7 +7875,7 @@ label: break; } /* Try movi / mshflo.l w/ r63. */ - val2 = val + ((HOST_WIDE_INT) -1 << 32); + val2 = val + ((HOST_WIDE_INT) (HOST_WIDE_INT_M1U << 32)); if ((HOST_WIDE_INT) val2 < 0 && CONST_OK_FOR_I16 (val2)) { operands[1] = gen_mshflo_l_di (operands[0], operands[0],