[LLVMdev] optimization assumes malloc return is non-null
David Greene
dag at cray.com
Thu May 1 10:00:01 PDT 2008
On Wednesday 30 April 2008 21:21, Chris Lattner wrote:
> If LLVM is able to eliminate all users of the malloc assuming the
> malloc succeeded (as in this case), then it is safe to assume the malloc
> returned success.
Ah, I missed this bit. I didn't see that the result of malloc was not used
outside the if test.
But is the if test considered a "use?" If so, it's a use in the context of
success or failure, so how can LLVM assume success?
Your argument seems circular:
1. LLVM can't assume malloc success
2. If, assuming malloc success, LLVM can eliminate all uses, the malloc
becomes dead.
3. LLVM can eliminate the dead malloc.
4. Since the malloc was eliminated under assumption of success, the if test
becomes dead code and we can assume the malloc succeeded.
Perhaps the trouble is that your statement, "If LLVM is able to eliminate all
users of the malloc assuming the malloc succeeded," is ambiguous. Do
you mean that LLVM assumes the malloc succeeded and then tries to eliminate
all users by making use of that assumption or that it tries to eliminate all
users that are in a context where malloc is assumed to have succeeded (for
example the "else" of a check for malloc failure)?
If the former, it's a circular argument, if the latter, then what about the
use in the if test, which is in a context where we don't know whether the
malloc succeeded or not?
Just trying to get some clarity.
-Dave
More information about the llvm-dev
mailing list