<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr"><div class="gmail_default" style>On Wed, Jan 2, 2013 at 5:01 PM, Shuxin Yang <span dir="ltr"><<a href="mailto:shuxin.llvm@gmail.com" target="_blank" class="cremed">shuxin.llvm@gmail.com</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
   The attached patch is to implement following rules. (Please ignore the changes to APFloat.{h,cpp}).<br>
<br>
   1. X/C1 * C2 => X * (C2/C1) (if C2/C1 is neither special FP nor denormal)<br>
   2. X/C1 * C2 -> X/(C1/C2)   (if C2/C1 is either specical FP or denormal, but C1/C2 is a normal Fp)<br>
<br>
    Let MDC denote multiplication or dividion with one & only one operand being a constant<br>
  3. (MDC +/- C1) * C2 => (MDC * C2) +/- (C1 * C2)<br>
    (so long as the constant-folding doesn't yield any denormal or special value)<br></blockquote><div><br></div><div style>I would separate this into two patches: one for #1 and #2, the second patch for #3.</div><div style>
<br></div><div style>I feel like this (and a lot of future transformations) would be greatly simplified by two things:</div><div style><br></div><div style>a) Have InstCombine do operand order canonicalization when it can due to fastmath the same as we do for integers. This is a key element of bounding the complexity of implementing fundamental scalar math simplifications, and it will remove a lot of the testing for which side of an operation a constant is on.</div>
<div style><br></div><div style>b) Build up a set of rich pattern matching routines for the floating point properties your checking here: is normal, is denormal, etc etc.</div><div style><br></div><div style><br></div><div style>
Once we have these two in place, optimizations such as this should be able to be written in a very short, declarative pattern that is easier to maintain and organize in the long-term.</div><div style><br></div><div style>
Thoughts?</div></div></div></div></div>