[InstCombine] keep assumption before sinking calls
authortyker <tyker1@outlook.com>
Wed, 30 Oct 2019 23:11:18 +0000 (00:11 +0100)
committertyker <tyker1@outlook.com>
Wed, 30 Oct 2019 23:15:19 +0000 (00:15 +0100)
commitc3b06d0c393e533eab712922911d14e5a079fa5d
tree7e6e292e9ce1a5e879bbcaa87774d606c869d2e9
parent5632d3756cd589a8139099317829a746dab650ee
[InstCombine] keep assumption before sinking calls

Summary:
in the following C code the branch is not removed by clang in O3.
```
int f1(char* p) {
    int i1 = __builtin_strlen(p);
    if (!p)
        return -1;
    return i1;
}
```
The issue is that the call to strlen is sunk to the following block by instcombine. In its new place the call to strlen doesn't dominate the use in the icmp anymore so value tracking can't see that p cannot be null.
This patch resolves the issue by inserting an assumption at the place of the call before sinking a call when that call can be used to prove an argument to be nonnull.
This resolves this issue at O3.

Reviewers: majnemer, xbolva00, fhahn, jdoerfert, spatel, efriedma

Reviewed By: jdoerfert

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D69477
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/assume-replacing-call.ll [new file with mode: 0644]