[llvm-commits] PATCH: new Value::getThruSplat API

Chris Lattner clattner at apple.com
Fri Oct 29 22:09:13 PDT 2010

On Oct 29, 2010, at 9:50 PM, Nick Lewycky wrote:

> Also, the way it is used is confusing.  Why not name it "getSplatElement" and have it return null on failure?
> Because I want to preserve the pattern of a declaring a single variable inside an if-statement with a dyn_cast. I'm planning to find and update code which currently does that with a test for ConstantInt/FP and don't want to add lots of this pattern:
>   Value *V = value;
>   if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
>     if (Constant *Splat = CV->getSplatValue())
>       V = Splat;
>   if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
>     ...
> all over. If getSplatElement() returned NULL instead of "this" then I would only be able to remove one line of that (the test for ConstantVector).
> I guess I don't really understand what makes the replacement code confusing.

Well, the function currently only has one client, so it's hard to tell what other places use it and what would be more convenient.  I'm just saying that the API is cleaner and easier to understand if it returns null on a non-splat value.  I'm fine with keeping it your way if you strongly prefer that.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20101029/5ba459ee/attachment.html>

More information about the llvm-commits mailing list