If the pointer is not null, the runtime overhead of the null check is pretty negligible next to the cost of actually doing the allocation. If the pointer is null, the runtime overhead of making at least one unnecessary call — probably two, if 'operator delete' doesn't do its own null check before calling 'free', and probably one that crosses image boundaries — is not negligible at all. So the relative impact on code that does end up destroying a trivial value is outsized.
A question: what is backport policy of LLVM project? I'd love to see this fix in 5.0.0 .
Submitted as r326023.
Use getTerminatingMustTailCall instead of iterating through all instructions.
@hans: Thanks! Is it already too late to cherry-pick these changes to the upcoming 6.0 version?