[llvm-commits] [PATCH] Skip NULL pointer check for free

Quentin Colombet qcolombet at apple.com
Wed Jan 2 10:18:51 PST 2013


Ping!

-Quentin


On Dec 21, 2012, at 4:04 PM, Quentin Colombet <qcolombet at apple.com> wrote:

> Hi Nick,
> 
> On Dec 21, 2012, at 3:59 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> 
>> On Sat, Dec 22, 2012 at 1:53 AM, Nick Lewycky <nicholas at mxc.ca> wrote:
>>> On 12/21/2012 03:43 PM, Quentin Colombet wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> Here is a patch to help llvm turning a code like this:
>>>> if (foo)
>>>> free(foo)
>>>> 
>>>> into that:
>>>> free(foo)
>>>> 
>>>> It is legal and safe, since free is already checking its argument
>>>> against NULL internally (I may find the reference in the Standard if
>>>> needed :)).
>>> 
>>> It's legal and safe, but is it desirable? Calling a function is expensive
>>> even if the function doesn't do anything.
> 
> Yes, you're right, it may not be desirable but I'm tempt to think like Dmitri.
> 
> Do you think that this optimization should be controlled by a flag?
> At least, for code size (Oz and maybe Os), it may always be desirable.
> 
> I did not consider changing free(foo) into if(foo) free(foo)
> 
>> 
>> That's true, but there's another viewpoint: programmers usually write
>> 'if(!foo) free(foo);' not because they are manually inlining the fast
>> path of free(), but because they think that free(NULL) is UB.
>> 
>> Dmitri
>> 
>> -- 
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130102/bac623d7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: skipNullPtrCheckForFreeFct.patch
Type: application/octet-stream
Size: 4740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130102/bac623d7/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130102/bac623d7/attachment-0001.html>


More information about the llvm-commits mailing list