<br><br><div class="gmail_quote">On Thu, Aug 8, 2013 at 1:56 PM, Mark Lacey <span dir="ltr"><<a href="mailto:mark.lacey@apple.com" target="_blank">mark.lacey@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div class="im"><div>On Aug 8, 2013, at 9:56 AM, Jim Grosbach <<a href="mailto:grosbach@apple.com" target="_blank">grosbach@apple.com</a>> wrote:</div><br><blockquote type="cite">
<div style="word-wrap:break-word">Hi Chad,<div><br></div><div>This is a great transform to do, but you’re right that it’s only safe under fast-math. This is particularly interesting when the original divisor is a constant so you can materialize the reciprocal at compile-time. You’re right that in either case, this optimization should only kick in when there is more than one divide instruction that will be changed to a mul.</div>
</div></blockquote><div><br></div></div><div class="h5">It can be worthwhile to do this even in the case where there is only a single divide since 1/Y might be loop invariant, and could then be hoisted out later by LICM. You just need to be able to fold it back together when there is only a single use, and that use is not inside a more deeply nested loop.<br>
</div></div></div></blockquote><div><br>Ben's patch does exactly this, so perhaps that is the right approach.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="word-wrap:break-word"><div><div class="h5"><blockquote type="cite"><div style="word-wrap:break-word"><div><br></div><div>I don’t have a strong preference for instcombine vs. dagcombine, though I lean slightly towards later when we’ll have more target information available if we want to apply a more complicated cost function for some targets.</div>
<div><br></div><div>-Jim</div><div><br></div><div><br><div><div>On Aug 8, 2013, at 9:25 AM, Chad Rosier <<a href="mailto:chad.rosier@gmail.com" target="_blank">chad.rosier@gmail.com</a>> wrote:</div><br><blockquote type="cite">
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
I would like to transform X/Y -> X*1/Y. Specifically, I would like to convert:<br><br>define void @t1a(double %a, double %b, double %d) {<br>entry:<br> %div = fdiv fast double %a, %d<br> %div1 = fdiv fast double %b, %d<br>
%call = tail call i32 @foo(double %div, double %div1)<br> ret void<br>}<br><br>to:<br><br>define void @t1b(double %a, double %b, double %d) {<br>entry:<br> %div = fdiv fast double 1.000000e+00, %d<br> %mul = fmul fast double %div, %a<br>
%mul1 = fmul fast double %div, %b<br> %call = tail call i32 @foo(double %mul, double %mul1)<br> ret void<br>}<br><br>Is such a transformation best done as a (target-specific) DAG combine?<br><br>A similar instcombine already exists for the X/C->X*1/C case (see the CvtFDivConstToReciprocal function in InstCombineMlDivRem.cpp), but I don't believe the above can be done as an instcombine as it creates a new instruction (in addition to replacing the original). Also, I only want to perform the transformation if there are multiple uses of 1/Y (like in my test case). Otherwise, the transformation replaces a fdiv with a fdiv+fmul pair, which I doubt would be profitable.<br>
<br>FWIW, I'm also pretty sure this combine requires -fast-math.<br><br>Can someone point me in the right direction?<br><br> Thanks,<br> Chad<br>_______________________________________________<br>LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a><span> </span> <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div>
</blockquote></div><br></div></div>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div></div><br></div></blockquote></div><br>