On Feb 12, 2014, at 9:54 , Kyle Sluder <k...@ksluder.com> wrote:

> On Feb 12, 2014, at 9:23 AM, Jordan Rose <jordan_r...@apple.com> wrote:
> 
>> Hi, Kyle. It looks like Clang does not perform this optimization, even under 
>> -O3 or -Oz. I can guess why: even though sending a message to nil will 
>> result in 0, it's still more work to call objc_msgSend, have it do the 
>> comparison to nil, and then have it clean things up properly to return 0. 
>> (In fact, you can poke at the source for objc_msgSend and see exactly how 
>> much work it is: not much, but still more than doing the check yourself.)
> 
> Understood. Though I’m curious: is there a hard-and-fast rule against 
> optimizations introducing function calls and/or branches where they would 
> otherwise not appear?
> 
> Nonetheless, this optimization also introduces the possibility of involving 
> the nil message handler (which AFAIK is undocumented), so there is a semantic 
> difference as well as a performance difference.

I didn't want to muddy the situation, but yes, that is exactly a case where 
messaging nil will not be equivalent. That might actually mean you'd end up 
having to hide your optimization behind a flag. Since the custom nil receiver 
is so rare, though, it might be okay to be on by default. (Can you tell that's 
not my area of the compiler? :-) )

Jordan
_______________________________________________
cfe-users mailing list
cfe-users@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to