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.
[Wording]
While you only test caller arguments below, the code will actually add assumptions for any nonnull call site argument.