From cd3eb99016611c003c274112e21f9cd796ecf0b8 Mon Sep 17 00:00:00 2001 From: David Bolvansky Date: Wed, 23 May 2018 03:01:45 +0000 Subject: [InstCombine] [NFC] Added more tests for unlocked IO transformation Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47243 llvm-svn: 333057 --- llvm/test/Transforms/InstCombine/unlocked-stdio.ll | 35 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'llvm/test/Transforms') diff --git a/llvm/test/Transforms/InstCombine/unlocked-stdio.ll b/llvm/test/Transforms/InstCombine/unlocked-stdio.ll index 77eb9188138..f10772bc802 100644 --- a/llvm/test/Transforms/InstCombine/unlocked-stdio.ll +++ b/llvm/test/Transforms/InstCombine/unlocked-stdio.ll @@ -7,6 +7,7 @@ @.str = private unnamed_addr constant [5 x i8] c"file\00", align 1 @.str.1 = private unnamed_addr constant [2 x i8] c"w\00", align 1 @.str.2 = private unnamed_addr constant [4 x i8] c"str\00", align 1 +@stdout = external global %struct._IO_FILE*, align 8 @global_file = common global %struct._IO_FILE* null, align 8 define void @external_fgetc_test(%struct._IO_FILE* %f) { @@ -189,9 +190,35 @@ define void @test_captured_by_global_value() { ret void } +define void @test_captured_by_standard_stream(i8* nocapture readonly %s) { +; CHECK-LABEL: @test_captured_by_standard_stream( +; CHECK-NEXT: [[CALL:%.*]] = tail call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)) +; CHECK-NEXT: [[TMP:%.*]] = load %struct._IO_FILE*, %struct._IO_FILE** @stdout, align 8 +; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @fputs(i8* [[S:%.*]], %struct._IO_FILE* [[TMP]]) +; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @fclose(%struct._IO_FILE* [[TMP]]) +; CHECK-NEXT: ret void +; + %call = tail call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)) + %tmp = load %struct._IO_FILE*, %struct._IO_FILE** @stdout, align 8 + %call1 = tail call i32 @fputs(i8* %s, %struct._IO_FILE* %tmp) + %call2 = tail call i32 @fclose(%struct._IO_FILE* %tmp) + ret void +} +define void @test_captured_by_arg(i8* nocapture readonly %s, %struct._IO_FILE* nocapture %file) { +; CHECK-LABEL: @test_captured_by_arg( +; CHECK-NEXT: [[CALL:%.*]] = tail call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)) +; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @fputs(i8* [[S:%.*]], %struct._IO_FILE* [[FILE:%.*]]) +; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @fclose(%struct._IO_FILE* [[FILE]]) +; CHECK-NEXT: ret void +; + %call = tail call %struct._IO_FILE* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)) + %call1 = tail call i32 @fputs(i8* %s, %struct._IO_FILE* %file) + %call2 = tail call i32 @fclose(%struct._IO_FILE* %file) + ret void +} -declare i64 @fwrite(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) #0 -declare i64 @fread(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) #0 -declare i32 @fputs(i8* nocapture readonly, %struct._IO_FILE* nocapture) #0 -declare i8* @fgets(i8*, i32, %struct._IO_FILE* nocapture) #0 +declare i64 @fwrite(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) +declare i64 @fread(i8* nocapture, i64, i64, %struct._IO_FILE* nocapture) +declare i32 @fputs(i8* nocapture readonly, %struct._IO_FILE* nocapture) +declare i8* @fgets(i8*, i32, %struct._IO_FILE* nocapture) -- cgit v1.2.3