diff --git a/llvm/test/Transforms/InstCombine/printf-2.ll b/llvm/test/Transforms/InstCombine/printf-2.ll --- a/llvm/test/Transforms/InstCombine/printf-2.ll +++ b/llvm/test/Transforms/InstCombine/printf-2.ll @@ -10,6 +10,7 @@ @percent_s = constant [4 x i8] c"%s\0A\00" @format_str = constant [3 x i8] c"%s\00" @charstr = constant [2 x i8] c"a\00" +@empty = constant [1 x i8] c"\00" declare void @printf(i8*, ...) @@ -21,6 +22,7 @@ ; CHECK: @[[PERCENT_S:[a-zA-Z0-9_$"\\.-]+]] = constant [4 x i8] c"%s\0A\00" ; CHECK: @[[FORMAT_STR:[a-zA-Z0-9_$"\\.-]+]] = constant [3 x i8] c"%s\00" ; CHECK: @[[CHARSTR:[a-zA-Z0-9_$"\\.-]+]] = constant [2 x i8] c"a\00" +; CHECK: @[[EMPTY:[a-zA-Z0-9_$"\\.-]+]] = constant [1 x i8] zeroinitializer ; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1 ;. define void @test_simplify1() { @@ -64,6 +66,45 @@ call void (i8*, ...) @printf(i8* %fmt, i8* %str) ret void } + +define void @test_simplify8() { +; CHECK-LABEL: @test_simplify8( +; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0)) +; CHECK-NEXT: ret void +; + %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0 + %str = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0 + call void (i8*, ...) @printf(i8* %fmt, i8* %str) + ret void +} + +define void @test_simplify9() { +; CHECK-LABEL: @test_simplify9( +; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0)) +; CHECK-NEXT: ret void +; + %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0 + %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 + call void (i8*, ...) @printf(i8* %fmt, i8* %str) + ret void +} + +define void @test_simplify10() { +; CHECK-LABEL: @test_simplify10( +; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0), i32 42, double 0x40091EB860000000) +; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97) +; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 42, double 0x40091EB860000000) +; CHECK-NEXT: ret void +; + %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0 + %str1 = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0 + call void (i8*, ...) @printf(i8* %fmt, i8* %str1, i32 42, double 0x40091EB860000000) + %str2 = getelementptr [2 x i8], [2 x i8]* @charstr, i32 0, i32 0 + call void (i8*, ...) @printf(i8* %fmt, i8* %str2, i32 42, double 0x40091EB860000000) + %str3 = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 + call void (i8*, ...) @printf(i8* %fmt, i8* %str3, i32 42, double 0x40091EB860000000) + ret void +} ;. ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nofree nounwind } ;.