Skip to content

Commit 6070aeb

Browse files
committed
[Coro] Use poison instead of undef as placeholder [NFC]
1 parent 928460a commit 6070aeb

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

llvm/lib/Transforms/Coroutines/CoroCleanup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool Lowerer::lower(Function &F) {
7878
case Intrinsic::coro_end:
7979
case Intrinsic::coro_suspend_retcon:
8080
if (IsPrivateAndUnprocessed) {
81-
II->replaceAllUsesWith(UndefValue::get(II->getType()));
81+
II->replaceAllUsesWith(PoisonValue::get(II->getType()));
8282
} else
8383
continue;
8484
break;

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End,
375375
if (auto *RetStructTy = dyn_cast<StructType>(RetTy)) {
376376
assert(RetStructTy->getNumElements() == NumReturns &&
377377
"numbers of returns should match resume function singature");
378-
Value *ReturnValue = UndefValue::get(RetStructTy);
378+
Value *ReturnValue = PoisonValue::get(RetStructTy);
379379
unsigned Idx = 0;
380380
for (Value *RetValEl : CoroResults->return_values())
381381
ReturnValue = Builder.CreateInsertValue(ReturnValue, RetValEl, Idx++);
@@ -406,7 +406,7 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End,
406406

407407
Value *ReturnValue = ConstantPointerNull::get(ContinuationTy);
408408
if (RetStructTy) {
409-
ReturnValue = Builder.CreateInsertValue(UndefValue::get(RetStructTy),
409+
ReturnValue = Builder.CreateInsertValue(PoisonValue::get(RetStructTy),
410410
ReturnValue, 0);
411411
}
412412
Builder.CreateRet(ReturnValue);
@@ -1304,7 +1304,7 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) {
13041304
case coro::ABI::Async:
13051305
case coro::ABI::Retcon:
13061306
case coro::ABI::RetconOnce:
1307-
CoroBegin->replaceAllUsesWith(UndefValue::get(CoroBegin->getType()));
1307+
CoroBegin->replaceAllUsesWith(PoisonValue::get(CoroBegin->getType()));
13081308
break;
13091309
}
13101310

@@ -1758,7 +1758,7 @@ static void replaceAsyncResumeFunction(CoroSuspendAsyncInst *Suspend,
17581758
ResumeIntrinsic->replaceAllUsesWith(Val);
17591759
ResumeIntrinsic->eraseFromParent();
17601760
Suspend->setOperand(CoroSuspendAsyncInst::ResumeFunctionArg,
1761-
UndefValue::get(Int8PtrTy));
1761+
PoisonValue::get(Int8PtrTy));
17621762
}
17631763

17641764
/// Coerce the arguments in \p FnArgs according to \p FnTy in \p CallArgs.

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,18 @@ void coro::Shape::invalidateCoroutine(
353353
assert(!CoroBegin);
354354
{
355355
// Replace coro.frame which are supposed to be lowered to the result of
356-
// coro.begin with undef.
357-
auto *Undef = UndefValue::get(PointerType::get(F.getContext(), 0));
356+
// coro.begin with poison.
357+
auto *Poison = PoisonValue::get(PointerType::get(F.getContext(), 0));
358358
for (CoroFrameInst *CF : CoroFrames) {
359-
CF->replaceAllUsesWith(Undef);
359+
CF->replaceAllUsesWith(Poison);
360360
CF->eraseFromParent();
361361
}
362362
CoroFrames.clear();
363363

364-
// Replace all coro.suspend with undef and remove related coro.saves if
364+
// Replace all coro.suspend with poison and remove related coro.saves if
365365
// present.
366366
for (AnyCoroSuspendInst *CS : CoroSuspends) {
367-
CS->replaceAllUsesWith(UndefValue::get(CS->getType()));
367+
CS->replaceAllUsesWith(PoisonValue::get(CS->getType()));
368368
CS->eraseFromParent();
369369
if (auto *CoroSave = CS->getCoroSave())
370370
CoroSave->eraseFromParent();

llvm/test/Transforms/Coroutines/coro-retcon-once-value.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ declare void @print(i32)
184184
; CHECK-NEXT: [[VAL_RELOAD:%.*]] = load i32, ptr [[VAL_RELOAD_ADDR]], align 4
185185
; CHECK-NEXT: [[NEW_VAL:%.*]] = add i32 [[VAL_RELOAD]], 123
186186
; CHECK-NEXT: tail call void @deallocate(ptr [[TMP2]])
187-
; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 undef, ptr undef }, i32 [[NEW_VAL]], 1
187+
; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 poison, ptr poison }, i32 [[NEW_VAL]], 1
188188
; CHECK-NEXT: [[TMP4:%.*]] = insertvalue { ptr, i32, ptr } [[TMP3]], ptr @deallocate, 2
189189
; CHECK-NEXT: ret { ptr, i32, ptr } [[TMP4]]
190190
;
@@ -202,7 +202,7 @@ declare void @print(i32)
202202
; CHECK-NEXT: [[VAL_RELOAD:%.*]] = load i32, ptr [[VAL_RELOAD_ADDR]], align 4
203203
; CHECK-NEXT: [[NEW_VAL:%.*]] = add i32 [[VAL_RELOAD]], 123
204204
; CHECK-NEXT: tail call void @deallocate(ptr [[TMP2]])
205-
; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 undef, ptr undef }, i32 [[NEW_VAL]], 1
205+
; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { ptr, i32, ptr } { ptr null, i32 poison, ptr poison }, i32 [[NEW_VAL]], 1
206206
; CHECK-NEXT: [[TMP4:%.*]] = insertvalue { ptr, i32, ptr } [[TMP3]], ptr @deallocate, 2
207207
; CHECK-NEXT: ret { ptr, i32, ptr } [[TMP4]]
208208
;

0 commit comments

Comments
 (0)