[llvm] [llvm][Coroutines] Remove no-op ptr-to-ptr bitcasts (NFC) (PR #73427)
Youngsuk Kim via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 25 23:23:07 PST 2023
https://github.com/JOE1994 updated https://github.com/llvm/llvm-project/pull/73427
>From 46e9666263acbd55deb55bb858b2e60236cea464 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim <joseph942010 at gmail.com>
Date: Sun, 26 Nov 2023 01:18:58 -0500
Subject: [PATCH 1/2] [llvm][Coroutines] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort
---
llvm/lib/Transforms/Coroutines/CoroCleanup.cpp | 4 +---
llvm/lib/Transforms/Coroutines/Coroutines.cpp | 13 ++++---------
2 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
index 5c10d4ddaacd512..3e3825fcd50e23d 100644
--- a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp
@@ -29,15 +29,13 @@ struct Lowerer : coro::LowererBase {
static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
Builder.SetInsertPoint(SubFn);
- Value *FrameRaw = SubFn->getFrame();
+ Value *FramePtr = SubFn->getFrame();
int Index = SubFn->getIndex();
auto *FrameTy = StructType::get(SubFn->getContext(),
{Builder.getPtrTy(), Builder.getPtrTy()});
- PointerType *FramePtrTy = FrameTy->getPointerTo();
Builder.SetInsertPoint(SubFn);
- auto *FramePtr = Builder.CreateBitCast(FrameRaw, FramePtrTy);
auto *Gep = Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0, Index);
auto *Load = Builder.CreateLoad(FrameTy->getElementType(Index), Gep);
diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
index 61cfbecfbe9be89..eef5543bae24ab9 100644
--- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp
+++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp
@@ -42,11 +42,10 @@ coro::LowererBase::LowererBase(Module &M)
/*isVarArg=*/false)),
NullPtr(ConstantPointerNull::get(Int8Ptr)) {}
-// Creates a sequence of instructions to obtain a resume function address using
-// llvm.coro.subfn.addr. It generates the following sequence:
+// Creates a call to llvm.coro.subfn.addr to obtain a resume function address.
+// It generates the following:
//
-// call i8* @llvm.coro.subfn.addr(i8* %Arg, i8 %index)
-// bitcast i8* %2 to void(i8*)*
+// call ptr @llvm.coro.subfn.addr(ptr %Arg, i8 %index)
Value *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
Instruction *InsertPt) {
@@ -56,11 +55,7 @@ Value *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
assert(Index >= CoroSubFnInst::IndexFirst &&
Index < CoroSubFnInst::IndexLast &&
"makeSubFnCall: Index value out of range");
- auto *Call = CallInst::Create(Fn, {Arg, IndexVal}, "", InsertPt);
-
- auto *Bitcast =
- new BitCastInst(Call, ResumeFnType->getPointerTo(), "", InsertPt);
- return Bitcast;
+ return CallInst::Create(Fn, {Arg, IndexVal}, "", InsertPt);
}
// NOTE: Must be sorted!
>From ee740f93efae2a980507a138132e29f927cc9242 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim <youngsuk.kim at hpe.com>
Date: Sun, 26 Nov 2023 01:18:33 -0600
Subject: [PATCH 2/2] Remove ptr-to-ptr bitcast checks from
coro-resume-destroy.ll
---
.../test/Transforms/Coroutines/coro-resume-destroy.ll | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/llvm/test/Transforms/Coroutines/coro-resume-destroy.ll b/llvm/test/Transforms/Coroutines/coro-resume-destroy.ll
index e5e828dd6abffdd..157aa8e372e69b3 100644
--- a/llvm/test/Transforms/Coroutines/coro-resume-destroy.ll
+++ b/llvm/test/Transforms/Coroutines/coro-resume-destroy.ll
@@ -6,13 +6,11 @@ define void @callResume(ptr %hdl) {
; CHECK-NEXT: entry
entry:
; CHECK-NEXT: %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)
-; CHECK-NEXT: %1 = bitcast ptr %0 to ptr
-; CHECK-NEXT: call fastcc void %1(ptr %hdl)
+; CHECK-NEXT: call fastcc void %0(ptr %hdl)
call void @llvm.coro.resume(ptr %hdl)
-; CHECK-NEXT: %2 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)
-; CHECK-NEXT: %3 = bitcast ptr %2 to ptr
-; CHECK-NEXT: call fastcc void %3(ptr %hdl)
+; CHECK-NEXT: %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)
+; CHECK-NEXT: call fastcc void %1(ptr %hdl)
call void @llvm.coro.destroy(ptr %hdl)
ret void
@@ -24,8 +22,7 @@ define void @eh(ptr %hdl) personality ptr null {
; CHECK-NEXT: entry
entry:
; CHECK-NEXT: %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)
-; CHECK-NEXT: %1 = bitcast ptr %0 to ptr
-; CHECK-NEXT: invoke fastcc void %1(ptr %hdl)
+; CHECK-NEXT: invoke fastcc void %0(ptr %hdl)
invoke void @llvm.coro.resume(ptr %hdl)
to label %cont unwind label %ehcleanup
cont:
More information about the llvm-commits
mailing list