105 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals2; Test that the printf library call simplifier works correctly.3;4; RUN: opt < %s -passes=instcombine -S | FileCheck %s5 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@empty = constant [1 x i8] c"\00"14 15declare i32 @printf(ptr, ...)16 17; Check simplification of printf with void return type.18 19;.20; CHECK: @[[HELLO_WORLD:[a-zA-Z0-9_$"\\.-]+]] = constant [13 x i8] c"hello world\0A\00"21; CHECK: @[[H:[a-zA-Z0-9_$"\\.-]+]] = constant [2 x i8] c"h\00"22; CHECK: @[[PERCENT_S:[a-zA-Z0-9_$"\\.-]+]] = constant [4 x i8] c"%s\0A\00"23; CHECK: @[[FORMAT_STR:[a-zA-Z0-9_$"\\.-]+]] = constant [3 x i8] c"%s\00"24; CHECK: @[[CHARSTR:[a-zA-Z0-9_$"\\.-]+]] = constant [2 x i8] c"a\00"25; CHECK: @[[EMPTY:[a-zA-Z0-9_$"\\.-]+]] = constant [1 x i8] zeroinitializer26; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 127; CHECK: @[[STR_1:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 128; CHECK: @[[STR_2:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 129;.30define void @test_simplify1() {31; CHECK-LABEL: @test_simplify1(32; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 104)33; CHECK-NEXT: ret void34;35 call i32 (ptr, ...) @printf(ptr @h)36 ret void37}38 39define void @test_simplify2() {40; CHECK-LABEL: @test_simplify2(41; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)42; CHECK-NEXT: ret void43;44 call i32 (ptr, ...) @printf(ptr @hello_world)45 ret void46}47 48define void @test_simplify6() {49; CHECK-LABEL: @test_simplify6(50; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)51; CHECK-NEXT: ret void52;53 call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world)54 ret void55}56 57define void @test_simplify7() {58; CHECK-LABEL: @test_simplify7(59; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)60; CHECK-NEXT: ret void61;62 call i32 (ptr, ...) @printf(ptr @format_str, ptr @charstr)63 ret void64}65 66; printf("%s", "") --> noop67 68define void @test_simplify8() {69; CHECK-LABEL: @test_simplify8(70; CHECK-NEXT: ret void71;72 call i32 (ptr, ...) @printf(ptr @format_str, ptr @empty)73 ret void74}75 76; printf("%s", str"\n") --> puts(str)77 78define void @test_simplify9() {79; CHECK-LABEL: @test_simplify9(80; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str.1)81; CHECK-NEXT: ret void82;83 call i32 (ptr, ...) @printf(ptr @format_str, ptr @hello_world)84 ret void85}86 87; printf("%s", "", ...) --> noop88; printf("%s", "a", ...) --> putchar('a')89; printf("%s", str"\n", ...) --> puts(str)90 91define void @test_simplify10() {92; CHECK-LABEL: @test_simplify10(93; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)94; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str.2)95; CHECK-NEXT: ret void96;97 call i32 (ptr, ...) @printf(ptr @format_str, ptr @empty, i32 42, double 0x40091EB860000000)98 call i32 (ptr, ...) @printf(ptr @format_str, ptr @charstr, i32 42, double 0x40091EB860000000)99 call i32 (ptr, ...) @printf(ptr @format_str, ptr @hello_world, i32 42, double 0x40091EB860000000)100 ret void101}102;.103; CHECK: attributes #[[ATTR0:[0-9]+]] = { nofree nounwind }104;.105