[llvm-commits] [llvm] r145304 - in /llvm/trunk: lib/Analysis/ValueTracking.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp test/Transforms/InstCombine/constant-fold-gep.ll

Duncan Sands baldrick at free.fr
Tue Nov 29 01:09:36 PST 2011


Hi Eli,

> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Nov 28 16:48:22 2011
> @@ -103,14 +103,16 @@
>     if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
>       unsigned Align = GV->getAlignment();
>       if (Align == 0&&  TD&&  GV->getType()->getElementType()->isSized()) {
> -      Type *ObjectType = GV->getType()->getElementType();
> -      // If the object is defined in the current Module, we'll be giving
> -      // it the preferred alignment. Otherwise, we have to assume that it
> -      // may only have the minimum ABI alignment.
> -      if (!GV->isDeclaration()&&  !GV->mayBeOverridden())
> -        Align = TD->getPrefTypeAlignment(ObjectType);
> -      else
> -        Align = TD->getABITypeAlignment(ObjectType);
> +      if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
> +        Type *ObjectType = GVar->getType()->getElementType();
> +        // If the object is defined in the current Module, we'll be giving
> +        // it the preferred alignment. Otherwise, we have to assume that it
> +        // may only have the minimum ABI alignment.
> +        if (!GVar->isDeclaration()&&  !GVar->mayBeOverridden())

I think this should use isWeakForLinker rather than mayBeOverridden.  That's
because if a copy in another translation is compiled using a different compiler
then there's no reason to think it will use anything more than the ABI
alignment.  Doing so wouldn't (for example) violate the ODR.  If anything, it
would be LLVM that is violating the ODR by bumping up the alignment of globals.

Ciao, Duncan.

> +          Align = TD->getPreferredAlignment(GVar);
> +        else
> +          Align = TD->getABITypeAlignment(ObjectType);
> +      }
>       }
>       if (Align>  0)
>         KnownZero = Mask&  APInt::getLowBitsSet(BitWidth,



More information about the llvm-commits mailing list