[llvm] [Coroutines] Drop dead instructions more aggressively in addMustTailToCoroResumes() (PR #85271)

Chuanqi Xu via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 01:22:28 PDT 2024


================
@@ -1203,10 +1203,6 @@ static bool simplifyTerminatorLeadingToRet(Instruction *InitialInst) {
       if (isa<BitCastInst>(I) || I->isDebugOrPseudoInst() ||
           I->isLifetimeStartOrEnd())
         I = I->getNextNode();
-      else if (isInstructionTriviallyDead(I))
-        // Duing we are in the middle of the transformation, we need to erase
-        // the dead instruction manually.
-        I = &*I->eraseFromParent();
----------------
ChuanqiXu9 wrote:

Yeah, since these instructions become dead during CoroSplit pass. The internals are

```
  %save2 = call token @llvm.coro.save(ptr null)
  call fastcc void @fakeresume1(ptr align 8 null)
  %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)

  ; These (non-trivially) dead instructions are in the way.
  %gep = getelementptr inbounds i64, ptr %alloc.var, i32 0
  %foo = ptrtoint ptr %gep to i64

  switch i8 %suspend2, label %exit [
    i8 0, label %await.ready
    i8 1, label %exit
  ]
await.ready:
  call void @consume(ptr %alloc.var)
  call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
  br label %exit
exit:
  call i1 @llvm.coro.end(ptr null, i1 false, token none)
  ret void
}
```

During the splitting,  the value `%suspend2` will become a constant in different splitted functions. So it makes sense if the previous passes can't catch such things.

https://github.com/llvm/llvm-project/pull/85271


More information about the llvm-commits mailing list