[PATCH] D84821: Don't transfer BitCastInst at InstCombine pass when the user of BitCast is lifetime marker

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 20:46:29 PDT 2020


ChuanqiXu created this revision.
ChuanqiXu added reviewers: nikic, lebedev.ri, fhahn.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
ChuanqiXu requested review of this revision.

It is a usual pattern  to get the `lifetime marker` of Instruction `I`:

  SmallPtrSet<Instruction*, 4> LifetimeMarkers;
  for (User *U : I->users()) {
      if ( U is a lifetime marker)
          LifetimeMarkers.insert(U);
      if (BitCastInst* BCI=dyn_cast<BitCastInst>(U)){
          for (User* BCIUser:BCI->users())
              if (BCIUser is a lifetime marker)
                  LifetimeMarkers.insert(BCIUser);
      }
  }

In another word, the `lifetime marker` of an instruction `I` is either a user of I or a user of a user of I which is a BitCastInst. Although I don't find any rule for this pattern, I find it in a lot of codes.

However, in the InstCombine pass, it would try to transfer BitCast to a GEP when the target type of BitCast could be transferred by the source type of BitCast, which would break this pattern.

So I try to Disable the transferring process when the user of BitCast is `lifetime` marker.


https://reviews.llvm.org/D84821

Files:
  clang/test/CodeGen/aggregate-assign-call.c
  clang/test/CodeGen/temporary-lifetime-exceptions.cpp
  clang/test/CodeGenCXX/auto-var-init.cpp
  clang/test/CodeGenCXX/nrvo.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/bitcast-lifetime.ll
  llvm/test/Transforms/MemCpyOpt/memcpy-to-memset-with-lifetimes.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84821.281456.patch
Type: text/x-patch
Size: 8498 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/686532ab/attachment.bin>


More information about the llvm-commits mailing list