1 ; Test that the fwrite library call simplifier works correctly. 2 ; 3 ; RUN: opt < %s -instcombine -S | FileCheck %s 4 5 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" 6 7 %FILE = type { } 8 9 @str = constant [1 x i8] zeroinitializer 10 @empty = constant [0 x i8] zeroinitializer 11 12 declare i64 @fwrite(i8*, i64, i64, %FILE *) 13 14 ; Check fwrite(S, 1, 1, fp) -> fputc(S[0], fp). 15 16 define void @test_simplify1(%FILE* %fp) { 17 ; CHECK-LABEL: @test_simplify1( 18 %str = getelementptr inbounds [1 x i8], [1 x i8]* @str, i64 0, i64 0 19 call i64 @fwrite(i8* %str, i64 1, i64 1, %FILE* %fp) 20 ; CHECK-NEXT: call i32 @fputc(i32 0, %FILE* %fp) 21 ret void 22 ; CHECK-NEXT: ret void 23 } 24 25 define void @test_simplify2(%FILE* %fp) { 26 ; CHECK-LABEL: @test_simplify2( 27 %str = getelementptr inbounds [0 x i8], [0 x i8]* @empty, i64 0, i64 0 28 call i64 @fwrite(i8* %str, i64 1, i64 0, %FILE* %fp) 29 ret void 30 ; CHECK-NEXT: ret void 31 } 32 33 define void @test_simplify3(%FILE* %fp) { 34 ; CHECK-LABEL: @test_simplify3( 35 %str = getelementptr inbounds [0 x i8], [0 x i8]* @empty, i64 0, i64 0 36 call i64 @fwrite(i8* %str, i64 0, i64 1, %FILE* %fp) 37 ret void 38 ; CHECK-NEXT: ret void 39 } 40 41 define i64 @test_no_simplify1(%FILE* %fp) { 42 ; CHECK-LABEL: @test_no_simplify1( 43 %str = getelementptr inbounds [1 x i8], [1 x i8]* @str, i64 0, i64 0 44 %ret = call i64 @fwrite(i8* %str, i64 1, i64 1, %FILE* %fp) 45 ; CHECK-NEXT: call i64 @fwrite 46 ret i64 %ret 47 ; CHECK-NEXT: ret i64 %ret 48 } 49 50 define void @test_no_simplify2(%FILE* %fp, i64 %size) { 51 ; CHECK-LABEL: @test_no_simplify2( 52 %str = getelementptr inbounds [1 x i8], [1 x i8]* @str, i64 0, i64 0 53 call i64 @fwrite(i8* %str, i64 %size, i64 1, %FILE* %fp) 54 ; CHECK-NEXT: call i64 @fwrite 55 ret void 56 ; CHECK-NEXT: ret void 57 } 58