Home | History | Annotate | Download | only in InstCombine
      1 ; Test that the fputs 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 @empty = constant [1 x i8] zeroinitializer
     10 @A = constant [2 x i8] c"A\00"
     11 @hello = constant [7 x i8] c"hello\0A\00"
     12 
     13 declare i32 @fputs(i8*, %FILE*)
     14 
     15 ; Check fputs(str, fp) --> fwrite(str, 1, strlen(s), fp).
     16 
     17 define void @test_simplify1(%FILE* %fp) {
     18 ; CHECK-LABEL: @test_simplify1(
     19   %str = getelementptr [1 x i8]* @empty, i32 0, i32 0
     20   call i32 @fputs(i8* %str, %FILE* %fp)
     21   ret void
     22 ; CHECK-NEXT: ret void
     23 }
     24 
     25 ; NOTE: The fwrite simplifier simplifies this further to fputc.
     26 
     27 define void @test_simplify2(%FILE* %fp) {
     28 ; CHECK-LABEL: @test_simplify2(
     29   %str = getelementptr [2 x i8]* @A, i32 0, i32 0
     30   call i32 @fputs(i8* %str, %FILE* %fp)
     31 ; CHECK-NEXT: call i32 @fputc(i32 65, %FILE* %fp)
     32   ret void
     33 ; CHECK-NEXT: ret void
     34 }
     35 
     36 define void @test_simplify3(%FILE* %fp) {
     37 ; CHECK-LABEL: @test_simplify3(
     38   %str = getelementptr [7 x i8]* @hello, i32 0, i32 0
     39   call i32 @fputs(i8* %str, %FILE* %fp)
     40 ; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([7 x i8]* @hello, i32 0, i32 0), i32 6, i32 1, %FILE* %fp)
     41   ret void
     42 ; CHECK-NEXT: ret void
     43 }
     44