From 6070aeb3b71520287e81e322b19f32f18ec2031a Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Tue, 5 Nov 2024 13:51:36 +0000 Subject: [PATCH] [Coro] Use poison instead of undef as placeholder [NFC] --- llvm/lib/Transforms/Coroutines/CoroCleanup.cpp | 2 +- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 8 ++++---- llvm/lib/Transforms/Coroutines/Coroutines.cpp | 10 +++++----- .../Transforms/Coroutines/coro-retcon-once-value.ll | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp index 1cda7f93f72a2c..a0a26827aa09d2 100644 --- a/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroCleanup.cpp @@ -78,7 +78,7 @@ bool Lowerer::lower(Function &F) { case Intrinsic::coro_end: case Intrinsic::coro_suspend_retcon: if (IsPrivateAndUnprocessed) { - II->replaceAllUsesWith(UndefValue::get(II->getType())); + II->replaceAllUsesWith(PoisonValue::get(II->getType())); } else continue; break; diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index 070df429bfc265..efd622123bccde 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -375,7 +375,7 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End, if (auto *RetStructTy = dyn_cast(RetTy)) { assert(RetStructTy->getNumElements() == NumReturns && "numbers of returns should match resume function singature"); - Value *ReturnValue = UndefValue::get(RetStructTy); + Value *ReturnValue = PoisonValue::get(RetStructTy); unsigned Idx = 0; for (Value *RetValEl : CoroResults->return_values()) ReturnValue = Builder.CreateInsertValue(ReturnValue, RetValEl, Idx++); @@ -406,7 +406,7 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End, Value *ReturnValue = ConstantPointerNull::get(ContinuationTy); if (RetStructTy) { - ReturnValue = Builder.CreateInsertValue(UndefValue::get(RetStructTy), + ReturnValue = Builder.CreateInsertValue(PoisonValue::get(RetStructTy), ReturnValue, 0); } Builder.CreateRet(ReturnValue); @@ -1304,7 +1304,7 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) { case coro::ABI::Async: case coro::ABI::Retcon: case coro::ABI::RetconOnce: - CoroBegin->replaceAllUsesWith(UndefValue::get(CoroBegin->getType())); + CoroBegin->replaceAllUsesWith(PoisonValue::get(CoroBegin->getType())); break; } @@ -1758,7 +1758,7 @@ static void replaceAsyncResumeFunction(CoroSuspendAsyncInst *Suspend, ResumeIntrinsic->replaceAllUsesWith(Val); ResumeIntrinsic->eraseFromParent(); Suspend->setOperand(CoroSuspendAsyncInst::ResumeFunctionArg, - UndefValue::get(Int8PtrTy)); + PoisonValue::get(Int8PtrTy)); } /// Coerce the arguments in \p FnArgs according to \p FnTy in \p CallArgs. diff --git a/llvm/lib/Transforms/Coroutines/Coroutines.cpp b/llvm/lib/Transforms/Coroutines/Coroutines.cpp index 45b9767657c66a..9032cadcdcae06 100644 --- a/llvm/lib/Transforms/Coroutines/Coroutines.cpp +++ b/llvm/lib/Transforms/Coroutines/Coroutines.cpp @@ -353,18 +353,18 @@ void coro::Shape::invalidateCoroutine( assert(!CoroBegin); { // Replace coro.frame which are supposed to be lowered to the result of - // coro.begin with undef. - auto *Undef = UndefValue::get(PointerType::get(F.getContext(), 0)); + // coro.begin with poison. + auto *Poison = PoisonValue::get(PointerType::get(F.getContext(), 0)); for (CoroFrameInst *CF : CoroFrames) { - CF->replaceAllUsesWith(Undef); + CF->replaceAllUsesWith(Poison); CF->eraseFromParent(); } CoroFrames.clear(); - // Replace all coro.suspend with undef and remove related coro.saves if + // Replace all coro.suspend with poison and remove related coro.saves if // present. for (AnyCoroSuspendInst *CS : CoroSuspends) { - CS->replaceAllUsesWith(UndefValue::get(CS->getType())); + CS->replaceAllUsesWith(PoisonValue::get(CS->getType())); CS->eraseFromParent(); if (auto *CoroSave = CS->getCoroSave()) CoroSave->eraseFromParent(); diff --git a/llvm/test/Transforms/Coroutines/coro-retcon-once-value.ll b/llvm/test/Transforms/Coroutines/coro-retcon-once-value.ll index 2ee515f0a1a91e..b2da9affcd500a 100644 --- a/llvm/test/Transforms/Coroutines/coro-retcon-once-value.ll +++ b/llvm/test/Transforms/Coroutines/coro-retcon-once-value.ll @@ -184,7 +184,7 @@ declare void @print(i32) ; CHECK-NEXT: [[VAL_RELOAD:%.*]] = load i32, ptr [[VAL_RELOAD_ADDR]], align 4 ; CHECK-NEXT: [[NEW_VAL:%.*]] = add i32 [[VAL_RELOAD]], 123 ; CHECK-NEXT: tail call void @deallocate(ptr [[TMP2]]) -; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 undef, ptr undef }, i32 [[NEW_VAL]], 1 +; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 poison, ptr poison }, i32 [[NEW_VAL]], 1 ; CHECK-NEXT: [[TMP4:%.*]] = insertvalue { ptr, i32, ptr } [[TMP3]], ptr @deallocate, 2 ; CHECK-NEXT: ret { ptr, i32, ptr } [[TMP4]] ; @@ -202,7 +202,7 @@ declare void @print(i32) ; CHECK-NEXT: [[VAL_RELOAD:%.*]] = load i32, ptr [[VAL_RELOAD_ADDR]], align 4 ; CHECK-NEXT: [[NEW_VAL:%.*]] = add i32 [[VAL_RELOAD]], 123 ; CHECK-NEXT: tail call void @deallocate(ptr [[TMP2]]) -; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 undef, ptr undef }, i32 [[NEW_VAL]], 1 +; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 poison, ptr poison }, i32 [[NEW_VAL]], 1 ; CHECK-NEXT: [[TMP4:%.*]] = insertvalue { ptr, i32, ptr } [[TMP3]], ptr @deallocate, 2 ; CHECK-NEXT: ret { ptr, i32, ptr } [[TMP4]] ;