Commit df1c878e by Jakub Jelinek Committed by Jakub Jelinek

re PR middle-end/80100 (simplify-rtx.c sanitizer detects undefined behaviour with optimization)

	PR middle-end/80100
	* simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Perform
	left shift in unsigned HOST_WIDE_INT type.

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

From-SVN: r246851
parent 8585103f
2017-04-11 Jakub Jelinek <jakub@redhat.com> 2017-04-11 Jakub Jelinek <jakub@redhat.com>
PR middle-end/80100
* simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Perform
left shift in unsigned HOST_WIDE_INT type.
PR rtl-optimization/80385 PR rtl-optimization/80385
* simplify-rtx.c (simplify_unary_operation_1): Don't transform * simplify-rtx.c (simplify_unary_operation_1): Don't transform
(not (neg X)) into (plus X -1) for complex or non-integral modes. (not (neg X)) into (plus X -1) for complex or non-integral modes.
......
...@@ -2741,8 +2741,8 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, ...@@ -2741,8 +2741,8 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode,
&& CONST_INT_P (XEXP (op0, 1)) && CONST_INT_P (XEXP (op0, 1))
&& INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT) && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT)
{ {
int count = INTVAL (XEXP (op0, 1)); int count = INTVAL (XEXP (op0, 1));
HOST_WIDE_INT mask = INTVAL (trueop1) << count; HOST_WIDE_INT mask = UINTVAL (trueop1) << count;
if (mask >> count == INTVAL (trueop1) if (mask >> count == INTVAL (trueop1)
&& trunc_int_for_mode (mask, mode) == mask && trunc_int_for_mode (mask, mode) == mask
......
2017-04-11 Jakub Jelinek <jakub@redhat.com> 2017-04-11 Jakub Jelinek <jakub@redhat.com>
PR middle-end/80100
* gcc.dg/pr80100.c: New test.
PR rtl-optimization/80385 PR rtl-optimization/80385
* g++.dg/opt/pr80385.C: New test. * g++.dg/opt/pr80385.C: New test.
......
/* PR middle-end/80100 */
/* { dg-do compile } */
/* { dg-options "-O2" } */
long int
foo (long int x)
{
return 2L | ((x - 1L) >> (__SIZEOF_LONG__ * __CHAR_BIT__ - 1));
}
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