[llvm] r174555 - Signficantly generalize our ability to constant fold floating point intrinsics, including ones on half types.
Nick Lewycky
nlewycky at google.com
Wed Feb 6 15:43:10 PST 2013
On 6 February 2013 14:43, Owen Anderson <resistor at mac.com> wrote:
> Author: resistor
> Date: Wed Feb 6 16:43:31 2013
> New Revision: 174555
>
> URL: http://llvm.org/viewvc/llvm-project?rev=174555&view=rev
> Log:
> Signficantly generalize our ability to constant fold floating point
> intrinsics, including ones on half types.
>
> Added:
> llvm/trunk/test/Transforms/ConstProp/half.ll
> Modified:
> llvm/trunk/lib/Analysis/ConstantFolding.cpp
>
> Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=174555&r1=174554&r2=174555&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
> +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Wed Feb 6 16:43:31 2013
> [...]
@@ -1241,8 +1266,36 @@ llvm::ConstantFoldCall(Function *F, Arra
> /// the host native double versions. Float versions are not called
> /// directly but for all these it is true (float)(f((double)arg)) ==
> /// f(arg). Long double not supported yet.
> - double V = Ty->isFloatTy() ?
> (double)Op->getValueAPF().convertToFloat() :
> - Op->getValueAPF().convertToDouble();
> + double V;
> + if (Ty->isFloatTy())
> + V = Op->getValueAPF().convertToFloat();
> + else if (Ty->isDoubleTy())
> + V = Op->getValueAPF().convertToDouble();
> + else {
> + bool unused;
> + APFloat APF = Op->getValueAPF();
> + APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
> &unused);
> + V = APF.convertToDouble();
> + }
> +
> + switch (F->getIntrinsicID()) {
> + default: break;
> + case Intrinsic::fabs:
> + return ConstantFoldFP(fabs, V, Ty);
> + case Intrinsic::log2:
> + return ConstantFoldFP(log2, V, Ty);
> + case Intrinsic::log:
> + return ConstantFoldFP(log, V, Ty);
> + case Intrinsic::log10:
> + return ConstantFoldFP(log10, V, Ty);
> + case Intrinsic::exp:
> + return ConstantFoldFP(exp, V, Ty);
> + case Intrinsic::exp2:
> + return ConstantFoldFP(exp2, V, Ty);
> + case Intrinsic::floor:
> + return ConstantFoldFP(floor, V, Ty);
> + }
>
Owen, could we instead trend in the direction of reducing our dependence on
the native system's libm calls? I don't want things which can cause
different IR on different host systems. I didn't realize we were even doing
this.
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130206/31d023f4/attachment.html>
More information about the llvm-commits
mailing list