From: Jakub Jelinek Date: Tue, 30 May 2017 07:40:21 +0000 (+0200) Subject: backport: re PR rtl-optimization/78378 (wrong code when combining shift + mult +... X-Git-Tag: releases/gcc-5.5.0~288 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdd17c3b486a427de8e92d89472530f277506138;p=thirdparty%2Fgcc.git backport: re PR rtl-optimization/78378 (wrong code when combining shift + mult + zero_extend) Backported from mainline 2016-11-16 Jakub Jelinek PR rtl-optimization/78378 * combine.c (make_extraction): Use force_to_mode for non-{REG,MEM} inner only if pos is 0. Fix up formatting. * gcc.c-torture/execute/pr78378.c: New test. From-SVN: r248623 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7772c3d7749a..0f79e4fe0417 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,12 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-11-16 Jakub Jelinek + + PR rtl-optimization/78378 + * combine.c (make_extraction): Use force_to_mode for non-{REG,MEM} + inner only if pos is 0. Fix up formatting. + 2016-11-07 Jakub Jelinek PR target/78227 diff --git a/gcc/combine.c b/gcc/combine.c index a6c134458582..936aa756eea9 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -7342,6 +7342,7 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos, if (tmode != BLKmode && ((pos_rtx == 0 && (pos % BITS_PER_WORD) == 0 && !MEM_P (inner) + && (pos == 0 || REG_P (inner)) && (inner_mode == tmode || !REG_P (inner) || TRULY_NOOP_TRUNCATION_MODES_P (tmode, inner_mode) @@ -7418,10 +7419,9 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos, } else new_rtx = force_to_mode (inner, tmode, - len >= HOST_BITS_PER_WIDE_INT - ? ~(unsigned HOST_WIDE_INT) 0 - : ((unsigned HOST_WIDE_INT) 1 << len) - 1, - 0); + len >= HOST_BITS_PER_WIDE_INT + ? ~(unsigned HOST_WIDE_INT) 0 + : ((unsigned HOST_WIDE_INT) 1 << len) - 1, 0); /* If this extraction is going into the destination of a SET, make a STRICT_LOW_PART unless we made a MEM. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74f7bfdf55d2..78d6ccf89c43 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-11-16 Jakub Jelinek + + PR rtl-optimization/78378 + * gcc.c-torture/execute/pr78378.c: New test. + 2016-11-07 Jakub Jelinek PR target/78227 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr78378.c b/gcc/testsuite/gcc.c-torture/execute/pr78378.c new file mode 100644 index 000000000000..05c1f9c771c1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr78378.c @@ -0,0 +1,18 @@ +/* PR rtl-optimization/78378 */ + +unsigned long long __attribute__ ((noinline, noclone)) +foo (unsigned long long x) +{ + x <<= 41; + x /= 232; + return 1 + (unsigned short) x; +} + +int +main () +{ + unsigned long long x = foo (1); + if (x != 0x2c24) + __builtin_abort(); + return 0; +}