[llvm-commits] [llvm] r122236 - in /llvm/trunk: lib/Transforms/Utils/InlineFunction.cpp test/Transforms/Inline/byval.ll

Frits van Bommel fvbommel at gmail.com
Mon Dec 20 03:33:43 PST 2010


On Mon, Dec 20, 2010 at 9:10 AM, Chris Lattner <sabre at nondot.org> wrote:
> +    // See if the argument is a (bitcasted) pointer to an alloca.  If so, we can
> +    // round up the alloca if needed.
> +    if (AllocaInst *AI = dyn_cast<AllocaInst>(Arg->stripPointerCasts())) {
> +      unsigned AIAlign = AI->getAlignment();
> +
> +      // If the alloca is known at least aligned as much as the byval, we can do
> +      // this optimization.
> +      if (AIAlign >= ByValAlignment)
> +        return Arg;
> +
> +      // If the alloca has a specified alignment that is less than the byval,
> +      // then we can safely bump it up.
> +      if (AIAlign) {
> +        AI->setAlignment(ByValAlignment);
> +        return Arg;
> +      }
> +
> +      // If the alignment has an unspecified alignment, then we can only modify
> +      // it if we have TD information.  Doing so without TD info could end up
> +      // with us rounding the alignment *down* accidentally, which is badness.
> +      if (IFI.TD) {
> +        AIAlign = std::max(ByValAlignment, IFI.TD->getPrefTypeAlignment(AggTy));
> +        AI->setAlignment(AIAlign);
> +        return Arg;
> +      }
> +    }

-instcombine has a method that does much the same thing, except more
aggressively, in InstCombineCalls.cpp
(InstCombiner::GetOrEnforceKnownAlignment()).
Maybe this should be factored out and placed somewhere in
Transforms/Util/ so it can be used here too?

Then you could replace the quoted code with:
  if (GetOrEnforceKnownAlignment(Arg, ByValAlignment) >= ByValAlignment)
    return Arg;




More information about the llvm-commits mailing list