[llvm-commits] [llvm] r50174 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner clattner at apple.com
Wed Apr 23 14:38:28 PDT 2008


Very nice, thanks Dale!

-Chris

On Apr 23, 2008, at 11:34 AM, Dale Johannesen wrote:

> Author: johannes
> Date: Wed Apr 23 13:34:37 2008
> New Revision: 50174
>
> URL: http://llvm.org/viewvc/llvm-project?rev=50174&view=rev
> Log:
> Rewrite previous patch to suit Chris's preference.
>
>
> Modified:
>    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=50174&r1=50173&r2=50174&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp  
> (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Wed  
> Apr 23 13:34:37 2008
> @@ -8694,6 +8694,31 @@
>   return visitCallSite(&II);
> }
>
> +// If this cast does not affect the value passed through the varargs
> +// area, we can eliminate the use of the cast.
> +static bool isSafeToEliminateVarargsCast(const CallSite CS,
> +                                         const CastInst * const CI,
> +                                         const TargetData * const TD,
> +                                         const int ix) {
> +  if (!CI->isLosslessCast())
> +    return false;
> +
> +  // The size of ByVal arguments is derived from the type, so we
> +  // can't change to a type with a different size.  If the size were
> +  // passed explicitly we could avoid this check.
> +  if (!CS.paramHasAttr(ix, ParamAttr::ByVal))
> +    return true;
> +
> +  const Type* SrcTy =
> +            cast<PointerType>(CI->getOperand(0)->getType())- 
> >getElementType();
> +  const Type* DstTy = cast<PointerType>(CI->getType())- 
> >getElementType();
> +  if (!SrcTy->isSized() || !DstTy->isSized())
> +    return false;
> +  if (TD->getABITypeSize(SrcTy) != TD->getABITypeSize(DstTy))
> +    return false;
> +  return true;
> +}
> +
> // visitCallSite - Improvements for call and invoke instructions.
> //
> Instruction *InstCombiner::visitCallSite(CallSite CS) {
> @@ -8752,28 +8777,13 @@
>     // See if we can optimize any arguments passed through the  
> varargs area of
>     // the call.
>     for (CallSite::arg_iterator I = CS.arg_begin()+FTy- 
> >getNumParams(),
> -           E = CS.arg_end(); I != E; ++I, ++ix)
> -      if (CastInst *CI = dyn_cast<CastInst>(*I)) {
> -        // If this cast does not affect the value passed through  
> the varargs
> -        // area, we can eliminate the use of the cast.
> -        const PointerType* SrcPTy, *DstPTy;
> -        if (CI->isLosslessCast()) {
> -          // The size of ByVal arguments is derived from the type,  
> so we
> -          // can't change to a type with a different size.  If the  
> size were
> -          // passed explicitly we could avoid this check.
> -          if (CS.paramHasAttr(ix, ParamAttr::ByVal) &&
> -              (SrcPTy = cast<PointerType>(CI->getOperand(0)- 
> >getType())) &&
> -              (DstPTy = cast<PointerType>(CI->getType()))) {
> -            const Type* SrcTy = SrcPTy->getElementType();
> -            const Type* DstTy = DstPTy->getElementType();
> -            if (!SrcTy->isSized() || !DstTy->isSized() ||
> -                TD->getABITypeSize(SrcTy) != TD- 
> >getABITypeSize(DstTy))
> -              continue;
> -          }
> -          *I = CI->getOperand(0);
> -          Changed = true;
> -        }
> +           E = CS.arg_end(); I != E; ++I, ++ix) {
> +      CastInst *CI = dyn_cast<CastInst>(*I);
> +      if (CI && isSafeToEliminateVarargsCast(CS, CI, TD, ix)) {
> +        *I = CI->getOperand(0);
> +        Changed = true;
>       }
> +    }
>   }
>
>   if (isa<InlineAsm>(Callee) && !CS.doesNotThrow()) {
>
>
> _______________________________________________
> 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