GVN: Enable value forwarding for calloc
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 12 Jun 2014 21:16:19 +0000 (21:16 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 12 Jun 2014 21:16:19 +0000 (21:16 +0000)
commitfd5c553f54237715fbaf8b76736cef7f500c3abc
tree5973a607b3ca490955bba4d45ca58d46ce27ffcb
parent5d47d4ac7e5d7f89916c901a09527a134261dd34
GVN: Enable value forwarding for calloc

Enable value forwarding for loads from `calloc()` without an intervening
store.

This change extends GVN to handle the following case:

    %1 = tail call noalias i8* @calloc(i64 1, i64 4)
    %2 = bitcast i8* %1 to i32*
    ; This load is trivially constant zero
    %3 = load i32* %2, align 4

This is analogous to the handling for `malloc()` in the same places.
`malloc()` returns `undef`; `calloc()` returns a zero value.  Note that
it is correct to return zero even for out of bounds GEPs since the
result of such a GEP would be undefined.

Patch by Philip Reames!

llvm-svn: 210828
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/calloc-load-removal.ll [new file with mode: 0644]