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

Benjamin Kramer benny.kra at googlemail.com
Wed Mar 28 11:52:56 PDT 2012


On 28.03.2012, at 20:39, Duncan Sands wrote:

> 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?

That was the idea, yes.

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