Commit ceed6e67 by Jakub Jelinek

re PR middle-end/61158 (negative shift at fold-const.c:12095)

	PR tree-optimization/61158
	* fold-const.c (fold_binary_loc): If X is zero-extended and
	shiftc >= prec, make sure zerobits is all ones instead of
	invoking undefined behavior.

	* gcc.dg/pr61158.c: New test.

From-SVN: r210467
parent a2555c65
2014-05-15 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/61158
* fold-const.c (fold_binary_loc): If X is zero-extended and
shiftc >= prec, make sure zerobits is all ones instead of
invoking undefined behavior.
2014-05-15 Zhenqiang Chen <zhenqiang.chen@linaro.org> 2014-05-15 Zhenqiang Chen <zhenqiang.chen@linaro.org>
* regcprop.h: New file. * regcprop.h: New file.
* regcprop.c (skip_debug_insn_p): New decl. * regcprop.c (skip_debug_insn_p): New decl.
(replace_oldest_value_reg): Check skip_debug_insn_p. (replace_oldest_value_reg): Check skip_debug_insn_p.
(copyprop_hardreg_forward_bb_without_debug_insn.): New function. (copyprop_hardreg_forward_bb_without_debug_insn): New function.
* shrink-wrap.c: include regcprop.h * shrink-wrap.c: Include regcprop.h.
(prepare_shrink_wrap): (prepare_shrink_wrap): Call
Call copyprop_hardreg_forward_bb_without_debug_insn. copyprop_hardreg_forward_bb_without_debug_insn.
2014-05-15 Zhenqiang Chen <zhenqiang.chen@linaro.org> 2014-05-15 Zhenqiang Chen <zhenqiang.chen@linaro.org>
......
...@@ -11972,11 +11972,17 @@ fold_binary_loc (location_t loc, ...@@ -11972,11 +11972,17 @@ fold_binary_loc (location_t loc,
/* See if we can shorten the right shift. */ /* See if we can shorten the right shift. */
if (shiftc < prec) if (shiftc < prec)
shift_type = inner_type; shift_type = inner_type;
/* Otherwise X >> C1 is all zeros, so we'll optimize
it into (X, 0) later on by making sure zerobits
is all ones. */
} }
} }
zerobits = ~(unsigned HOST_WIDE_INT) 0; zerobits = ~(unsigned HOST_WIDE_INT) 0;
zerobits >>= HOST_BITS_PER_WIDE_INT - shiftc; if (shiftc < prec)
zerobits <<= prec - shiftc; {
zerobits >>= HOST_BITS_PER_WIDE_INT - shiftc;
zerobits <<= prec - shiftc;
}
/* For arithmetic shift if sign bit could be set, zerobits /* For arithmetic shift if sign bit could be set, zerobits
can contain actually sign bits, so no transformation is can contain actually sign bits, so no transformation is
possible, unless MASK masks them all away. In that possible, unless MASK masks them all away. In that
...@@ -11994,7 +12000,7 @@ fold_binary_loc (location_t loc, ...@@ -11994,7 +12000,7 @@ fold_binary_loc (location_t loc,
/* ((X << 16) & 0xff00) is (X, 0). */ /* ((X << 16) & 0xff00) is (X, 0). */
if ((mask & zerobits) == mask) if ((mask & zerobits) == mask)
return omit_one_operand_loc (loc, type, return omit_one_operand_loc (loc, type,
build_int_cst (type, 0), arg0); build_int_cst (type, 0), arg0);
newmask = mask | zerobits; newmask = mask | zerobits;
if (newmask != mask && (newmask & (newmask + 1)) == 0) if (newmask != mask && (newmask & (newmask + 1)) == 0)
......
2014-05-15 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/61158
* gcc.dg/pr61158.c: New test.
2014-05-15 Andreas Schwab <schwab@suse.de> 2014-05-15 Andreas Schwab <schwab@suse.de>
* obj-c++.dg/exceptions-3.mm: Remove check for message no longer * obj-c++.dg/exceptions-3.mm: Remove check for message no longer
......
/* PR tree-optimization/61158 */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-original" } */
unsigned long long
foo (unsigned int x)
{
return ((unsigned long long) x & 0x00ff000000000000ULL) >> 40;
}
/* { dg-final { scan-tree-dump "return 0;" "original" { target { ilp32 || lp64 } } } } */
/* { dg-final { cleanup-tree-dump "original" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment