* Fix ceil_log2(0) (PR 86644)
@ 2018-07-24 18:11 Richard Sandiford
2018-07-24 21:11 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2018-07-24 18:11 UTC (permalink / raw)
To: gcc-patches
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.
Tested on aarch64-linux-gnu, aarch64_be-elf and x86_64-linux-gnu.
OK to install?
Richard
2018-07-24 Richard Sandiford <richard.sandiford@arm.com>
gcc/
* hwint.c (ceil_log2): Fix comment. Return 0 for 0.
Index: gcc/hwint.c
===================================================================
--- gcc/hwint.c 2018-05-02 08:38:14.433364094 +0100
+++ gcc/hwint.c 2018-07-24 19:09:03.522774662 +0100
@@ -60,12 +60,12 @@ floor_log2 (unsigned HOST_WIDE_INT x)
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
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,
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Fix ceil_log2(0) (PR 86644)
2018-07-24 18:11 Fix ceil_log2(0) (PR 86644) Richard Sandiford
@ 2018-07-24 21:11 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2018-07-24 21:11 UTC (permalink / raw)
To: gcc-patches, richard.sandiford
On 07/24/2018 12:11 PM, Richard Sandiford wrote:
> 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.
>
> Tested on aarch64-linux-gnu, aarch64_be-elf and x86_64-linux-gnu.
> OK to install?
>
> Richard
>
>
> 2018-07-24 Richard Sandiford <richard.sandiford@arm.com>
>
> gcc/
> * hwint.c (ceil_log2): Fix comment. Return 0 for 0.
OK
Jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-24 21:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-24 18:11 Fix ceil_log2(0) (PR 86644) Richard Sandiford
2018-07-24 21:11 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).