Skip to content

Commit f42eb15

Browse files
authored
[llvm][Coroutines] Remove no-op ptr-to-ptr bitcasts (NFC) (#73427)
Opaque ptr cleanup effort
1 parent 9ba74c2 commit f42eb15

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

llvm/lib/Transforms/Coroutines/CoroCleanup.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ struct Lowerer : coro::LowererBase {
2929

3030
static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
3131
Builder.SetInsertPoint(SubFn);
32-
Value *FrameRaw = SubFn->getFrame();
32+
Value *FramePtr = SubFn->getFrame();
3333
int Index = SubFn->getIndex();
3434

3535
auto *FrameTy = StructType::get(SubFn->getContext(),
3636
{Builder.getPtrTy(), Builder.getPtrTy()});
37-
PointerType *FramePtrTy = FrameTy->getPointerTo();
3837

3938
Builder.SetInsertPoint(SubFn);
40-
auto *FramePtr = Builder.CreateBitCast(FrameRaw, FramePtrTy);
4139
auto *Gep = Builder.CreateConstInBoundsGEP2_32(FrameTy, FramePtr, 0, Index);
4240
auto *Load = Builder.CreateLoad(FrameTy->getElementType(Index), Gep);
4341

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ coro::LowererBase::LowererBase(Module &M)
4242
/*isVarArg=*/false)),
4343
NullPtr(ConstantPointerNull::get(Int8Ptr)) {}
4444

45-
// Creates a sequence of instructions to obtain a resume function address using
46-
// llvm.coro.subfn.addr. It generates the following sequence:
45+
// Creates a call to llvm.coro.subfn.addr to obtain a resume function address.
46+
// It generates the following:
4747
//
48-
// call i8* @llvm.coro.subfn.addr(i8* %Arg, i8 %index)
49-
// bitcast i8* %2 to void(i8*)*
48+
// call ptr @llvm.coro.subfn.addr(ptr %Arg, i8 %index)
5049

5150
Value *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
5251
Instruction *InsertPt) {
@@ -56,11 +55,7 @@ Value *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
5655
assert(Index >= CoroSubFnInst::IndexFirst &&
5756
Index < CoroSubFnInst::IndexLast &&
5857
"makeSubFnCall: Index value out of range");
59-
auto *Call = CallInst::Create(Fn, {Arg, IndexVal}, "", InsertPt);
60-
61-
auto *Bitcast =
62-
new BitCastInst(Call, ResumeFnType->getPointerTo(), "", InsertPt);
63-
return Bitcast;
58+
return CallInst::Create(Fn, {Arg, IndexVal}, "", InsertPt);
6459
}
6560

6661
// NOTE: Must be sorted!

llvm/test/Transforms/Coroutines/coro-resume-destroy.ll

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ define void @callResume(ptr %hdl) {
66
; CHECK-NEXT: entry
77
entry:
88
; CHECK-NEXT: %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)
9-
; CHECK-NEXT: %1 = bitcast ptr %0 to ptr
10-
; CHECK-NEXT: call fastcc void %1(ptr %hdl)
9+
; CHECK-NEXT: call fastcc void %0(ptr %hdl)
1110
call void @llvm.coro.resume(ptr %hdl)
1211

13-
; CHECK-NEXT: %2 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)
14-
; CHECK-NEXT: %3 = bitcast ptr %2 to ptr
15-
; CHECK-NEXT: call fastcc void %3(ptr %hdl)
12+
; CHECK-NEXT: %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)
13+
; CHECK-NEXT: call fastcc void %1(ptr %hdl)
1614
call void @llvm.coro.destroy(ptr %hdl)
1715

1816
ret void
@@ -24,8 +22,7 @@ define void @eh(ptr %hdl) personality ptr null {
2422
; CHECK-NEXT: entry
2523
entry:
2624
; CHECK-NEXT: %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)
27-
; CHECK-NEXT: %1 = bitcast ptr %0 to ptr
28-
; CHECK-NEXT: invoke fastcc void %1(ptr %hdl)
25+
; CHECK-NEXT: invoke fastcc void %0(ptr %hdl)
2926
invoke void @llvm.coro.resume(ptr %hdl)
3027
to label %cont unwind label %ehcleanup
3128
cont:

0 commit comments

Comments
 (0)