Hi Eli,

Could you add a regression test from the testcase in the PR, to
verify that the load is optimized out?

Thanks,

Dan

On Feb 12, 2008, at 4:08 AM, Eli Friedman wrote:

> Author: efriedma
> Date: Tue Feb 12 06:08:14 2008
> New Revision: 47006
>
> URL: http://llvm.org/viewvc/llvm-project?rev=47006&view=rev
> Log:
> Fix for bug 1996: optimize out loads of undef.  This code basically  
> just
> checks for a malloc/alloca immediately followed by a load.
>
> Modified:
>    llvm/trunk/lib/Transforms/Scalar/GVN.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=47006&r1=47005&r2=47006&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue Feb 12 06:08:14 2008
> @@ -1010,7 +1010,34 @@
>       dep = MD.getDependency(L, dep);
>     }
>   }
> -
> +
> +  if (dep != MemoryDependenceAnalysis::None &&
> +      dep != MemoryDependenceAnalysis::NonLocal &&
> +      isa<AllocationInst>(dep)) {
> +    // Check that this load is actually from the
> +    // allocation we found
> +    Value* v = L->getOperand(0);
> +    while (true) {
> +      if (BitCastInst *BC = dyn_cast<BitCastInst>(v))
> +        v = BC->getOperand(0);
> +      else if (GetElementPtrInst *GEP =  
> dyn_cast<GetElementPtrInst>(v))
> +        v = GEP->getOperand(0);
> +      else
> +        break;
> +    }
> +    if (v == dep) {
> +      // If this load depends directly on an allocation, there isn't
> +      // anything stored there; therefore, we can optimize this load
> +      // to undef.
> +      MD.removeInstruction(L);
> +
> +      L->replaceAllUsesWith(UndefValue::get(L->getType()));
> +      toErase.push_back(L);
> +      deletedLoad = true;
> +      NumGVNLoad++;
> +    }
> +  }
> +
>   if (!deletedLoad)
>     last = L;
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to