From: Jakub Jelinek Date: Thu, 7 May 2009 15:53:11 +0000 (+0200) Subject: re PR middle-end/40057 (Incorrect right shift by 31 with long long) X-Git-Tag: releases/gcc-4.3.4~189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e546529d6f9081f7961ba4a622b22f628860135;p=thirdparty%2Fgcc.git re PR middle-end/40057 (Incorrect right shift by 31 with long long) PR middle-end/40057 * dojump.c (prefer_and_bit_test): Use immed_double_const instead of GEN_INT for 1 << bitnum. (do_jump) : Use build_int_cst_wide_type instead of build_int_cst_type. * gcc.c-torture/execute/pr40057.c: New test. From-SVN: r147245 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d3ef5bf992b..d84af7aa2e13 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2009-05-07 Jakub Jelinek + + PR middle-end/40057 + * dojump.c (prefer_and_bit_test): Use immed_double_const instead of + GEN_INT for 1 << bitnum. + (do_jump) : Use build_int_cst_wide_type instead of + build_int_cst_type. + 2009-04-29 Kaveh R. Ghazi * toplev.c (print_version): Update GMP version string calculation. diff --git a/gcc/dojump.c b/gcc/dojump.c index da11f3ae32b5..2027b70eb4a2 100644 --- a/gcc/dojump.c +++ b/gcc/dojump.c @@ -141,7 +141,8 @@ prefer_and_bit_test (enum machine_mode mode, int bitnum) } /* Fill in the integers. */ - XEXP (and_test, 1) = GEN_INT ((unsigned HOST_WIDE_INT) 1 << bitnum); + XEXP (and_test, 1) + = immed_double_const ((unsigned HOST_WIDE_INT) 1 << bitnum, 0, mode); XEXP (XEXP (shift_test, 0), 1) = GEN_INT (bitnum); return (rtx_cost (and_test, IF_THEN_ELSE) @@ -251,10 +252,10 @@ do_jump (tree exp, rtx if_false_label, rtx if_true_label) && prefer_and_bit_test (TYPE_MODE (argtype), TREE_INT_CST_LOW (shift))) { - HOST_WIDE_INT mask = (HOST_WIDE_INT) 1 - << TREE_INT_CST_LOW (shift); + unsigned HOST_WIDE_INT mask + = (unsigned HOST_WIDE_INT) 1 << TREE_INT_CST_LOW (shift); do_jump (build2 (BIT_AND_EXPR, argtype, arg, - build_int_cst_type (argtype, mask)), + build_int_cst_wide_type (argtype, mask, 0)), clr_label, set_label); break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b18a3143b2a0..4656576ae956 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-05-07 Jakub Jelinek + + PR middle-end/40057 + * gcc.c-torture/execute/pr40057.c: New test. + 2009-05-06 Janis Johnson * gcc.dg/dfp/pr39986.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr40057.c b/gcc/testsuite/gcc.c-torture/execute/pr40057.c new file mode 100644 index 000000000000..9d5c4e31e87e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr40057.c @@ -0,0 +1,37 @@ +/* PR middle-end/40057 */ + +extern void abort (void); + +__attribute__((noinline)) int +foo (unsigned long long x) +{ + unsigned long long y = (x >> 31ULL) & 1ULL; + if (y == 0ULL) + return 0; + return -1; +} + +__attribute__((noinline)) int +bar (long long x) +{ + long long y = (x >> 31LL) & 1LL; + if (y == 0LL) + return 0; + return -1; +} + +int +main (void) +{ + if (sizeof (long long) != 8) + return 0; + if (foo (0x1682a9aaaULL)) + abort (); + if (!foo (0x1882a9aaaULL)) + abort (); + if (bar (0x1682a9aaaLL)) + abort (); + if (!bar (0x1882a9aaaLL)) + abort (); + return 0; +}