[llvm-commits] [llvm] r94829 - in /llvm/trunk: include/llvm/Transforms/Utils/Local.h lib/Target/README.txt lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp lib/Transforms/Scalar/GVN.cpp lib/Transforms/Utils/Local.cpp test/Transforms/InstCombine/load-select.ll

Bob Wilson bob.wilson at apple.com
Fri Jan 29 12:38:28 PST 2010


On Jan 29, 2010, at 11:52 AM, Dan Gohman wrote:

> Hi Bob,
> 
> On Jan 29, 2010, at 11:19 AM, Bob Wilson wrote:
>> 
>> +/// getUnderlyingObjectWithOffset - Strip off up to MaxLookup GEPs and
>> +/// bitcasts to get back to the underlying object being addressed, keeping
>> +/// track of the offset in bytes from the GEPs relative to the result.
>> +/// This is closely related to Value::getUnderlyingObject but is located
>> +/// here to avoid making VMCore depend on TargetData.
>> +static Value *getUnderlyingObjectWithOffset(Value *V, const TargetData *TD,
>> +                                            unsigned &ByteOffset,
> 
> Please use uint64_t for ByteOffset.

Oops.  Fixed in r94835.

> 
>> +bool llvm::isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
>> +                                       const TargetData *TD) {
>> +  unsigned ByteOffset = 0;
>> +  Value *Base = V;
>> +  if (TD)
>> +    Base = getUnderlyingObjectWithOffset(V, TD, ByteOffset);
>> +
>> +  const Type *BaseType = 0;
>> +  if (const AllocaInst *AI = dyn_cast<AllocaInst>(Base))
>> +    // If it is an alloca it is always safe to load from.
>> +    BaseType = AI->getAllocatedType();
>> +  else if (const GlobalValue *GV = dyn_cast<GlobalValue>(Base)) {
>> +    // Global variables are safe to load from but their size cannot be
>> +    // guaranteed if they are overridden.
>> +    if (!isa<GlobalAlias>(GV) && !GV->mayBeOverridden())
> 
> The check for GlobalAlias here is redundant.

Maybe.  The getUnderlyingObjectWithOffset call may fail to skip over aliases if it hits the MaxLookup limit on how deep it should go.  Even so, it might be OK but I'm not sufficiently confident to remove the check.  It was in the previous code, so I thought it best to keep it.  If you're convinced that it's safe, go ahead and take it out.



More information about the llvm-commits mailing list