<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
+ if (ConstantFP *Const = dyn_cast<ConstantFP>(Val)) {<br>
+ APFloat F = Const->getValueAPF();<br>
+ bool loosesInfo;<br></blockquote><div><br></div><div>Nit: "loses".</div><div> </div><div>-eric</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ (void)F.convert(APFloat::<u></u>IEEEsingle, APFloat::rmNearestTiesToEven,<br>
+ &loosesInfo);<br></blockquote><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ if (!loosesInfo)<br>
+ return ConstantFP::get(Const-><u></u>getContext(), F);<br>
+ }<br>
+ return nullptr;<br>
+}<br>
+<br>
//===-------------------------<u></u>------------------------------<u></u>---------------===//<br>
// Double -> Float Shrinking Optimizations for Unary Functions like 'floor'<br>
<br>
@@ -1052,12 +1074,11 @@ Value *LibCallSimplifier::<u></u>optimizeUnaryD<br>
}<br>
<br>
// If this is something like 'floor((double)floatval)', convert to floorf.<br>
- FPExtInst *Cast = dyn_cast<FPExtInst>(CI-><u></u>getArgOperand(0));<br>
- if (!Cast || !Cast->getOperand(0)->getType(<u></u>)->isFloatTy())<br>
+ Value *V = valueHasFloatPrecision(CI-><u></u>getArgOperand(0));<br>
+ if (V == nullptr)<br>
return nullptr;<br>
<br>
// floor((double)floatval) -> (double)floorf(floatval)<br>
- Value *V = Cast->getOperand(0);<br>
if (Callee->isIntrinsic()) {<br>
Module *M = CI->getParent()->getParent()-><u></u>getParent();<br>
Intrinsic::ID IID = (Intrinsic::ID) Callee->getIntrinsicID();<br>
@@ -1083,21 +1104,19 @@ Value *LibCallSimplifier::<u></u>optimizeBinary<br>
return nullptr;<br>
<br>
// If this is something like 'fmin((double)floatval1, (double)floatval2)',<br>
- // we convert it to fminf.<br>
- FPExtInst *Cast1 = dyn_cast<FPExtInst>(CI-><u></u>getArgOperand(0));<br>
- FPExtInst *Cast2 = dyn_cast<FPExtInst>(CI-><u></u>getArgOperand(1));<br>
- if (!Cast1 || !Cast1->getOperand(0)-><u></u>getType()->isFloatTy() || !Cast2 ||<br>
- !Cast2->getOperand(0)-><u></u>getType()->isFloatTy())<br>
+ // or fmin(1.0, (double)floatval), then we convert it to fminf.<br>
+ Value *V1 = valueHasFloatPrecision(CI-><u></u>getArgOperand(0));<br>
+ if (V1 == nullptr)<br>
+ return nullptr;<br>
+ Value *V2 = valueHasFloatPrecision(CI-><u></u>getArgOperand(1));<br>
+ if (V2 == nullptr)<br>
return nullptr;<br>
<br>
// fmin((double)floatval1, (double)floatval2)<br>
- // -> (double)fmin(floatval1, floatval2)<br>
- Value *V = nullptr;<br>
- Value *V1 = Cast1->getOperand(0);<br>
- Value *V2 = Cast2->getOperand(0);<br>
+ // -> (double)fminf(floatval1, floatval2)<br>
// TODO: Handle intrinsics in the same way as in optimizeUnaryDoubleFP().<br>
- V = EmitBinaryFloatFnCall(V1, V2, Callee->getName(), B,<br>
- Callee->getAttributes());<br>
+ Value *V = EmitBinaryFloatFnCall(V1, V2, Callee->getName(), B,<br>
+ Callee->getAttributes());<br>
return B.CreateFPExt(V, B.getDoubleTy());<br>
}<br>
<br>
<br>
Modified: llvm/trunk/test/Transforms/<u></u>InstCombine/float-shrink-<u></u>compare.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/float-shrink-compare.ll?rev=223270&r1=223269&r2=223270&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/llvm/trunk/test/<u></u>Transforms/InstCombine/float-<u></u>shrink-compare.ll?rev=223270&<u></u>r1=223269&r2=223270&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- llvm/trunk/test/Transforms/<u></u>InstCombine/float-shrink-<u></u>compare.ll (original)<br>
+++ llvm/trunk/test/Transforms/<u></u>InstCombine/float-shrink-<u></u>compare.ll Wed Dec 3 15:46:33 2014<br>
@@ -235,6 +235,30 @@ define i32 @test19(float %x, float %y, f<br>
; CHECK-NEXT: fcmp oeq float %copysignf, %z<br>
}<br>
<br>
+define i32 @test20(float %x, float %y) nounwind uwtable {<br>
+ %1 = fpext float %y to double<br>
+ %2 = fpext float %x to double<br>
+ %3 = call double @fmin(double 1.000000e+00, double %2) nounwind<br>
+ %4 = fcmp oeq double %1, %3<br>
+ %5 = zext i1 %4 to i32<br>
+ ret i32 %5<br>
+; CHECK-LABEL: @test20(<br>
+; CHECK-NEXT: %fminf = call float @fminf(float 1.000000e+00, float %x)<br>
+; CHECK-NEXT: fcmp oeq float %fminf, %y<br>
+}<br>
+<br>
+define i32 @test21(float %x, float %y) nounwind uwtable {<br>
+ %1 = fpext float %y to double<br>
+ %2 = fpext float %x to double<br>
+ %3 = call double @fmin(double 1.300000e+00, double %2) nounwind<br>
+ %4 = fcmp oeq double %1, %3<br>
+ %5 = zext i1 %4 to i32<br>
+ ret i32 %5<br>
+; should not be changed to fminf as the constant would loose precision<br>
+; CHECK-LABEL: @test21(<br>
+; CHECK: %3 = call double @fmin(double 1.300000e+00, double %2)<br>
+}<br>
+<br>
declare double @fabs(double) nounwind readnone<br>
declare double @ceil(double) nounwind readnone<br>
declare double @copysign(double, double) nounwind readnone<br>
<br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</blockquote></div>