[PATCH] D129025: [SimplifyCFG] Skip hoisting common instructions that return token type

Yuanfang Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 1 15:57:35 PDT 2022


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

By LangRef, hoisting token-returning instructions obsures the origin
so it should be skipped. Found this issue while investigating a
CoroSplit pass crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129025

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll


Index: llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -passes='simplifycfg<hoist-common-insts>' -S | FileCheck %s
+
+; CHECK: call token @llvm.coro.save(ptr null)
+; CHECK: call token @llvm.coro.save(ptr null)
+
+declare token @llvm.coro.save(ptr)
+declare i8 @llvm.coro.suspend(token, i1)
+
+define void @f(i32 %x) {
+entry:
+  br label %while.cond
+
+while.cond:
+  %cmp = icmp slt i32 %x, 0
+  br i1 %cmp, label %await.suspend, label %final.suspend
+
+await.suspend:
+  %0 = call token @llvm.coro.save(ptr null)
+  %1 = call i8 @llvm.coro.suspend(token %0, i1 false)
+  switch i8 %1, label %coro.ret [
+    i8 0, label %while.cond
+    i8 1, label %cleanup
+  ]
+
+final.suspend:
+  %2 = call token @llvm.coro.save(ptr null)
+  %3 = call i8 @llvm.coro.suspend(token %2, i1 true)
+  %switch = icmp ult i8 %3, 2
+  br i1 %switch, label %cleanup, label %coro.ret
+
+cleanup:
+  br label %coro.ret
+
+coro.ret:
+  ret void
+}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1476,6 +1476,7 @@
   // FIXME: Can we define a safety predicate for CallBr?
   if (isa<PHINode>(I1) || !I1->isIdenticalToWhenDefined(I2) ||
       (isa<InvokeInst>(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2)) ||
+      I1->getType()->isTokenTy() || I2->getType()->isTokenTy() ||
       isa<CallBrInst>(I1))
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129025.441804.patch
Type: text/x-patch
Size: 1647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220701/2f99d865/attachment.bin>


More information about the llvm-commits mailing list