[llvm-commits] [llvm] r153576 - in /llvm/trunk: lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/zeroinitializer-gep-load.ll

Duncan Sands baldrick at free.fr
Wed Mar 28 11:39:29 PDT 2012


Hi Benjamin,

> GlobalOpt: If we have an inbounds GEP from a ConstantAggregateZero global that we just determined to be constant, replace all loads from it with a zero value.

> --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Wed Mar 28 09:50:09 2012
> @@ -341,6 +341,12 @@
>             dyn_cast_or_null<ConstantExpr>(ConstantFoldInstruction(GEP, TD, TLI));
>           if (Init&&  CE&&  CE->getOpcode() == Instruction::GetElementPtr)
>             SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE);
> +
> +        // If the initializer is an all-null value and we have an inbounds GEP,
> +        // we already know what the result of any load from that GEP is.

the load might load off the end of the struct.  However I'm presuming in that
case that you are reasoning: any extra values loaded are undefined, so we may
as well say that they are zero?

Ciao, Duncan.

> +        // TODO: Handle splats.
> +        if (Init&&  isa<ConstantAggregateZero>(Init)&&  GEP->isInBounds())
> +          SubInit = Constant::getNullValue(GEP->getType()->getElementType());
>         }
>         Changed |= CleanupConstantGlobalUsers(GEP, SubInit, TD, TLI);



More information about the llvm-commits mailing list