[llvm-commits] [llvm] r108687 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Chris Lattner clattner at apple.com
Mon Jul 19 09:31:00 PDT 2010


On Jul 19, 2010, at 1:09 AM, Owen Anderson wrote:

> Author: resistor
> Date: Mon Jul 19 03:09:34 2010
> New Revision: 108687
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=108687&view=rev
> Log:
> Reimplement r108639 in InstCombine rather than DAGCombine.

Thanks Owen!  Please use ->isDoubleTy() instead of comparing to Builder->getDoubleTy(), also you're trying to do "Module* M" stuff again, please use "Module *M".

One minor pedantic point is that it might not be safe to propagate the attributes from the call to sqrt to the sqrtf function declaration... you should propagate the attributes from the sqrt function declaration instead.

-Chris


> 
> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=108687&r1=108686&r2=108687&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Mon Jul 19 03:09:34 2010
> @@ -1097,6 +1097,32 @@
>       break;  
>     }
>   }
> +  
> +  // Fold (fptrunc (sqrt (fpext x))) -> (sqrtf x)
> +  // NOTE: This should be disabled by -fno-builtin-sqrt if we ever support it.
> +  CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
> +  if (Call && Call->getCalledFunction() &&
> +      Call->getCalledFunction()->getName() == "sqrt" &&
> +      Call->getNumArgOperands() == 1) {
> +    CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
> +    if (Arg && Arg->getOpcode() == Instruction::FPExt &&
> +        CI.getType() == Builder->getFloatTy() &&
> +        Call->getType() == Builder->getDoubleTy() &&
> +        Arg->getType() == Builder->getDoubleTy() &&
> +        Arg->getOperand(0)->getType() == Builder->getFloatTy()) {
> +      Module* M = CI.getParent()->getParent()->getParent();
> +      Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf", 
> +                                                   Call->getAttributes(),
> +                                                   Builder->getFloatTy(),
> +                                                   Builder->getFloatTy(),
> +                                                   NULL);
> +      CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0),
> +                                       "sqrtfcall");
> +      ret->setAttributes(Call->getAttributes());
> +      return ret;
> +    }
> +  }
> +  
>   return 0;
> }
> 
> 
> 
> _______________________________________________
> 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