[llvm-commits] [PATCH] InstCombine: remove malloc+free if malloc's only uses are comparisons to null

Duncan Sands baldrick at free.fr
Mon May 17 02:12:46 PDT 2010


Hi Matti,

> There's one slight weirdness in it whose cleanness I'm not so sure
> about: when getting rid of the malloc+free, we want to replace the
> remaining uses of the malloc with a constant (trivially folded) non-null
> pointer. The only way of getting such a thing I could think of was to
> bitcast the enclosing function's address, since that's a GlobalValue and
> hence can be handled by ConstantFoldCompareInstruction. It definitely
> works, but it seems a bit hacky.

why not just directly replace the comparisons with true/false?  Also,
InstCombineCompares.cpp has a similar transformation in which a malloc
which is never freed, but only used in comparisons (for some reason it
is limited to only one comparison) is removed.  You may want to share
some code/logic with that.

Ciao,

Duncan.



More information about the llvm-commits mailing list