[llvm] r210439 - [SeparateConstOffsetFromGEP] Fix an illegitimate optimization on zext

David Blaikie dblaikie at gmail.com
Sun Jun 8 13:37:46 PDT 2014


Test coverage?

On Sun, Jun 8, 2014 at 1:19 PM, Jingyue Wu <jingyue at google.com> wrote:
> Author: jingyue
> Date: Sun Jun  8 15:19:38 2014
> New Revision: 210439
>
> URL: http://llvm.org/viewvc/llvm-project?rev=210439&view=rev
> Log:
> [SeparateConstOffsetFromGEP] Fix an illegitimate optimization on zext
>
> zext(a + b) != zext(a) + zext(b) even if a + b >= 0 && b >= 0.
>
> e.g., a = i4 0b1111, b = i4 0b0001
> zext a + b to i8 = zext 0b0000 to i8 = 0b00000000
> (zext a to i8) + (zext b to i8) = 0b00001111 + 0b00000001 = 0b00010000
>
> Modified:
>     llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp?rev=210439&r1=210438&r2=210439&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp Sun Jun  8 15:19:38 2014
> @@ -321,9 +321,9 @@ bool ConstantOffsetExtractor::CanTraceIn
>    //       1       |      0       | sext(BO) == sext(A) op sext(B)
>    //       1       |      1       | zext(sext(BO)) ==
>    //               |              |     zext(sext(A)) op zext(sext(B))
> -  if (BO->getOpcode() == Instruction::Add && NonNegative) {
> +  if (BO->getOpcode() == Instruction::Add && !ZeroExtended && NonNegative) {
>      // If a + b >= 0 and (a >= 0 or b >= 0), then
> -    //   s/zext(a + b) = s/zext(a) + s/zext(b)
> +    //   sext(a + b) = sext(a) + sext(b)
>      // even if the addition is not marked nsw.
>      //
>      // Leveraging this invarient, we can trace into an sext'ed inbound GEP
>
>
> _______________________________________________
> 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