<html><head></head><body bgcolor="#FFFFFF" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>On Oct 29, 2010, at 7:28 PM, Nick Lewycky <<a href="mailto:nlewycky@google.com">nlewycky@google.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><div class="gmail_quote">On 27 October 2010 17:42, Dan Gohman <span dir="ltr"><<a href="mailto:gohman@apple.com"></a><a href="mailto:gohman@apple.com">gohman@apple.com</a>></span> wrote:</div></div></blockquote><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.289062); -webkit-composition-fill-color: rgba(175, 192, 227, 0.222656); -webkit-composition-frame-color: rgba(77, 128, 180, 0.222656);"><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.300781); -webkit-composition-fill-color: rgba(175, 192, 227, 0.234375); -webkit-composition-frame-color: rgba(77, 128, 180, 0.234375);"><br></span></span></div><blockquote type="cite"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> It might be nice to<br>
push it into the API though, and have<br>
  ConstantInt *getAsConstantInt();<br>
  ConstantFP *getAsConstantFP();<br>
instead though, if you're going to be doing this a lot.<br></blockquote><div><br></div><div>I'm not a fan, it sounds as though you could get any Value as a ConstantInt/FP which just doesn't make sense.</div></div></div></blockquote><div><br></div><div>They'd reurn null if the Value is not a ConstantInt/FP, or vector thereof.</div><div><br></div><div>  if (ConstantInt *CI = C->getAsConstantInt())</div><div><br></div><div>seems pretty readable.  And it would avoid the double-dyncast issue.  But I'm not attatched.</div><div><br></div><div>Or if you like:</div><div><br></div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">  if (ConstantInt *CI = C->getAs<ConstantInt>())</span><div><br></div><div>clang uses some idioms like this, for example. *shrug*</div><br><blockquote type="cite"><div><div class="gmail_quote"><div>

<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">> The most radical alternative API would be to factor out a common base that represents a ConstantInt+ConstantVector(with splat) and another for ConstantFP+ConstantVector(with splat), then teach ConstantVector to return such a splatted CV from its getter. Sadly if you follow this through to its conclusion, you end up using multiple inheritance in the Constant hierarchy which causes all sorts of forms of pain.<br>


<br>
</div>I agree, don't do MI. But I think if you wanted to take this approach, you could<br>
make ConstantInt and ConstantFP capable of having vector types, but not be<br>
subclasses of ConstantVector. ConstantVector would just be for cases where it's<br>
really necessary to have an array of operands. This sounds like a big and scary<br>
change, though there are some reasons it might not have to be.<br>
<br>
With this approach, vector ConstantAggregateZero could go away.<br></blockquote><div><br></div><div>Doing that would force me to audit every single use of ConstantInt and ConstantFP to make sure they're okay with splat vectors instead of real int's/fp's, and adding tests on the type if necessary. Do you think that would be a better API at the end of the day? My proposed patch would be more of an opt-in approach.</div></div></div></blockquote><div><br></div><div>I think it's worth considering.  All of the relevant operators are overloaded for vector</div><div>these days; constants are the only remaining IR construct using different opcodes</div><div>for the same operations in scalar and vector.`</div><div><br></div><div>The SelectionDAG IR has already taken some steps in this direction.</div><div>The main complication has been code which looks at the size of a type to</div><div>determine its precision.  Each instance is easy to fix once found though.</div><div><br></div><div>Dan</div><br></body></html>