<div class="gmail_quote">On 27 October 2010 10:57, Dan Gohman <span dir="ltr"><<a href="mailto:gohman@apple.com">gohman@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"><br>
On Oct 26, 2010, at 11:34 PM, Nick Lewycky wrote:<br>
<br>
> This patch adds a new method on Value called getThruSplat() which returns the splatted value iff this is a ConstantValue with a splat, or 'this' otherwise. I demonstrate its usage by updating InstructionSimplify to uniformly handle splat vectors alongside ConstantInt values.<br>


<br>
</div>Looks reasonable to me.<br>
<br>
How about "getScalarValue" instead of "getThruSplat"?<br>
I don't have strong opinions about it though.<br></blockquote><div><br></div><div>ConstantArray and ConstantStruct aren't scalar and this method could return those. For that matter, it could even return a vector, constant or not.</div>

<div><br></div><div>My concern is to make very sure that this is the API we really want. Are we sure that "dyn_cast<ConstantInt>(V->getThruSplat())" doesn't do any more work than the minimum (or at least, that the compiler can't optimize away)? And is it okay to put this work on the lookup side? We will do this test more often this way than if we did the work at the point of creation, which is the pattern we follow in the rest of LLVM.</div>

<div><br></div><div>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.</div>

<div><br></div><div>I think the tradeoff in my patch is the most reasonable one, but I want to be certain that we've thought of everything before I go off and apply this idiom all over the place.</div><div><br></div>
<div>
Nick</div><div><br></div></div>