<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 1/2/13 5:10 PM, Chandler Carruth
wrote:<br>
</div>
<blockquote
cite="mid:CAGCO0KhDrgR8FFEJn4AmMxgUsAdPk_ex2yW+K-3WAAQh7Jo_Rg@mail.gmail.com"
type="cite">
<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
moz-do-not-send="true"
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>
</div>
</div>
</div>
</blockquote>
I can separate them into two parts, but I don't think it will make
things tons better as both set of optimizations are pretty trivial (<br>
at very least, conceptually so). <br>
<br>
<blockquote
cite="mid:CAGCO0KhDrgR8FFEJn4AmMxgUsAdPk_ex2yW+K-3WAAQh7Jo_Rg@mail.gmail.com"
type="cite">
<div style="font-family: arial, helvetica, sans-serif; font-size:
10pt">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<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>
</div>
</div>
</div>
</blockquote>
Canonicalization will help if one of the operands is constant. <br>
Otherwise, its meaning is pretty vague. Consider the the case
"(select c ? v1 : v2) * (m + n)", which form is canonical? <br>
(select ...) * (.. + ... ) or "(..+...) * (select ...)?<br>
<br>
In my code I use 2-iteration-loop to tackle the symmetric situations
in order to avoid code duplication. <br>
I guess this may alleviate the problem a bit. <br>
<blockquote
cite="mid:CAGCO0KhDrgR8FFEJn4AmMxgUsAdPk_ex2yW+K-3WAAQh7Jo_Rg@mail.gmail.com"
type="cite">
<div style="font-family: arial, helvetica, sans-serif; font-size:
10pt">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<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>
</div>
</div>
</div>
</blockquote>
I agree with you in general. <br>
The biggest problem is how to factor things out and implement them
by some pattern matching routines, and<br>
in the mean time keep the interface clean and easy to understand.
This is difficult in practice.<br>
If the pattern match routines are used only once, you are better off
directly implementing the logic. <br>
<br>
Pattern matching is intrinsically messy. I don't expect it is as
clean as loop nest optimizations. <br>
<br>
<blockquote
cite="mid:CAGCO0KhDrgR8FFEJn4AmMxgUsAdPk_ex2yW+K-3WAAQh7Jo_Rg@mail.gmail.com"
type="cite">
<div style="font-family: arial, helvetica, sans-serif; font-size:
10pt">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<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>
</blockquote>
<br>
</body>
</html>