[llvm] r185218 - Eliminate an assortment of undefined behavior.

Benjamin Kramer benny.kra at gmail.com
Fri Jun 28 14:28:57 PDT 2013


On 28.06.2013, at 23:10, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:

> Author: stoklund
> Date: Fri Jun 28 16:10:25 2013
> New Revision: 185218
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=185218&view=rev
> Log:
> Eliminate an assortment of undefined behavior.
> 
> Hopefully, this fixes the PPC64 buildbots.
> 
> Modified:
>    llvm/trunk/lib/Support/BlockFrequency.cpp
> 
> Modified: llvm/trunk/lib/Support/BlockFrequency.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/BlockFrequency.cpp?rev=185218&r1=185217&r2=185218&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/BlockFrequency.cpp (original)
> +++ llvm/trunk/lib/Support/BlockFrequency.cpp Fri Jun 28 16:10:25 2013
> @@ -47,9 +47,13 @@ static uint64_t div96bit(uint64_t W[2],
>   uint64_t x = W[1];
>   unsigned i;
> 
> +  // This is really a 64-bit division.
> +  if (!x)
> +    return y / D;

This should never happen if the mul overflow checking code works right. An assertion would be sufficient.

- Ben

> +
>   // This long division algorithm automatically saturates on overflow.
>   for (i = 0; i < 64 && x; ++i) {
> -    uint32_t t = (int)x >> 31;
> +    uint32_t t = -((x >> 31) & 1); // Splat bit 31 to bits 0-31.
>     x = (x << 1) | (y >> 63);
>     y = y << 1;
>     if ((x | t) >= D) {
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list