1 ; Test that the fwrite library call simplifier works correctly.
3 ; RUN: opt < %s -instcombine -S | FileCheck %s
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"
9 @str = constant [1 x i8] zeroinitializer
10 @empty = constant [0 x i8] zeroinitializer
12 declare i64 @fwrite(i8*, i64, i64, %FILE *)
14 ; Check fwrite(S, 1, 1, fp) -> fputc(S[0], fp).
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)
22 ; CHECK-NEXT: ret void
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)
30 ; CHECK-NEXT: ret void
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)
38 ; CHECK-NEXT: ret void
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
47 ; CHECK-NEXT: ret i64 %ret
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
56 ; CHECK-NEXT: ret void