[llvm] ce6ca00 - [CoroSplit] Avoid self-replacement
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 14 05:53:38 PDT 2022
Author: Nikita Popov
Date: 2022-03-14T13:53:31+01:00
New Revision: ce6ca00a92007a9104c040a402c4bd2b8e1dfcd7
URL: https://github.com/llvm/llvm-project/commit/ce6ca00a92007a9104c040a402c4bd2b8e1dfcd7
DIFF: https://github.com/llvm/llvm-project/commit/ce6ca00a92007a9104c040a402c4bd2b8e1dfcd7.diff
LOG: [CoroSplit] Avoid self-replacement
With opaque pointers, the bitcast might be a no-op, and this can
end up trying to replace a value with itself, which is illegal.
Added:
Modified:
llvm/lib/Transforms/Coroutines/CoroSplit.cpp
llvm/test/Transforms/Coroutines/coro-split-recursive.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
index 192743bc0ebf4..790ff4d92d347 100644
--- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1015,7 +1015,8 @@ void CoroCloner::create() {
auto *NewVFrame = Builder.CreateBitCast(
NewFramePtr, Type::getInt8PtrTy(Builder.getContext()), "vFrame");
Value *OldVFrame = cast<Value>(VMap[Shape.CoroBegin]);
- OldVFrame->replaceAllUsesWith(NewVFrame);
+ if (OldVFrame != NewVFrame)
+ OldVFrame->replaceAllUsesWith(NewVFrame);
switch (Shape.ABI) {
case coro::ABI::Switch:
diff --git a/llvm/test/Transforms/Coroutines/coro-split-recursive.ll b/llvm/test/Transforms/Coroutines/coro-split-recursive.ll
index 658e38f057387..f85107dce9c9d 100644
--- a/llvm/test/Transforms/Coroutines/coro-split-recursive.ll
+++ b/llvm/test/Transforms/Coroutines/coro-split-recursive.ll
@@ -1,4 +1,5 @@
-; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -S < %s | FileCheck %s
+; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -opaque-pointers=0 -S < %s | FileCheck %s
+; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -opaque-pointers=1 -S < %s | FileCheck %s
declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
More information about the llvm-commits
mailing list