<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 20, 2016 at 9:08 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</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"><span class="">----- Original Message -----<br>
> From: "David Majnemer via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>><br>
> To: <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> Sent: Friday, April 15, 2016 12:21:03 PM<br>
> Subject: [llvm] r266452 - [InstCombine] Don't transform compares of calls to functions named fabs{f, l, }<br>
><br>
> Author: majnemer<br>
> Date: Fri Apr 15 12:21:03 2016<br>
> New Revision: 266452<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=266452&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=266452&view=rev</a><br>
> Log:<br>
> [InstCombine] Don't transform compares of calls to functions named<br>
> fabs{f,l,}<br>
><br>
> InstCombine wants to optimize compares of calls to fabs with zero.<br>
> However, we didn't have the necessary legality checking to verify<br>
> that<br>
> the function call had the same behavior as fabs.<br>
<br>
</span>And so you limited the transformation only to the intrinsic?</blockquote><div><br></div><div>No, I have not.</div><div><br></div><div>The call to getIntrinsicIDForCall will return Intrinsic::fabs for either the abs intrinsic or an explicit call to the library functions fabsf, fabs, fabsl.</div><div><br></div><div>By utilizing getIntrinsicIDForCall to test if we have a call to Intrinsic::fabs we nicely abstract the same checks over and over again out to a single, canonical, location.</div><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"> Why? Shouldn't we just have the same checks here that we have in LibCallSimplifier::optimizeFabs:<br>
<br>
Value *LibCallSimplifier::optimizeFabs(CallInst *CI, IRBuilder<> &B) {<br>
Function *Callee = CI->getCalledFunction();<br>
if (!matchesFPLibFunctionSignature(Callee, 1, false))<br>
return nullptr;<br>
<br>
specifically the matchesFPLibFunctionSignature check.<br>
<br>
Thanks again,<br>
Hal<br>
<div class=""><div class="h5"><br>
><br>
> Modified:<br>
> llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
> llvm/trunk/test/Transforms/InstCombine/pr27332.ll<br>
><br>
> Modified:<br>
> llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=266452&r1=266451&r2=266452&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=266452&r1=266451&r2=266452&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp<br>
> (original)<br>
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri<br>
> Apr 15 12:21:03 2016<br>
> @@ -26,6 +26,7 @@<br>
> #include "llvm/Support/CommandLine.h"<br>
> #include "llvm/Support/Debug.h"<br>
> #include "llvm/Analysis/TargetLibraryInfo.h"<br>
> +#include "llvm/Analysis/VectorUtils.h"<br>
><br>
> using namespace llvm;<br>
> using namespace PatternMatch;<br>
> @@ -4564,39 +4565,33 @@ Instruction *InstCombiner::visitFCmpInst<br>
> break;<br>
><br>
> CallInst *CI = cast<CallInst>(LHSI);<br>
> - const Function *F = CI->getCalledFunction();<br>
> - if (!F)<br>
> + Intrinsic::ID IID = getIntrinsicIDForCall(CI, TLI);<br>
> + if (IID != Intrinsic::fabs)<br>
> break;<br>
><br>
> // Various optimization for fabs compared with zero.<br>
> - LibFunc::Func Func;<br>
> - if (F->getIntrinsicID() == Intrinsic::fabs ||<br>
> - (TLI->getLibFunc(F->getName(), Func) && TLI->has(Func)<br>
> &&<br>
> - (Func == LibFunc::fabs || Func == LibFunc::fabsf ||<br>
> - Func == LibFunc::fabsl))) {<br>
> - switch (I.getPredicate()) {<br>
> - default:<br>
> - break;<br>
> - // fabs(x) < 0 --> false<br>
> - case FCmpInst::FCMP_OLT:<br>
> - llvm_unreachable("handled by SimplifyFCmpInst");<br>
> - // fabs(x) > 0 --> x != 0<br>
> - case FCmpInst::FCMP_OGT:<br>
> - return new FCmpInst(FCmpInst::FCMP_ONE,<br>
> CI->getArgOperand(0), RHSC);<br>
> - // fabs(x) <= 0 --> x == 0<br>
> - case FCmpInst::FCMP_OLE:<br>
> - return new FCmpInst(FCmpInst::FCMP_OEQ,<br>
> CI->getArgOperand(0), RHSC);<br>
> - // fabs(x) >= 0 --> !isnan(x)<br>
> - case FCmpInst::FCMP_OGE:<br>
> - return new FCmpInst(FCmpInst::FCMP_ORD,<br>
> CI->getArgOperand(0), RHSC);<br>
> - // fabs(x) == 0 --> x == 0<br>
> - // fabs(x) != 0 --> x != 0<br>
> - case FCmpInst::FCMP_OEQ:<br>
> - case FCmpInst::FCMP_UEQ:<br>
> - case FCmpInst::FCMP_ONE:<br>
> - case FCmpInst::FCMP_UNE:<br>
> - return new FCmpInst(I.getPredicate(),<br>
> CI->getArgOperand(0), RHSC);<br>
> - }<br>
> + switch (I.getPredicate()) {<br>
> + default:<br>
> + break;<br>
> + // fabs(x) < 0 --> false<br>
> + case FCmpInst::FCMP_OLT:<br>
> + llvm_unreachable("handled by SimplifyFCmpInst");<br>
> + // fabs(x) > 0 --> x != 0<br>
> + case FCmpInst::FCMP_OGT:<br>
> + return new FCmpInst(FCmpInst::FCMP_ONE,<br>
> CI->getArgOperand(0), RHSC);<br>
> + // fabs(x) <= 0 --> x == 0<br>
> + case FCmpInst::FCMP_OLE:<br>
> + return new FCmpInst(FCmpInst::FCMP_OEQ,<br>
> CI->getArgOperand(0), RHSC);<br>
> + // fabs(x) >= 0 --> !isnan(x)<br>
> + case FCmpInst::FCMP_OGE:<br>
> + return new FCmpInst(FCmpInst::FCMP_ORD,<br>
> CI->getArgOperand(0), RHSC);<br>
> + // fabs(x) == 0 --> x == 0<br>
> + // fabs(x) != 0 --> x != 0<br>
> + case FCmpInst::FCMP_OEQ:<br>
> + case FCmpInst::FCMP_UEQ:<br>
> + case FCmpInst::FCMP_ONE:<br>
> + case FCmpInst::FCMP_UNE:<br>
> + return new FCmpInst(I.getPredicate(),<br>
> CI->getArgOperand(0), RHSC);<br>
> }<br>
> }<br>
> }<br>
><br>
> Modified: llvm/trunk/test/Transforms/InstCombine/pr27332.ll<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pr27332.ll?rev=266452&r1=266451&r2=266452&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pr27332.ll?rev=266452&r1=266451&r2=266452&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Transforms/InstCombine/pr27332.ll (original)<br>
> +++ llvm/trunk/test/Transforms/InstCombine/pr27332.ll Fri Apr 15<br>
> 12:21:03 2016<br>
> @@ -9,3 +9,15 @@ entry:<br>
> }<br>
> ; CHECK-LABEL: define <4 x i1> @test1(<br>
> ; CHECK: ret <4 x i1> zeroinitializer<br>
> +<br>
> +declare float @fabsf()<br>
> +<br>
> +define i1 @test2() {<br>
> + %call = call float @fabsf()<br>
> + %cmp = fcmp olt float %call, 0.000000e+00<br>
> + ret i1 %cmp<br>
> +}<br>
> +; CHECK-LABEL: define i1 @test2(<br>
> +; CHECK: %[[call:.*]] = call float @fabsf()<br>
> +; CHECK: %[[cmp:.*]] = fcmp olt float %[[call]], 0.000000e+00<br>
> +; CHECK: ret i1 %[[cmp]]<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
><br>
<br>
</div></div><span class=""><font color="#888888">--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</font></span></blockquote></div><br></div></div>