1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test that the printf library call simplifier works correctly.
4 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 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"
8 @hello_world = constant [13 x i8] c"hello world\0A\00"
9 @h = constant [2 x i8] c"h\00"
10 @percent_s = constant [4 x i8] c"%s\0A\00"
11 @format_str = constant [3 x i8] c"%s\00"
12 @charstr = constant [2 x i8] c"a\00"
14 declare void @printf(i8*, ...)
16 ; Check simplification of printf with void return type.
18 define void @test_simplify1() {
19 ; CHECK-LABEL: @test_simplify1(
20 ; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 104)
21 ; CHECK-NEXT: ret void
23 %fmt = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0
24 call void (i8*, ...) @printf(i8* %fmt)
28 define void @test_simplify2() {
29 ; CHECK-LABEL: @test_simplify2(
30 ; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i32 0, i32 0))
31 ; CHECK-NEXT: ret void
33 %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
34 call void (i8*, ...) @printf(i8* %fmt)
38 define void @test_simplify6() {
39 ; CHECK-LABEL: @test_simplify6(
40 ; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0))
41 ; CHECK-NEXT: ret void
43 %fmt = getelementptr [4 x i8], [4 x i8]* @percent_s, i32 0, i32 0
44 %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
45 call void (i8*, ...) @printf(i8* %fmt, i8* %str)
49 define void @test_simplify7() {
50 ; CHECK-LABEL: @test_simplify7(
51 ; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)
52 ; CHECK-NEXT: ret void
54 %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
55 %str = getelementptr [2 x i8], [2 x i8]* @charstr, i32 0, i32 0
56 call void (i8*, ...) @printf(i8* %fmt, i8* %str)