[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

Dan Gohman gohman at apple.com
Fri Jan 29 11:52:04 PST 2010


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.

> +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.

Dan





More information about the llvm-commits mailing list