Commit e8dce850 by Richard Sandiford Committed by Richard Sandiford

Fix ceil_log2(0) (PR 86644)

This PR shows a pathological case in which we try SLP vectorisation on
dead code.  We record that 0 bits of the result are enough to satisfy
all users (which is true), and that led to precision being 0 in:

static unsigned int
vect_element_precision (unsigned int precision)
{
  precision = 1 << ceil_log2 (precision);
  return MAX (precision, BITS_PER_UNIT);
}

ceil_log2 (0) returned 64 rather than 0, leading to 1 << 64, which is UB.

2018-07-25  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* hwint.c (ceil_log2): Fix comment.  Return 0 for 0.

From-SVN: r262961
parent de6c8d7f
2018-07-25 Richard Sandiford <richard.sandiford@arm.com>
* hwint.c (ceil_log2): Fix comment. Return 0 for 0.
2018-07-25 Martin Liska <mliska@suse.cz> 2018-07-25 Martin Liska <mliska@suse.cz>
PR middle-end/86645 PR middle-end/86645
......
...@@ -60,12 +60,12 @@ floor_log2 (unsigned HOST_WIDE_INT x) ...@@ -60,12 +60,12 @@ floor_log2 (unsigned HOST_WIDE_INT x)
return t; return t;
} }
/* Given X, an unsigned number, return the largest Y such that 2**Y >= X. */ /* Given X, an unsigned number, return the least Y such that 2**Y >= X. */
int int
ceil_log2 (unsigned HOST_WIDE_INT x) ceil_log2 (unsigned HOST_WIDE_INT x)
{ {
return floor_log2 (x - 1) + 1; return x == 0 ? 0 : floor_log2 (x - 1) + 1;
} }
/* Return the logarithm of X, base 2, considering X unsigned, /* Return the logarithm of X, base 2, considering X unsigned,
......
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