[llvm-commits] [llvm] r160317 - in /llvm/trunk: lib/Support/ConstantRange.cpp unittests/Support/ConstantRangeTest.cpp

Duncan Sands baldrick at free.fr
Tue Jul 17 00:41:56 PDT 2012


Hi Nuno,

> teach ConstantRange that zero times X is always zero

while this patch is OK, the multiplication algorithm could clearly be much much
better in general.  It's astonishing (to me) that it didn't already handle the
case when one operand has only a single value (and not just when that single
value is zero).  It would be great if you could enhance it to at least handle
that case perfectly.

Ciao, Duncan.

> --- llvm/trunk/lib/Support/ConstantRange.cpp (original)
> +++ llvm/trunk/lib/Support/ConstantRange.cpp Mon Jul 16 15:47:16 2012
> @@ -537,6 +537,12 @@
>
>     if (isEmptySet() || Other.isEmptySet())
>       return ConstantRange(getBitWidth(), /*isFullSet=*/false);
> +
> +  // If any of the operands is zero, then the result is also zero.
> +  if ((getSingleElement() && *getSingleElement() == 0) ||
> +      (Other.getSingleElement() && *Other.getSingleElement() == 0))
> +    return ConstantRange(APInt(getBitWidth(), 0));
> +
>     if (isFullSet() || Other.isFullSet())
>       return ConstantRange(getBitWidth(), /*isFullSet=*/true);
>
>
> Modified: llvm/trunk/unittests/Support/ConstantRangeTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ConstantRangeTest.cpp?rev=160317&r1=160316&r2=160317&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Support/ConstantRangeTest.cpp (original)
> +++ llvm/trunk/unittests/Support/ConstantRangeTest.cpp Mon Jul 16 15:47:16 2012
> @@ -382,6 +382,14 @@
>     EXPECT_EQ(Some.multiply(Wrap), Full);
>     EXPECT_EQ(Wrap.multiply(Wrap), Full);
>
> +  ConstantRange Zero(APInt(16, 0));
> +  EXPECT_EQ(Zero.multiply(Full), Zero);
> +  EXPECT_EQ(Zero.multiply(Some), Zero);
> +  EXPECT_EQ(Zero.multiply(Wrap), Zero);
> +  EXPECT_EQ(Full.multiply(Zero), Zero);
> +  EXPECT_EQ(Some.multiply(Zero), Zero);
> +  EXPECT_EQ(Wrap.multiply(Zero), Zero);
> +
>     // http://llvm.org/PR4545
>     EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
>                   ConstantRange(APInt(4, 6), APInt(4, 2))),
>
>
> _______________________________________________
> 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