<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 9, 2011, at 5:12 PM, Chandler Carruth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Sun, Jan 9, 2011 at 4:39 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com">clattner@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 class="im">Chandler, I don't see what the issue is here.  While it "would be nice" to have generic rounding mode support in the IR, there is no problem with having an intrinsic here.  llvm.x86.sse2.cvtsd2si is a readnone function, so it should be optimized just about as well as fptosi.  What specifically are we missing?</div>

<br>
If you're concerned about the extraneous mov + xor in:<br>
<div class="im">+        xorps   %xmm1, %xmm1<br>
+        movsd   %xmm0, %xmm1<br>
+        cvtsd2sil       %xmm1, %eax<br>
<br>
</div>The the right fix is to teach SimplifyDemandedVectorElts that llvm.x86.sse2.cvtsd2si does not demand a top element.  This will allow the ir to be optimized to remove the insertion of the 0.0.<br></blockquote><div><br>
</div><div>Interesting. The other, and probably more important thing I was seeing is code like:</div><div><br></div><div>int a() { return f(1.1) + g(2.2); }</div><div><br></div><div>After inlining the 'g(2.2)' --> 2 constant folding works, but we're still left with an intrinsic call with a constant argument of 1.1:</div>
<div><br></div><div><div>define i32 @_Z1av() nounwind readnone {</div><div>entry:</div><div>  %0 = tail call i32 @llvm.x86.sse2.cvtsd2si(<2 x double> <double 1.100000e+00, double 0.000000e+00>) nounwind</div><div>
  %add = add nsw i32 %0, 2</div><div>  ret i32 %add</div><div>}</div></div><div><br></div><div>However, perhaps the right way to solve this is along the same lines: teach a pass to fold constant arguments to that intrinsic. I don't know how long a list of these types of transformations there will be however. If constant prop is enough, maybe this is the best way to go.</div>
</div>
</blockquote></div><br><div>We want intrinsics to be well optimized.  In this case, constant folding should be added to lib/Analysis/ConstantFolding.cpp.  Just grep for intrinsic to see how others are handled.</div><div><br></div><div>-Chris</div><div><br></div></body></html>