From 81bff5e6ea27d5ff45b01372fdbbdad2fbac98b9 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Tue, 27 Nov 2018 11:08:14 +0000 Subject: [PATCH] InstCombine: add comment explaining malloc deletion. NFC. I tried to change this, not quite realising the logic behind what we were doing. Hopefully this comment will help the next person to come along. llvm-svn: 347653 --- .../Transforms/InstCombine/InstructionCombining.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index a3962a04b500..a8fd47c9d451 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2244,9 +2244,16 @@ static bool isAllocSiteRemovable(Instruction *AI, } Instruction *InstCombiner::visitAllocSite(Instruction &MI) { - // If we have a malloc call which is only used in any amount of comparisons - // to null and free calls, delete the calls and replace the comparisons with - // true or false as appropriate. + // If we have a malloc call which is only used in any amount of comparisons to + // null and free calls, delete the calls and replace the comparisons with true + // or false as appropriate. + + // This is based on the principle that we can substitute our own allocation + // function (which will never return null) rather than knowledge of the + // specific function being called. In some sense this can change the permitted + // outputs of a program (when we convert a malloc to an alloca, the fact that + // the allocation is now on the stack is potentially visible, for example), + // but we believe in a permissible manner. SmallVector Users; // If we are removing an alloca with a dbg.declare, insert dbg.value calls