[llvm] 0387679 - [Coroutines] Presubmit retcon without suspend test
Sebastian Neubauer via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 14 01:47:01 PST 2022
Author: Sebastian Neubauer
Date: 2022-11-14T10:46:33+01:00
New Revision: 0387679e3ea2adfa12098a0ba1817180e56c4555
URL: https://github.com/llvm/llvm-project/commit/0387679e3ea2adfa12098a0ba1817180e56c4555
DIFF: https://github.com/llvm/llvm-project/commit/0387679e3ea2adfa12098a0ba1817180e56c4555.diff
LOG: [Coroutines] Presubmit retcon without suspend test
The test gets incorrectly optimized to unreachable.
Added:
Modified:
llvm/test/Transforms/Coroutines/coro-retcon.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/Coroutines/coro-retcon.ll b/llvm/test/Transforms/Coroutines/coro-retcon.ll
index 719ab58b0c822..c092709e0fef4 100644
--- a/llvm/test/Transforms/Coroutines/coro-retcon.ll
+++ b/llvm/test/Transforms/Coroutines/coro-retcon.ll
@@ -1,6 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; First example from Doc/Coroutines.rst (two block loop) converted to retcon
; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
+; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split),module(coro-cleanup)' -S | FileCheck --check-prefix=CORO %s
define i8* @f(i8* %buffer, i32 %n) {
; CHECK-LABEL: @f(
@@ -10,6 +11,15 @@ define i8* @f(i8* %buffer, i32 %n) {
; CHECK-NEXT: tail call void @print(i32 [[N]])
; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i1)* @f.resume.0 to i8*)
;
+; CORO-LABEL: @f(
+; CORO-NEXT: entry:
+; CORO-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[BUFFER:%.*]] to %f.Frame*
+; CORO-NEXT: [[N_VAL_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR]], i32 0, i32 0
+; CORO-NEXT: store i32 [[N:%.*]], i32* [[N_VAL_SPILL_ADDR]], align 4
+; CORO-NEXT: call void @print(i32 [[N]])
+; CORO-NEXT: [[TMP0:%.*]] = bitcast i8* (i8*, i1)* @f.resume.0 to i8*
+; CORO-NEXT: ret i8* [[TMP0]]
+;
entry:
%id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
%hdl = call i8* @llvm.coro.begin(token %id, i8* null)
@@ -35,11 +45,24 @@ cleanup:
define i32 @main() {
; CHECK-LABEL: @main(
; CHECK-NEXT: entry:
-; CHECK-NEXT: call void @print(i32 4)
-; CHECK-NEXT: call void @print(i32 5), !noalias !0
-; CHECK-NEXT: call void @print(i32 6), !noalias !3
+; CHECK-NEXT: tail call void @print(i32 4)
+; CHECK-NEXT: tail call void @print(i32 5), !noalias !0
+; CHECK-NEXT: tail call void @print(i32 6), !noalias !3
; CHECK-NEXT: ret i32 0
;
+; CORO-LABEL: @main(
+; CORO-NEXT: entry:
+; CORO-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 4
+; CORO-NEXT: [[BUFFER:%.*]] = bitcast [8 x i8]* [[TMP0]] to i8*
+; CORO-NEXT: [[CONT0:%.*]] = call i8* @f(i8* [[BUFFER]], i32 4)
+; CORO-NEXT: [[CONT0_CAST:%.*]] = bitcast i8* [[CONT0]] to i8* (i8*, i1)*
+; CORO-NEXT: [[CONT1:%.*]] = call i8* [[CONT0_CAST]](i8* [[BUFFER]], i1 zeroext false)
+; CORO-NEXT: [[CONT1_CAST:%.*]] = bitcast i8* [[CONT1]] to i8* (i8*, i1)*
+; CORO-NEXT: [[CONT2:%.*]] = call i8* [[CONT1_CAST]](i8* [[BUFFER]], i1 zeroext false)
+; CORO-NEXT: [[CONT2_CAST:%.*]] = bitcast i8* [[CONT2]] to i8* (i8*, i1)*
+; CORO-NEXT: [[TMP1:%.*]] = call i8* [[CONT2_CAST]](i8* [[BUFFER]], i1 zeroext true)
+; CORO-NEXT: ret i32 0
+;
entry:
%0 = alloca [8 x i8], align 4
%buffer = bitcast [8 x i8]* %0 to i8*
@@ -70,6 +93,22 @@ define hidden { i8*, i8* } @g(i8* %buffer, i16* %ptr) {
; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { i8*, i8* } { i8* bitcast ({ i8*, i8* } (i8*, i1)* @g.resume.0 to i8*), i8* undef }, i8* [[TMP2]], 1
; CHECK-NEXT: ret { i8*, i8* } [[TMP3]]
;
+; CORO-LABEL: @g(
+; CORO-NEXT: entry:
+; CORO-NEXT: [[TMP0:%.*]] = call i8* @allocate(i32 8)
+; CORO-NEXT: [[TMP1:%.*]] = bitcast i8* [[BUFFER:%.*]] to i8**
+; CORO-NEXT: store i8* [[TMP0]], i8** [[TMP1]], align 8
+; CORO-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[TMP0]] to %g.Frame*
+; CORO-NEXT: [[PTR_SPILL_ADDR:%.*]] = getelementptr inbounds [[G_FRAME:%.*]], %g.Frame* [[FRAMEPTR]], i32 0, i32 0
+; CORO-NEXT: store i16* [[PTR:%.*]], i16** [[PTR_SPILL_ADDR]], align 8
+; CORO-NEXT: [[PTR_RELOAD_ADDR:%.*]] = getelementptr inbounds [[G_FRAME]], %g.Frame* [[FRAMEPTR]], i32 0, i32 0
+; CORO-NEXT: [[PTR_RELOAD:%.*]] = load i16*, i16** [[PTR_RELOAD_ADDR]], align 8
+; CORO-NEXT: [[PTR2:%.*]] = bitcast i16* [[PTR_RELOAD]] to i8*
+; CORO-NEXT: [[TMP2:%.*]] = bitcast { i8*, i8* } (i8*, i1)* @g.resume.0 to i8*
+; CORO-NEXT: [[TMP3:%.*]] = insertvalue { i8*, i8* } undef, i8* [[TMP2]], 0
+; CORO-NEXT: [[TMP4:%.*]] = insertvalue { i8*, i8* } [[TMP3]], i8* [[PTR2]], 1
+; CORO-NEXT: ret { i8*, i8* } [[TMP4]]
+;
entry:
%id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast ({ i8*, i8* } (i8*, i1)* @g_prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
%hdl = call i8* @llvm.coro.begin(token %id, i8* null)
@@ -88,12 +127,45 @@ cleanup:
unreachable
}
+define i8* @nosuspend(i8* %buffer, i32 %n) {
+; CHECK-LABEL: @nosuspend(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: unreachable
+;
+; CORO-LABEL: @nosuspend(
+; CORO-NEXT: entry:
+; CORO-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* undef to %nosuspend.Frame*
+; CORO-NEXT: [[A:%.*]] = getelementptr inbounds [[NOSUSPEND_FRAME:%.*]], %nosuspend.Frame* [[FRAMEPTR]], i32 0, i32 0
+; CORO-NEXT: store i32 [[N:%.*]], i32* [[A]], align 4
+; CORO-NEXT: call void @use_var_ptr(i32* [[A]])
+; CORO-NEXT: [[AL:%.*]] = load i32, i32* [[A]], align 4
+; CORO-NEXT: call void @use_var(i32 [[AL]])
+; CORO-NEXT: ret i8* null
+;
+entry:
+ %id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
+ %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
+ %a = alloca i32
+ store i32 %n, i32* %a
+ br label %cleanup
+
+cleanup:
+ call void @use_var_ptr(i32* %a)
+ %al = load i32, i32* %a
+ call void @use_var(i32 %al)
+ call i1 @llvm.coro.end(i8* %hdl, i1 0)
+ ret i8* %hdl
+}
+
declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*)
declare i8* @llvm.coro.begin(token, i8*)
declare i1 @llvm.coro.suspend.retcon.i1(...)
declare i1 @llvm.coro.end(i8*, i1)
declare i8* @llvm.coro.prepare.retcon(i8*)
+declare void @use_var(i32)
+declare void @use_var_ptr(i32*)
+
declare i8* @prototype(i8*, i1 zeroext)
declare {i8*,i8*} @g_prototype(i8*, i1 zeroext)
More information about the llvm-commits
mailing list