[llvm-commits] [llvm] r73222 - /llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp

Frits van Bommel fvbommel at wxs.nl
Fri Jun 12 03:51:55 PDT 2009


Nick Lewycky wrote:
> +  // Check special state that is a part of some instructions.
> +  if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
> +    return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
> +           LI->getAlignment() == cast<LoadInst>(I2)->getAlignment();
> +  if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
> +    return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
> +           SI->getAlignment() == cast<StoreInst>(I2)->getAlignment();
> +  if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
> +    return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
> +  if (const CallInst *CI = dyn_cast<CallInst>(I1))
> +    return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
> +           CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
> +           CI->getAttributes().getRawPointer() ==
> +             cast<CallInst>(I2)->getAttributes().getRawPointer();
> +  if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
> +    return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
> +           CI->getAttributes().getRawPointer() ==
> +             cast<InvokeInst>(I2)->getAttributes().getRawPointer();
> +  if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1)) {
> +    if (IVI->getNumIndices() != cast<InsertValueInst>(I2)->getNumIndices())
> +      return false;
> +    for (unsigned i = 0, e = IVI->getNumIndices(); i != e; ++i)
> +      if (IVI->idx_begin()[i] != cast<InsertValueInst>(I2)->idx_begin()[i])
> +        return false;
> +    return true;
> +  }
> +  if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1)) {
> +    if (EVI->getNumIndices() != cast<ExtractValueInst>(I2)->getNumIndices())
> +      return false;
> +    for (unsigned i = 0, e = EVI->getNumIndices(); i != e; ++i)
> +      if (EVI->idx_begin()[i] != cast<ExtractValueInst>(I2)->idx_begin()[i])
> +        return false;
> +    return true;
> +  }
> +
> +  return true;
>  }

Shouldn't this have some special handling of GEPs too? A "gep {i32, i8}* %arg, 
i32 0, i32 1" is a different operation than "gep {i8, i8}* %arg, i32 0, i32 1" 
even though the types of the first operands (which are both pointers) are 
"equivalent".
(Merging GEPs should probably require that the type *pointed at* by their first 
operands are equivalent)



More information about the llvm-commits mailing list