<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jun 16, 2015 at 2:09 AM Sean Silva <<a href="mailto:chisophugis@gmail.com">chisophugis@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jun 14, 2015 at 11:53 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: d0k<br>
Date: Sun Jun 14 13:53:58 2015<br>
New Revision: 239701<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239701-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=vm34Rc9BakeAxzLkXH73VrK8ZlYsPtkHJ8UJJt48ePQ&s=d_2AYe8qWVEETva_YYdR9hMrsl0cnEdrYQ7CILlodeE&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=239701&view=rev</a><br>
Log:<br>
[InstSimplify] Add self-fdiv identities for -ffinite-math-only.<br>
<br>
When NaNs and Infs are ignored we can fold<br>
X / X -> 1.0<br>
-X / X -> -1.0<br>
X / -X -> -1.0<br>
<br>
Modified:<br>
llvm/trunk/lib/Analysis/InstructionSimplify.cpp<br>
llvm/trunk/test/Transforms/InstSimplify/fast-math.ll<br>
<br>
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Analysis_InstructionSimplify.cpp-3Frev-3D239701-26r1-3D239700-26r2-3D239701-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=vm34Rc9BakeAxzLkXH73VrK8ZlYsPtkHJ8UJJt48ePQ&s=i1WfnEAz3oC1JwUq2K_aJ6tSxkqQh2Zq4Ai6VFM2fCI&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=239701&r1=239700&r2=239701&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Jun 14 13:53:58 2015<br>
@@ -1126,6 +1126,21 @@ static Value *SimplifyFDivInst(Value *Op<br>
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZero()))<br>
return Op0;<br>
<br>
+ if (FMF.noNaNs() && FMF.noInfs()) {<br>
+ // X / X -> 1.0 iff NaNs and infinities are ignored.<br></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I'm not sure "iff NaNs and infinities are ignored" (in particular the "iff") is the best way to put it. The situation I think is more like "is legal when NaNs and infinities are ignored". Merely ignoring NaNs and infinities does not imply that X/X is guaranteed to be 1.0.</div><div><br></div><div>Also, I don't think you need the noInfs assumption. The cases where X/X->1.0 will fail have X/X->NaN.</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div></div></div></div></blockquote><div><br></div><div>Removed ninf check and rephrased comment in r239821. Thanks for the review :)</div><div><br></div><div>- Ben</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+ if (Op0 == Op1)<br>
+ return ConstantFP::get(Op0->getType(), 1.0);<br>
+<br>
+ // -X / X -> -1.0 and<br>
+ // X / -X -> -1.0 iff NaNs and infinities are ignored.<br>
+ // We can ignore signed zeros because +-0.0/+-0.0 is NaN and ignored.<br>
+ if ((BinaryOperator::isFNeg(Op0, /*IgnoreZeroSign=*/true) &&<br>
+ BinaryOperator::getFNegArgument(Op0) == Op1) ||<br>
+ (BinaryOperator::isFNeg(Op1, /*IgnoreZeroSign=*/true) &&<br>
+ BinaryOperator::getFNegArgument(Op1) == Op0))<br>
+ return ConstantFP::get(Op0->getType(), -1.0);<br>
+ }<br>
+<br>
return nullptr;<br>
}<br>
<br>
<br>
Modified: llvm/trunk/test/Transforms/InstSimplify/fast-math.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_Transforms_InstSimplify_fast-2Dmath.ll-3Frev-3D239701-26r1-3D239700-26r2-3D239701-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=vm34Rc9BakeAxzLkXH73VrK8ZlYsPtkHJ8UJJt48ePQ&s=tTcE4Of6FzIHXKDxpWyz-pi-zNf9H0NWrUMAhlV3Ko4&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/fast-math.ll?rev=239701&r1=239700&r2=239701&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/InstSimplify/fast-math.ll (original)<br>
+++ llvm/trunk/test/Transforms/InstSimplify/fast-math.ll Sun Jun 14 13:53:58 2015<br>
@@ -114,3 +114,80 @@ define double @fdiv_zero_by_x(double %X)<br>
ret double %r<br>
; CHECK: ret double 0<br>
}<br>
+<br>
+define float @fdiv_self(float %f) {<br>
+ %div = fdiv nnan ninf float %f, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_self<br>
+; CHECK: ret float 1.000000e+00<br>
+}<br>
+<br>
+define float @fdiv_self_invalid1(float %f) {<br>
+ %div = fdiv ninf float %f, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_self_invalid1<br>
+; CHECK: %div = fdiv ninf float %f, %f<br>
+; CHECK-NEXT: ret float %div<br>
+}<br>
+<br>
+define float @fdiv_self_invalid2(float %f) {<br>
+ %div = fdiv nnan float %f, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_self_invalid2<br>
+; CHECK: %div = fdiv nnan float %f, %f<br>
+; CHECK-NEXT: ret float %div<br>
+}<br>
+<br>
+define float @fdiv_self_invalid3(float %f) {<br>
+ %div = fdiv float %f, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_self_invalid3<br>
+; CHECK: %div = fdiv float %f, %f<br>
+; CHECK-NEXT: ret float %div<br>
+}<br>
+<br>
+define float @fdiv_neg(float %f) {<br>
+ %neg = fsub fast float -0.000000e+00, %f<br>
+ %div = fdiv nnan ninf float %neg, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_neg<br>
+; CHECK: ret float -1.000000e+00<br>
+}<br>
+<br>
+define float @fdiv_neg_invalid1(float %f) {<br>
+ %neg = fsub fast float -0.000000e+00, %f<br>
+ %div = fdiv ninf float %neg, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_neg_invalid1<br>
+; CHECK: %neg = fsub fast float -0.000000e+00, %f<br>
+; CHECK-NEXT: %div = fdiv ninf float %neg, %f<br>
+; CHECK-NEXT: ret float %div<br>
+}<br>
+<br>
+define float @fdiv_neg_invalid2(float %f) {<br>
+ %neg = fsub fast float -0.000000e+00, %f<br>
+ %div = fdiv nnan float %neg, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_neg_invalid2<br>
+; CHECK: %neg = fsub fast float -0.000000e+00, %f<br>
+; CHECK-NEXT: %div = fdiv nnan float %neg, %f<br>
+; CHECK-NEXT: ret float %div<br>
+}<br>
+<br>
+define float @fdiv_neg_invalid3(float %f) {<br>
+ %neg = fsub fast float -0.000000e+00, %f<br>
+ %div = fdiv float %neg, %f<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_neg_invalid3<br>
+; CHECK: %neg = fsub fast float -0.000000e+00, %f<br>
+; CHECK-NEXT: %div = fdiv float %neg, %f<br>
+; CHECK-NEXT: ret float %div<br>
+}<br>
+<br>
+define float @fdiv_neg_swapped(float %f) {<br>
+ %neg = fsub float 0.000000e+00, %f<br>
+ %div = fdiv nnan ninf float %f, %neg<br>
+ ret float %div<br>
+; CHECK-LABEL: fdiv_neg_swapped<br>
+; CHECK: ret float -1.000000e+00<br>
+}<br>
<br>
<br>
_______________________________________________<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" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></blockquote></div></div>