1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; Test that the printf library call simplifier works correctly.
3;
4; RUN: opt < %s -instcombine -S | FileCheck %s
5
6target 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"
7
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"
13
14declare void @printf(i8*, ...)
15
16; Check simplification of printf with void return type.
17
18define void @test_simplify1() {
19; CHECK-LABEL: @test_simplify1(
20; CHECK-NEXT:    [[PUTCHAR:%.*]] = call i32 @putchar(i32 104)
21; CHECK-NEXT:    ret void
22;
23  %fmt = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0
24  call void (i8*, ...) @printf(i8* %fmt)
25  ret void
26}
27
28define 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
32;
33  %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
34  call void (i8*, ...) @printf(i8* %fmt)
35  ret void
36}
37
38define 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
42;
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)
46  ret void
47}
48
49define void @test_simplify7() {
50; CHECK-LABEL: @test_simplify7(
51; CHECK-NEXT:    [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)
52; CHECK-NEXT:    ret void
53;
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)
57  ret void
58}
59