[PATCH] D129230: [IR][coroutine] make final and non-final llvm.coro.saves unique

Yuanfang Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 6 15:01:17 PDT 2022


ychen updated this revision to Diff 442695.
ychen added a comment.

update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129230/new/

https://reviews.llvm.org/D129230

Files:
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Transforms/Utils/FunctionComparator.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1505,10 +1505,6 @@
     if (I1->isTerminator())
       goto HoistTerminator;
 
-    // Hoisting token-returning instructions would obscure the origin.
-    if (I1->getType()->isTokenTy())
-      return Changed;
-
     // If we're going to hoist a call, make sure that the two instructions we're
     // commoning/hoisting are both marked with musttail, or neither of them is
     // marked as such. Otherwise, we might end up in a situation where we hoist
Index: llvm/lib/Transforms/Utils/FunctionComparator.cpp
===================================================================
--- llvm/lib/Transforms/Utils/FunctionComparator.cpp
+++ llvm/lib/Transforms/Utils/FunctionComparator.cpp
@@ -28,6 +28,7 @@
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
@@ -596,6 +597,21 @@
   if (const CmpInst *CI = dyn_cast<CmpInst>(L))
     return cmpNumbers(CI->getPredicate(), cast<CmpInst>(R)->getPredicate());
   if (auto *CBL = dyn_cast<CallBase>(L)) {
+    // Must have the same "Final Suspend" flag.
+    if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(L)) {
+      if (II->getIntrinsicID() == Intrinsic::coro_save && L->getNumUses() &&
+          R->getNumUses()) {
+        auto *CS1 = cast<IntrinsicInst>(L->user_back());
+        auto *CS2 = cast<IntrinsicInst>(R->user_back());
+        assert(CS1->getIntrinsicID() == Intrinsic::coro_suspend &&
+               CS2->getIntrinsicID() == Intrinsic::coro_suspend);
+        bool IsFinal1 = cast<Constant>(CS1->getArgOperand(1))->isOneValue();
+        bool IsFinal2 = cast<Constant>(CS2->getArgOperand(1))->isOneValue();
+        if (int Res = cmpNumbers(IsFinal1, IsFinal2))
+          return Res;
+      }
+    }
+
     auto *CBR = cast<CallBase>(R);
     if (int Res = cmpNumbers(CBL->getCallingConv(), CBR->getCallingConv()))
       return Res;
Index: llvm/lib/IR/Instruction.cpp
===================================================================
--- llvm/lib/IR/Instruction.cpp
+++ llvm/lib/IR/Instruction.cpp
@@ -455,11 +455,24 @@
            SI->getSyncScopeID() == cast<StoreInst>(I2)->getSyncScopeID();
   if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
     return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
-  if (const CallInst *CI = dyn_cast<CallInst>(I1))
+  if (const CallInst *CI = dyn_cast<CallInst>(I1)) {
+    // Must have the same "Final Suspend" flag.
+    if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I1)) {
+      if (II->getIntrinsicID() == Intrinsic::coro_save && I1->getNumUses() &&
+          I2->getNumUses()) {
+        auto *CS1 = cast<IntrinsicInst>(I1->user_back());
+        auto *CS2 = cast<IntrinsicInst>(I2->user_back());
+        assert(CS1->getIntrinsicID() == Intrinsic::coro_suspend &&
+               CS2->getIntrinsicID() == Intrinsic::coro_suspend);
+        return cast<Constant>(CS1->getArgOperand(1))->isOneValue() ==
+               cast<Constant>(CS2->getArgOperand(1))->isOneValue();
+      }
+    }
     return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
            CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
            CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
            CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
+  }
   if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
     return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
            CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129230.442695.patch
Type: text/x-patch
Size: 3830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220706/1b84a616/attachment.bin>


More information about the llvm-commits mailing list