<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 4, 2019 at 10:30 AM David Greene <<a href="mailto:dag@cray.com">dag@cray.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I don't think that's a correct replacement.<br>
<br>
if (var && isa<T>(var)) {<br>
...<br>
}<br>
<br>
is not the same as:<br>
<br>
if (isa_or_null<T>(var)) {<br>
...<br>
}<br>
<br>
at least according to what "isa_or_null" conveys to me.<br></blockquote><div><br></div><div>This is the same convention used by the existing "_or_null" varieties, i.e., "cast_or_null" and "dyn_cast_or_null". They accept a null and propagate it. In the "isa" case, it would accept a null and propagate it as false. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
not_null_and_isa<T> would seem a better fit, or maybe exists_and_isa<T>.<br>
<br>
That said, I'm not sure sure we need a special API for this. Are<br>
expensive calls used in the way you describe really common?<br></blockquote><div><br></div><div>I've only been looking at the ones involving method calls, but it's not too common. Perhaps a dozen in clang/lib -- haven't run it against the rest of the code base.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-David<br>
<br>
Don Hinton via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> writes:<br>
<br>
> I'd like to propose adding `isa_or_null<>` to replace the following usage pattern that's relatively common in conditionals:<br>
><br>
> var && isa<T>(var) =>> isa_or_null<T>(var)<br>
><br>
> And in particular when `var` is a method call which might be expensive, e.g.:<br>
><br>
> X->foo() && isa<T>(X->foo()) =>> isa_or_null<T>(X->foo())<br>
><br>
> The implementation could be a simple wrapper around isa<>, and while the IR produced is only slightly more efficient, the elimination of an extra call could be<br>
> worthwhile.<br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>