<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 01/02/2013 05:53 PM, Chandler
Carruth wrote:<br>
</div>
<blockquote
cite="mid:CAGCO0Kjv_qkpN2jQxHbz89DJ5TsSArkcSHeUJVWtmeQ9GUOADg@mail.gmail.com"
type="cite">
<div style="font-family: arial, helvetica, sans-serif; font-size:
10pt">
<div dir="ltr">
<div class="gmail_extra">On Wed, Jan 2, 2013 at 5:48 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 class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">Canonicalization
will help if one of the operands is constant. <br>
</div>
</blockquote>
<div><br>
</div>
<div style="">And in both of these patches, the
optimizations only trigger when one of the operands is
constant.</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
Maybe I were not clear in my previous mail(s). I said "I give up if
both operands are constant", it <br>
refers to the "X" in "f = x * c and x = c1 op c2". <br>
In this situation, I give up because I think "c1 op c2" must be
folded earlier. <br>
<br>
For any multiplication with constant, be it in the form of x * c or
c * x, I can handle it uniformly. <br>
This is because I call std::swap() to switch multiplication operands
if the 1st one is constant. <br>
<br>
<blockquote
cite="mid:CAGCO0Kjv_qkpN2jQxHbz89DJ5TsSArkcSHeUJVWtmeQ9GUOADg@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> </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> Otherwise, its
meaning is pretty vague. Consider the the case
"(select c ? v1 : v2) * (m + n)", which form is
canonical? <br>
(select ...) * (.. + ... ) or "(..+...) * (select
...)?</div>
</blockquote>
<div><br>
</div>
<div style="">Even here, I think it is fundamentally the
right architecture to pick a canonical form and rewrite
to that form. If we get it wrong, it is easy to fix. The
codegen layer should reorder things however is best on
the architecture regardless of the particular ordering
we canonicalize to in the IR. The point of
canonicalization is not that one form is "better" than
another, but merely to constrain the search space and
improve our ability to match patterns consistently.</div>
</div>
</div>
</div>
</div>
</blockquote>
<br>
You may define "add" should permute after "select", and "sub" should
be permute before "select".<br>
What if I need to handle "(select cond ? 1 : 0) * whatever"?<br>
<br>
I believe my way to tackle this situation is not too ugly -- it is
at the cost of no more than 5 lines of code to enclose <br>
a big chunk of logic which handle symmetric opportunities. <br>
<br>
for (int i = 0; i < 2 ; i++) {<br>
...detect the pattern ..<br>
std::swap(operands)<br>
}<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>