[PATCH] D69477: [InstCombine] keep assumption before skink calls

Tyker via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 27 09:07:26 PDT 2019


Tyker created this revision.
Tyker added a reviewer: majnemer.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Tyker retitled this revision from "[InstCombine]" to "[InstCombine] keep assumption before skink calls".

in the following C code the branch is not removed by clang in O3 <https://reviews.llvm.org/owners/package/3/>.

  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 <https://reviews.llvm.org/owners/package/3/>.


Repository:
  rL LLVM

https://reviews.llvm.org/D69477

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/Assume-Remplacing-Call.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69477.226573.patch
Type: text/x-patch
Size: 4870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191027/96ddef30/attachment.bin>


More information about the llvm-commits mailing list