From 89274584eeca019d1ebe6e22ebfa9d03ce8563f2 Mon Sep 17 00:00:00 2001 From: Bjorn Pettersson Date: Mon, 3 Oct 2022 19:05:12 +0200 Subject: [PATCH] [test][InstCombine] Update even more test cases to use opaque pointer These tests cases were converted using the script at https://gist.github.com/nikic/98357b71fd67756b0f064c9517b62a34. Needed to also re-run update_test_checks.py, otherwise some of them would fail. --- llvm/test/Transforms/InstCombine/fprintf-1.ll | 66 ++++----- llvm/test/Transforms/InstCombine/printf-1.ll | 61 ++++---- llvm/test/Transforms/InstCombine/printf-2.ll | 42 ++---- llvm/test/Transforms/InstCombine/printf-3.ll | 14 +- llvm/test/Transforms/InstCombine/printf-i16.ll | 38 +++-- llvm/test/Transforms/InstCombine/snprintf-2.ll | 166 +++++++++++----------- llvm/test/Transforms/InstCombine/snprintf-3.ll | 168 +++++++++++------------ llvm/test/Transforms/InstCombine/snprintf-4.ll | 138 +++++++++---------- llvm/test/Transforms/InstCombine/snprintf.ll | 105 +++++++------- llvm/test/Transforms/InstCombine/sprintf-1.ll | 116 +++++++--------- llvm/test/Transforms/InstCombine/sprintf-2.ll | 109 +++++++-------- llvm/test/Transforms/InstCombine/sprintf-3.ll | 6 +- llvm/test/Transforms/InstCombine/sprintf-void.ll | 9 +- 13 files changed, 483 insertions(+), 555 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/fprintf-1.ll b/llvm/test/Transforms/InstCombine/fprintf-1.ll index b6f22da..9c0134d 100644 --- a/llvm/test/Transforms/InstCombine/fprintf-1.ll +++ b/llvm/test/Transforms/InstCombine/fprintf-1.ll @@ -14,26 +14,24 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3 @percent_s = constant [3 x i8] c"%s\00" @percent_m = constant [3 x i8] c"%m\00" -declare i32 @fprintf(%FILE*, i8*, ...) +declare i32 @fprintf(ptr, ptr, ...) ; Check fprintf(fp, "foo") -> fwrite("foo", 3, 1, fp). -define void @test_simplify1(%FILE* %fp) { +define void @test_simplify1(ptr %fp) { ; CHECK-LABEL: @test_simplify1( - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt) -; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 12, i32 1, %FILE* %fp) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @hello_world) +; CHECK-NEXT: call i32 @fwrite(ptr nonnull @hello_world, i32 12, i32 1, ptr %fp) ret void ; CHECK-NEXT: ret void } ; Check fprintf(fp, "%c", chr) -> fputc(chr, fp). -define void @test_simplify2(%FILE* %fp) { +define void @test_simplify2(ptr %fp) { ; CHECK-LABEL: @test_simplify2( - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_c, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt, i8 104) -; CHECK-NEXT: call i32 @fputc(i32 104, %FILE* %fp) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @percent_c, i8 104) +; CHECK-NEXT: call i32 @fputc(i32 104, ptr %fp) ret void ; CHECK-NEXT: ret void } @@ -41,59 +39,52 @@ define void @test_simplify2(%FILE* %fp) { ; Check fprintf(fp, "%s", str) -> fputs(str, fp). ; NOTE: The fputs simplifier simplifies this further to fwrite. -define void @test_simplify3(%FILE* %fp) { +define void @test_simplify3(ptr %fp) { ; CHECK-LABEL: @test_simplify3( - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0 - %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt, i8* %str) -; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 12, i32 1, %FILE* %fp) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @percent_s, ptr @hello_world) +; CHECK-NEXT: call i32 @fwrite(ptr nonnull @hello_world, i32 12, i32 1, ptr %fp) ret void ; CHECK-NEXT: ret void } ; Check fprintf(fp, fmt, ...) -> fiprintf(fp, fmt, ...) if no floating point. -define void @test_simplify4(%FILE* %fp) { +define void @test_simplify4(ptr %fp) { ; CHECK-IPRINTF-LABEL: @test_simplify4( - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_d, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt, i32 187) -; CHECK-IPRINTF-NEXT: call i32 (%FILE*, i8*, ...) @fiprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @percent_d, i32 0, i32 0), i32 187) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @percent_d, i32 187) +; CHECK-IPRINTF-NEXT: call i32 (ptr, ptr, ...) @fiprintf(ptr %fp, ptr nonnull @percent_d, i32 187) ret void ; CHECK-IPRINTF-NEXT: ret void } -define void @test_simplify5(%FILE* %fp) { +define void @test_simplify5(ptr %fp) { ; CHECK-LABEL: @test_simplify5( - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt) [ "deopt"() ] -; CHECK-NEXT: call i32 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 12, i32 1, %FILE* %fp) [ "deopt"() ] + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @hello_world) [ "deopt"() ] +; CHECK-NEXT: call i32 @fwrite(ptr nonnull @hello_world, i32 12, i32 1, ptr %fp) [ "deopt"() ] ret void ; CHECK-NEXT: ret void } -define void @test_no_simplify1(%FILE* %fp) { +define void @test_no_simplify1(ptr %fp) { ; CHECK-IPRINTF-LABEL: @test_no_simplify1( - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_f, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt, double 1.87) -; CHECK-IPRINTF-NEXT: call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @percent_f, double 1.87) +; CHECK-IPRINTF-NEXT: call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr nonnull @percent_f, double 1.870000e+00) ret void ; CHECK-IPRINTF-NEXT: ret void } -define void @test_no_simplify2(%FILE* %fp, double %d) { +define void @test_no_simplify2(ptr %fp, double %d) { ; CHECK-LABEL: @test_no_simplify2( - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_f, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt, double %d) -; CHECK-NEXT: call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @percent_f, i32 0, i32 0), double %d) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @percent_f, double %d) +; CHECK-NEXT: call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr nonnull @percent_f, double %d) ret void ; CHECK-NEXT: ret void } -define i32 @test_no_simplify3(%FILE* %fp) { +define i32 @test_no_simplify3(ptr %fp) { ; CHECK-LABEL: @test_no_simplify3( - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - %1 = call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt) -; CHECK-NEXT: call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0)) + %1 = call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @hello_world) +; CHECK-NEXT: call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr nonnull @hello_world) ret i32 %1 ; CHECK-NEXT: ret i32 %1 } @@ -101,11 +92,10 @@ define i32 @test_no_simplify3(%FILE* %fp) { ; Verify that a call with a format string containing just the %m directive ; and no arguments is not simplified. -define void @test_no_simplify4(%FILE* %fp) { +define void @test_no_simplify4(ptr %fp) { ; CHECK-LABEL: @test_no_simplify4( - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_m, i32 0, i32 0 - call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* %fmt) -; CHECK-NEXT: call i32 (%FILE*, i8*, ...) @fprintf(%FILE* %fp, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @percent_m, i32 0, i32 0)) + call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr @percent_m) +; CHECK-NEXT: call i32 (ptr, ptr, ...) @fprintf(ptr %fp, ptr nonnull @percent_m) ret void ; CHECK-NEXT: ret void } diff --git a/llvm/test/Transforms/InstCombine/printf-1.ll b/llvm/test/Transforms/InstCombine/printf-1.ll index 170c0de..ae7f0d7 100644 --- a/llvm/test/Transforms/InstCombine/printf-1.ll +++ b/llvm/test/Transforms/InstCombine/printf-1.ll @@ -17,7 +17,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3 @empty = constant [1 x i8] c"\00" ; CHECK: [[$STR:@[a-z0-9]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1 -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) ; Check printf("") -> noop. @@ -28,8 +28,7 @@ define void @test_simplify1() { ; CHECK-IPRINTF-LABEL: @test_simplify1( ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @empty) ret void } @@ -44,8 +43,7 @@ define void @test_simplify2() { ; CHECK-IPRINTF-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 104) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @h) ret void } @@ -60,8 +58,7 @@ define void @test_simplify2b() { ; CHECK-IPRINTF-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 37) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @h2, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @h2) ret void } @@ -74,8 +71,7 @@ define void @test_simplify3() { ; CHECK-IPRINTF-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 37) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [2 x i8], [2 x i8]* @percent, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @percent) ret void } @@ -83,15 +79,14 @@ define void @test_simplify3() { define void @test_simplify4() { ; CHECK-LABEL: @test_simplify4( -; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i32 0, i32 0)) +; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str) ; CHECK-NEXT: ret void ; ; CHECK-IPRINTF-LABEL: @test_simplify4( -; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i32 0, i32 0)) +; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @hello_world) ret void } @@ -106,8 +101,7 @@ define void @test_simplify5() { ; CHECK-IPRINTF-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 104) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_c, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt, i8 104) + call i32 (ptr, ...) @printf(ptr @percent_c, i8 104) ret void } @@ -115,16 +109,14 @@ define void @test_simplify5() { define void @test_simplify6() { ; CHECK-LABEL: @test_simplify6( -; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0)) +; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world) ; CHECK-NEXT: ret void ; ; CHECK-IPRINTF-LABEL: @test_simplify6( -; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0)) +; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [4 x i8], [4 x i8]* @percent_s, i32 0, i32 0 - %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt, i8* %str) + call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world) ret void } @@ -132,55 +124,52 @@ define void @test_simplify6() { define void @test_simplify7() { ; CHECK-LABEL: @test_simplify7( -; CHECK-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @printf(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @percent_d, i32 0, i32 0), i32 187) +; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_d, i32 187) ; CHECK-NEXT: ret void ; ; CHECK-IPRINTF-LABEL: @test_simplify7( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @iprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @percent_d, i32 0, i32 0), i32 187) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @iprintf(ptr nonnull @percent_d, i32 187) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_d, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt, i32 187) + call i32 (ptr, ...) @printf(ptr @percent_d, i32 187) ret void } define void @test_no_simplify1() { ; CHECK-LABEL: @test_no_simplify1( -; CHECK-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @printf(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) +; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_f, double 1.870000e+00) ; CHECK-NEXT: ret void ; ; CHECK-IPRINTF-LABEL: @test_no_simplify1( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @printf(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_f, double 1.870000e+00) ; CHECK-IPRINTF-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_f, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt, double 1.87) + call i32 (ptr, ...) @printf(ptr @percent_f, double 1.87) ret void } -define void @test_no_simplify2(i8* %fmt, double %d) { +define void @test_no_simplify2(ptr %fmt, double %d) { ; CHECK-LABEL: @test_no_simplify2( -; CHECK-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @printf(i8* noundef nonnull dereferenceable(1) [[FMT:%.*]], double [[D:%.*]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) [[FMT:%.*]], double [[D:%.*]]) ; CHECK-NEXT: ret void ; ; CHECK-IPRINTF-LABEL: @test_no_simplify2( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @printf(i8* noundef nonnull dereferenceable(1) [[FMT:%.*]], double [[D:%.*]]) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) [[FMT:%.*]], double [[D:%.*]]) ; CHECK-IPRINTF-NEXT: ret void ; - call i32 (i8*, ...) @printf(i8* %fmt, double %d) + call i32 (ptr, ...) @printf(ptr %fmt, double %d) ret void } define i32 @test_no_simplify3() { ; CHECK-LABEL: @test_no_simplify3( -; CHECK-NEXT: [[RET:%.*]] = call i32 (i8*, ...) @printf(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @h, i32 0, i32 0)) +; CHECK-NEXT: [[RET:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @h) ; CHECK-NEXT: ret i32 [[RET]] ; ; CHECK-IPRINTF-LABEL: @test_no_simplify3( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (i8*, ...) @iprintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @h, i32 0, i32 0)) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @iprintf(ptr nonnull @h) ; CHECK-IPRINTF-NEXT: ret i32 [[TMP1]] ; - %fmt = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0 - %ret = call i32 (i8*, ...) @printf(i8* %fmt) + %ret = call i32 (ptr, ...) @printf(ptr @h) ret i32 %ret } diff --git a/llvm/test/Transforms/InstCombine/printf-2.ll b/llvm/test/Transforms/InstCombine/printf-2.ll index 209051b..5cd8f6f 100644 --- a/llvm/test/Transforms/InstCombine/printf-2.ll +++ b/llvm/test/Transforms/InstCombine/printf-2.ll @@ -12,7 +12,7 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3 @charstr = constant [2 x i8] c"a\00" @empty = constant [1 x i8] c"\00" -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) ; Check simplification of printf with void return type. @@ -32,29 +32,25 @@ define void @test_simplify1() { ; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 104) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @h) ret void } define void @test_simplify2() { ; CHECK-LABEL: @test_simplify2( -; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i32 0, i32 0)) +; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt) + call i32 (ptr, ...) @printf(ptr @hello_world) ret void } define void @test_simplify6() { ; CHECK-LABEL: @test_simplify6( -; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0)) +; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [4 x i8], [4 x i8]* @percent_s, i32 0, i32 0 - %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt, i8* %str) + call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world) ret void } @@ -63,9 +59,7 @@ define void @test_simplify7() { ; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0 - %str = getelementptr [2 x i8], [2 x i8]* @charstr, i32 0, i32 0 - call i32 (i8*, ...) @printf(i8* %fmt, i8* %str) + call i32 (ptr, ...) @printf(ptr @format_str, ptr @charstr) ret void } @@ -75,9 +69,7 @@ define void @test_simplify8() { ; CHECK-LABEL: @test_simplify8( ; 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 i32 (i8*, ...) @printf(i8* %fmt, i8* %str) + call i32 (ptr, ...) @printf(ptr @format_str, ptr @empty) ret void } @@ -85,12 +77,10 @@ define void @test_simplify8() { define void @test_simplify9() { ; CHECK-LABEL: @test_simplify9( -; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.1, i32 0, i32 0)) +; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str.1) ; 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 i32 (i8*, ...) @printf(i8* %fmt, i8* %str) + call i32 (ptr, ...) @printf(ptr @format_str, ptr @hello_world) ret void } @@ -101,16 +91,12 @@ define void @test_simplify9() { define void @test_simplify10() { ; CHECK-LABEL: @test_simplify10( ; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97) -; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i32 0, i32 0)) +; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str.2) ; 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 i32 (i8*, ...) @printf(i8* %fmt, i8* %str1, i32 42, double 0x40091EB860000000) - %str2 = getelementptr [2 x i8], [2 x i8]* @charstr, i32 0, i32 0 - call i32 (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 i32 (i8*, ...) @printf(i8* %fmt, i8* %str3, i32 42, double 0x40091EB860000000) + call i32 (ptr, ...) @printf(ptr @format_str, ptr @empty, i32 42, double 0x40091EB860000000) + call i32 (ptr, ...) @printf(ptr @format_str, ptr @charstr, i32 42, double 0x40091EB860000000) + call i32 (ptr, ...) @printf(ptr @format_str, ptr @hello_world, i32 42, double 0x40091EB860000000) ret void } ;. diff --git a/llvm/test/Transforms/InstCombine/printf-3.ll b/llvm/test/Transforms/InstCombine/printf-3.ll index d3d32b6..2799c36 100644 --- a/llvm/test/Transforms/InstCombine/printf-3.ll +++ b/llvm/test/Transforms/InstCombine/printf-3.ll @@ -7,17 +7,17 @@ target triple = "x86_64-pc-windows-msvc18.0.0" @.str = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 -define void @test1() personality i32 (...)* @__CxxFrameHandler3 { +define void @test1() personality ptr @__CxxFrameHandler3 { entry: - invoke void @_CxxThrowException(i8* null, i8* null) + invoke void @_CxxThrowException(ptr null, ptr null) to label %unreachable unwind label %catch.dispatch catch.dispatch: %cs = catchswitch within none [label %catch] unwind to caller catch: - %cp = catchpad within %cs [i8* null, i32 64, i8* null] - %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) [ "funclet"(token %cp) ] + %cp = catchpad within %cs [ptr null, i32 64, ptr null] + %call = call i32 (ptr, ...) @printf(ptr @.str) [ "funclet"(token %cp) ] catchret from %cp to label %try.cont try.cont: @@ -29,11 +29,11 @@ unreachable: ; CHECK-DAG: define void @test1( ; CHECK: %[[CS:.*]] = catchswitch within none -; CHECK: %[[CP:.*]] = catchpad within %[[CS]] [i8* null, i32 64, i8* null] +; CHECK: %[[CP:.*]] = catchpad within %[[CS]] [ptr null, i32 64, ptr null] ; CHECK: call i32 @putchar(i32 10) [ "funclet"(token %[[CP]]) ] -declare void @_CxxThrowException(i8*, i8*) +declare void @_CxxThrowException(ptr, ptr) declare i32 @__CxxFrameHandler3(...) -declare i32 @printf(i8*, ...) +declare i32 @printf(ptr, ...) diff --git a/llvm/test/Transforms/InstCombine/printf-i16.ll b/llvm/test/Transforms/InstCombine/printf-i16.ll index 96609a8..c5868b5 100644 --- a/llvm/test/Transforms/InstCombine/printf-i16.ll +++ b/llvm/test/Transforms/InstCombine/printf-i16.ll @@ -7,7 +7,7 @@ ; targets with 16-bit int. declare i16 @putchar(i16) -declare i16 @puts(i8*) +declare i16 @puts(ptr) @s1 = constant [2 x i8] c"\01\00" @s7f = constant [2 x i8] c"\7f\00" @@ -17,7 +17,7 @@ declare i16 @puts(i8*) @pcnt_c = constant [3 x i8] c"%c\00" @pcnt_s = constant [3 x i8] c"%s\00" -declare i16 @printf(i8*, ...) +declare i16 @printf(ptr, ...) ; Verfify that the three printf to putchar transformations all result ; in the same output for calls with equivalent arguments. @@ -41,32 +41,26 @@ define void @xform_printf(i8 %c8, i16 %c16) { ; CHECK-NEXT: [[PUTCHAR13:%.*]] = call i16 @putchar(i16 [[C16:%.*]]) ; CHECK-NEXT: ret void ; - %ppcnt_c = getelementptr [3 x i8], [3 x i8]* @pcnt_c, i32 0, i32 0 - %ppcnt_s = getelementptr [3 x i8], [3 x i8]* @pcnt_s, i32 0, i32 0 - %ps1 = getelementptr [2 x i8], [2 x i8]* @s1, i32 0, i32 0 - call i16 (i8*, ...) @printf(i8* %ps1) - call i16 (i8*, ...) @printf(i8* %ppcnt_c, i16 1) - call i16 (i8*, ...) @printf(i8* %ppcnt_s, i8* %ps1) + call i16 (ptr, ...) @printf(ptr @s1) + call i16 (ptr, ...) @printf(ptr @pcnt_c, i16 1) + call i16 (ptr, ...) @printf(ptr @pcnt_s, ptr @s1) - %ps7f = getelementptr [2 x i8], [2 x i8]* @s7f, i32 0, i32 0 - call i16 (i8*, ...) @printf(i8* %ps7f) - call i16 (i8*, ...) @printf(i8* %ppcnt_c, i16 127) - call i16 (i8*, ...) @printf(i8* %ppcnt_s, i8* %ps7f) + call i16 (ptr, ...) @printf(ptr @s7f) + call i16 (ptr, ...) @printf(ptr @pcnt_c, i16 127) + call i16 (ptr, ...) @printf(ptr @pcnt_s, ptr @s7f) - %ps80 = getelementptr [2 x i8], [2 x i8]* @s80, i32 0, i32 0 - call i16 (i8*, ...) @printf(i8* %ps80) - call i16 (i8*, ...) @printf(i8* %ppcnt_c, i16 128) - call i16 (i8*, ...) @printf(i8* %ppcnt_s, i8* %ps80) + call i16 (ptr, ...) @printf(ptr @s80) + call i16 (ptr, ...) @printf(ptr @pcnt_c, i16 128) + call i16 (ptr, ...) @printf(ptr @pcnt_s, ptr @s80) - %psff = getelementptr [2 x i8], [2 x i8]* @sff, i32 0, i32 0 - call i16 (i8*, ...) @printf(i8* %psff) - call i16 (i8*, ...) @printf(i8* %ppcnt_c, i16 255) - call i16 (i8*, ...) @printf(i8* %ppcnt_s, i8* %psff) + call i16 (ptr, ...) @printf(ptr @sff) + call i16 (ptr, ...) @printf(ptr @pcnt_c, i16 255) + call i16 (ptr, ...) @printf(ptr @pcnt_s, ptr @sff) ; The i8 argument to printf can be either zero-extended or sign-extended ; when passed to putchar which then converts it to unsigned char. - call i16 (i8*, ...) @printf(i8* %ppcnt_c, i8 %c8) - call i16 (i8*, ...) @printf(i8* %ppcnt_c, i16 %c16) + call i16 (ptr, ...) @printf(ptr @pcnt_c, i8 %c8) + call i16 (ptr, ...) @printf(ptr @pcnt_c, i16 %c16) ret void } diff --git a/llvm/test/Transforms/InstCombine/snprintf-2.ll b/llvm/test/Transforms/InstCombine/snprintf-2.ll index 1601e329..6d7b309 100644 --- a/llvm/test/Transforms/InstCombine/snprintf-2.ll +++ b/llvm/test/Transforms/InstCombine/snprintf-2.ll @@ -10,10 +10,10 @@ @s = constant [4 x i8] c"123\00" -@adst = external global [0 x i8*] +@adst = external global [0 x ptr] @asiz = external global [0 x i32] -declare i32 @snprintf(i8*, i64, i8*, ...) +declare i32 @snprintf(ptr, i64, ptr, ...) ; Verify that all snprintf calls with a bound between INT_MAX and down @@ -21,88 +21,85 @@ declare i32 @snprintf(i8*, i64, i8*, ...) define void @fold_snprintf_fmt() { ; BE-LABEL: @fold_snprintf_fmt( -; BE-NEXT: [[PDIMAX1:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2147483647) to i32**), align 8 -; BE-NEXT: store i32 825373440, i32* [[PDIMAX1]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 -; BE-NEXT: [[PD52:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 5) to i32**), align 8 -; BE-NEXT: store i32 825373440, i32* [[PD52]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 5), align 4 -; BE-NEXT: [[PD43:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 4) to i32**), align 8 -; BE-NEXT: store i32 825373440, i32* [[PD43]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 4), align 4 -; BE-NEXT: [[PD3:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 3), align 8 -; BE-NEXT: [[TMP1:%.*]] = bitcast i8* [[PD3]] to i16* -; BE-NEXT: store i16 12594, i16* [[TMP1]], align 1 -; BE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, i8* [[PD3]], i64 2 -; BE-NEXT: store i8 0, i8* [[ENDPTR]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 3), align 4 -; BE-NEXT: [[PD2:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2), align 8 -; BE-NEXT: store i8 49, i8* [[PD2]], align 1 -; BE-NEXT: [[ENDPTR4:%.*]] = getelementptr inbounds i8, i8* [[PD2]], i64 1 -; BE-NEXT: store i8 0, i8* [[ENDPTR4]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 2), align 4 -; BE-NEXT: [[PD1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; BE-NEXT: store i8 0, i8* [[PD1]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 +; BE-NEXT: [[PDIMAX:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2147483647), align 8 +; BE-NEXT: store i32 825373440, ptr [[PDIMAX]], align 1 +; BE-NEXT: store i32 3, ptr @asiz, align 4 +; BE-NEXT: [[PD5:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 5), align 8 +; BE-NEXT: store i32 825373440, ptr [[PD5]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 5), align 4 +; BE-NEXT: [[PD4:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 4), align 8 +; BE-NEXT: store i32 825373440, ptr [[PD4]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 4), align 4 +; BE-NEXT: [[PD3:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 3), align 8 +; BE-NEXT: store i16 12594, ptr [[PD3]], align 1 +; BE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, ptr [[PD3]], i64 2 +; BE-NEXT: store i8 0, ptr [[ENDPTR]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 3), align 4 +; BE-NEXT: [[PD2:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2), align 8 +; BE-NEXT: store i8 49, ptr [[PD2]], align 1 +; BE-NEXT: [[ENDPTR1:%.*]] = getelementptr inbounds i8, ptr [[PD2]], i64 1 +; BE-NEXT: store i8 0, ptr [[ENDPTR1]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 2), align 4 +; BE-NEXT: [[PD1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; BE-NEXT: store i8 0, ptr [[PD1]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; BE-NEXT: store i32 3, ptr @asiz, align 4 ; BE-NEXT: ret void ; ; LE-LABEL: @fold_snprintf_fmt( -; LE-NEXT: [[PDIMAX1:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2147483647) to i32**), align 8 -; LE-NEXT: store i32 3355185, i32* [[PDIMAX1]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 -; LE-NEXT: [[PD52:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 5) to i32**), align 8 -; LE-NEXT: store i32 3355185, i32* [[PD52]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 5), align 4 -; LE-NEXT: [[PD43:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 4) to i32**), align 8 -; LE-NEXT: store i32 3355185, i32* [[PD43]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 4), align 4 -; LE-NEXT: [[PD3:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 3), align 8 -; LE-NEXT: [[TMP1:%.*]] = bitcast i8* [[PD3]] to i16* -; LE-NEXT: store i16 12849, i16* [[TMP1]], align 1 -; LE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, i8* [[PD3]], i64 2 -; LE-NEXT: store i8 0, i8* [[ENDPTR]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 3), align 4 -; LE-NEXT: [[PD2:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2), align 8 -; LE-NEXT: store i8 49, i8* [[PD2]], align 1 -; LE-NEXT: [[ENDPTR4:%.*]] = getelementptr inbounds i8, i8* [[PD2]], i64 1 -; LE-NEXT: store i8 0, i8* [[ENDPTR4]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 2), align 4 -; LE-NEXT: [[PD1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; LE-NEXT: store i8 0, i8* [[PD1]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 +; LE-NEXT: [[PDIMAX:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2147483647), align 8 +; LE-NEXT: store i32 3355185, ptr [[PDIMAX]], align 1 +; LE-NEXT: store i32 3, ptr @asiz, align 4 +; LE-NEXT: [[PD5:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 5), align 8 +; LE-NEXT: store i32 3355185, ptr [[PD5]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 5), align 4 +; LE-NEXT: [[PD4:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 4), align 8 +; LE-NEXT: store i32 3355185, ptr [[PD4]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 4), align 4 +; LE-NEXT: [[PD3:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 3), align 8 +; LE-NEXT: store i16 12849, ptr [[PD3]], align 1 +; LE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, ptr [[PD3]], i64 2 +; LE-NEXT: store i8 0, ptr [[ENDPTR]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 3), align 4 +; LE-NEXT: [[PD2:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2), align 8 +; LE-NEXT: store i8 49, ptr [[PD2]], align 1 +; LE-NEXT: [[ENDPTR1:%.*]] = getelementptr inbounds i8, ptr [[PD2]], i64 1 +; LE-NEXT: store i8 0, ptr [[ENDPTR1]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 2), align 4 +; LE-NEXT: [[PD1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; LE-NEXT: store i8 0, ptr [[PD1]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; LE-NEXT: store i32 3, ptr @asiz, align 4 ; LE-NEXT: ret void ; - %fmt = getelementptr [4 x i8], [4 x i8]* @s, i32 0, i32 0 - %pdimax = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 2147483647) - %nimax = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdimax, i64 2147483647, i8* %fmt) - store i32 %nimax, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pdimax = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 2147483647) + %nimax = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdimax, i64 2147483647, ptr @s) + store i32 %nimax, ptr @asiz - %pd5 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 5) - %n5 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd5, i64 5, i8* %fmt) - store i32 %n5, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 5) + %pd5 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 5) + %n5 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd5, i64 5, ptr @s) + store i32 %n5, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 5) - %pd4 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 4) - %n4 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd4, i64 4, i8* %fmt) - store i32 %n4, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 4) + %pd4 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 4) + %n4 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd4, i64 4, ptr @s) + store i32 %n4, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 4) - %pd3 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 3) - %n3 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd3, i64 3, i8* %fmt) - store i32 %n3, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 3) + %pd3 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 3) + %n3 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd3, i64 3, ptr @s) + store i32 %n3, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 3) - %pd2 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 2) - %n2 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd2, i64 2, i8* %fmt) - store i32 %n2, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 2) + %pd2 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 2) + %n2 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd2, i64 2, ptr @s) + store i32 %n2, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 2) - %pd1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 1) - %n1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd1, i64 1, i8* %fmt) - store i32 %n1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 1) + %pd1 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 1) + %n1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd1, i64 1, ptr @s) + store i32 %n1, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 1) - %pd0 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 0) - %n0 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd0, i64 0, i8* %fmt) - store i32 %n0, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pd0 = load ptr, ptr @adst + %n0 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd0, i64 0, ptr @s) + store i32 %n0, ptr @asiz ret void } @@ -114,23 +111,22 @@ define void @fold_snprintf_fmt() { define void @call_snprintf_fmt_ximax() { ; ANY-LABEL: @call_snprintf_fmt_ximax( -; ANY-NEXT: [[PDM1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; ANY-NEXT: [[NM1:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDM1]], i64 -1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @s, i64 0, i64 0)) -; ANY-NEXT: store i32 [[NM1]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; ANY-NEXT: [[PDIMAXP1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 0), align 8 -; ANY-NEXT: [[NIMAXP1:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDIMAXP1]], i64 2147483648, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @s, i64 0, i64 0)) -; ANY-NEXT: store i32 [[NIMAXP1]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 +; ANY-NEXT: [[PDM1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; ANY-NEXT: [[NM1:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDM1]], i64 -1, ptr nonnull @s) +; ANY-NEXT: store i32 [[NM1]], ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; ANY-NEXT: [[PDIMAXP1:%.*]] = load ptr, ptr @adst, align 8 +; ANY-NEXT: [[NIMAXP1:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDIMAXP1]], i64 2147483648, ptr nonnull @s) +; ANY-NEXT: store i32 [[NIMAXP1]], ptr @asiz, align 4 ; ANY-NEXT: ret void ; - %fmt = getelementptr [4 x i8], [4 x i8]* @s, i32 0, i32 0 - %pdm1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 1) - %nm1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdm1, i64 -1, i8* %fmt) - store i32 %nm1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 1) + %pdm1 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 1) + %nm1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdm1, i64 -1, ptr @s) + store i32 %nm1, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 1) - %pdimaxp1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 0) - %nimaxp1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdimaxp1, i64 2147483648, i8* %fmt) - store i32 %nimaxp1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pdimaxp1 = load ptr, ptr @adst + %nimaxp1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdimaxp1, i64 2147483648, ptr @s) + store i32 %nimaxp1, ptr @asiz ret void } diff --git a/llvm/test/Transforms/InstCombine/snprintf-3.ll b/llvm/test/Transforms/InstCombine/snprintf-3.ll index 6576e7a..be5e025 100644 --- a/llvm/test/Transforms/InstCombine/snprintf-3.ll +++ b/llvm/test/Transforms/InstCombine/snprintf-3.ll @@ -11,10 +11,10 @@ @pcnt_s = constant [3 x i8] c"%s\00" @s = constant [4 x i8] c"123\00" -@adst = external global [0 x i8*] +@adst = external global [0 x ptr] @asiz = external global [0 x i32] -declare i32 @snprintf(i8*, i64, i8*, ...) +declare i32 @snprintf(ptr, i64, ptr, ...) ; Verify that all snprintf calls with a bound between INT_MAX and down @@ -22,89 +22,85 @@ declare i32 @snprintf(i8*, i64, i8*, ...) define void @fold_snprintf_pcnt_s() { ; BE-LABEL: @fold_snprintf_pcnt_s( -; BE-NEXT: [[PDIMAX1:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2147483647) to i32**), align 8 -; BE-NEXT: store i32 825373440, i32* [[PDIMAX1]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 -; BE-NEXT: [[PD52:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 5) to i32**), align 8 -; BE-NEXT: store i32 825373440, i32* [[PD52]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 5), align 4 -; BE-NEXT: [[PD43:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 4) to i32**), align 8 -; BE-NEXT: store i32 825373440, i32* [[PD43]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 4), align 4 -; BE-NEXT: [[PD3:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 3), align 8 -; BE-NEXT: [[TMP1:%.*]] = bitcast i8* [[PD3]] to i16* -; BE-NEXT: store i16 12594, i16* [[TMP1]], align 1 -; BE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, i8* [[PD3]], i64 2 -; BE-NEXT: store i8 0, i8* [[ENDPTR]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 3), align 4 -; BE-NEXT: [[PD2:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2), align 8 -; BE-NEXT: store i8 49, i8* [[PD2]], align 1 -; BE-NEXT: [[ENDPTR4:%.*]] = getelementptr inbounds i8, i8* [[PD2]], i64 1 -; BE-NEXT: store i8 0, i8* [[ENDPTR4]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 2), align 4 -; BE-NEXT: [[PD1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; BE-NEXT: store i8 0, i8* [[PD1]], align 1 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; BE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 +; BE-NEXT: [[PDIMAX:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2147483647), align 8 +; BE-NEXT: store i32 825373440, ptr [[PDIMAX]], align 1 +; BE-NEXT: store i32 3, ptr @asiz, align 4 +; BE-NEXT: [[PD5:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 5), align 8 +; BE-NEXT: store i32 825373440, ptr [[PD5]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 5), align 4 +; BE-NEXT: [[PD4:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 4), align 8 +; BE-NEXT: store i32 825373440, ptr [[PD4]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 4), align 4 +; BE-NEXT: [[PD3:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 3), align 8 +; BE-NEXT: store i16 12594, ptr [[PD3]], align 1 +; BE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, ptr [[PD3]], i64 2 +; BE-NEXT: store i8 0, ptr [[ENDPTR]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 3), align 4 +; BE-NEXT: [[PD2:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2), align 8 +; BE-NEXT: store i8 49, ptr [[PD2]], align 1 +; BE-NEXT: [[ENDPTR1:%.*]] = getelementptr inbounds i8, ptr [[PD2]], i64 1 +; BE-NEXT: store i8 0, ptr [[ENDPTR1]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 2), align 4 +; BE-NEXT: [[PD1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; BE-NEXT: store i8 0, ptr [[PD1]], align 1 +; BE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; BE-NEXT: store i32 3, ptr @asiz, align 4 ; BE-NEXT: ret void ; ; LE-LABEL: @fold_snprintf_pcnt_s( -; LE-NEXT: [[PDIMAX1:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2147483647) to i32**), align 8 -; LE-NEXT: store i32 3355185, i32* [[PDIMAX1]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 -; LE-NEXT: [[PD52:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 5) to i32**), align 8 -; LE-NEXT: store i32 3355185, i32* [[PD52]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 5), align 4 -; LE-NEXT: [[PD43:%.*]] = load i32*, i32** bitcast (i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 4) to i32**), align 8 -; LE-NEXT: store i32 3355185, i32* [[PD43]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 4), align 4 -; LE-NEXT: [[PD3:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 3), align 8 -; LE-NEXT: [[TMP1:%.*]] = bitcast i8* [[PD3]] to i16* -; LE-NEXT: store i16 12849, i16* [[TMP1]], align 1 -; LE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, i8* [[PD3]], i64 2 -; LE-NEXT: store i8 0, i8* [[ENDPTR]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 3), align 4 -; LE-NEXT: [[PD2:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2), align 8 -; LE-NEXT: store i8 49, i8* [[PD2]], align 1 -; LE-NEXT: [[ENDPTR4:%.*]] = getelementptr inbounds i8, i8* [[PD2]], i64 1 -; LE-NEXT: store i8 0, i8* [[ENDPTR4]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 2), align 4 -; LE-NEXT: [[PD1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; LE-NEXT: store i8 0, i8* [[PD1]], align 1 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; LE-NEXT: store i32 3, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 +; LE-NEXT: [[PDIMAX:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2147483647), align 8 +; LE-NEXT: store i32 3355185, ptr [[PDIMAX]], align 1 +; LE-NEXT: store i32 3, ptr @asiz, align 4 +; LE-NEXT: [[PD5:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 5), align 8 +; LE-NEXT: store i32 3355185, ptr [[PD5]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 5), align 4 +; LE-NEXT: [[PD4:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 4), align 8 +; LE-NEXT: store i32 3355185, ptr [[PD4]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 4), align 4 +; LE-NEXT: [[PD3:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 3), align 8 +; LE-NEXT: store i16 12849, ptr [[PD3]], align 1 +; LE-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, ptr [[PD3]], i64 2 +; LE-NEXT: store i8 0, ptr [[ENDPTR]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 3), align 4 +; LE-NEXT: [[PD2:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2), align 8 +; LE-NEXT: store i8 49, ptr [[PD2]], align 1 +; LE-NEXT: [[ENDPTR1:%.*]] = getelementptr inbounds i8, ptr [[PD2]], i64 1 +; LE-NEXT: store i8 0, ptr [[ENDPTR1]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 2), align 4 +; LE-NEXT: [[PD1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; LE-NEXT: store i8 0, ptr [[PD1]], align 1 +; LE-NEXT: store i32 3, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; LE-NEXT: store i32 3, ptr @asiz, align 4 ; LE-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @pcnt_s, i32 0, i32 0 - %ps = getelementptr [4 x i8], [4 x i8]* @s, i32 0, i32 0 - %pdimax = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 2147483647) - %nimax = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdimax, i64 2147483647, i8* %fmt, i8* %ps) - store i32 %nimax, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pdimax = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 2147483647) + %nimax = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdimax, i64 2147483647, ptr @pcnt_s, ptr @s) + store i32 %nimax, ptr @asiz - %pd5 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 5) - %n5 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd5, i64 5, i8* %fmt, i8* %ps) - store i32 %n5, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 5) + %pd5 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 5) + %n5 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd5, i64 5, ptr @pcnt_s, ptr @s) + store i32 %n5, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 5) - %pd4 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 4) - %n4 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd4, i64 4, i8* %fmt, i8* %ps) - store i32 %n4, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 4) + %pd4 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 4) + %n4 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd4, i64 4, ptr @pcnt_s, ptr @s) + store i32 %n4, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 4) - %pd3 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 3) - %n3 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd3, i64 3, i8* %fmt, i8* %ps) - store i32 %n3, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 3) + %pd3 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 3) + %n3 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd3, i64 3, ptr @pcnt_s, ptr @s) + store i32 %n3, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 3) - %pd2 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 2) - %n2 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd2, i64 2, i8* %fmt, i8* %ps) - store i32 %n2, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 2) + %pd2 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 2) + %n2 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd2, i64 2, ptr @pcnt_s, ptr @s) + store i32 %n2, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 2) - %pd1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 1) - %n1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd1, i64 1, i8* %fmt, i8* %ps) - store i32 %n1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 1) + %pd1 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 1) + %n1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd1, i64 1, ptr @pcnt_s, ptr @s) + store i32 %n1, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 1) - %pd0 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 0) - %n0 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd0, i64 0, i8* %fmt, i8* %ps) - store i32 %n0, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pd0 = load ptr, ptr @adst + %n0 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd0, i64 0, ptr @pcnt_s, ptr @s) + store i32 %n0, ptr @asiz ret void } @@ -116,24 +112,22 @@ define void @fold_snprintf_pcnt_s() { define void @call_snprintf_pcnt_s_ximax() { ; ANY-LABEL: @call_snprintf_pcnt_s_ximax( -; ANY-NEXT: [[PDM1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; ANY-NEXT: [[NM1:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDM1]], i64 -1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @pcnt_s, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @s, i64 0, i64 0)) -; ANY-NEXT: store i32 [[NM1]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; ANY-NEXT: [[PDIMAXP1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 0), align 8 -; ANY-NEXT: [[NIMAXP1:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDIMAXP1]], i64 2147483648, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @pcnt_s, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @s, i64 0, i64 0)) -; ANY-NEXT: store i32 [[NIMAXP1]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 +; ANY-NEXT: [[PDM1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; ANY-NEXT: [[NM1:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDM1]], i64 -1, ptr nonnull @pcnt_s, ptr nonnull @s) +; ANY-NEXT: store i32 [[NM1]], ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; ANY-NEXT: [[PDIMAXP1:%.*]] = load ptr, ptr @adst, align 8 +; ANY-NEXT: [[NIMAXP1:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDIMAXP1]], i64 2147483648, ptr nonnull @pcnt_s, ptr nonnull @s) +; ANY-NEXT: store i32 [[NIMAXP1]], ptr @asiz, align 4 ; ANY-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @pcnt_s, i32 0, i32 0 - %ps = getelementptr [4 x i8], [4 x i8]* @s, i32 0, i32 0 - %pdm1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 1) - %nm1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdm1, i64 -1, i8* %fmt, i8* %ps) - store i32 %nm1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 1) + %pdm1 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 1) + %nm1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdm1, i64 -1, ptr @pcnt_s, ptr @s) + store i32 %nm1, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 1) - %pdimaxp1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 0) - %nimaxp1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdimaxp1, i64 2147483648, i8* %fmt, i8* %ps) - store i32 %nimaxp1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pdimaxp1 = load ptr, ptr @adst + %nimaxp1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdimaxp1, i64 2147483648, ptr @pcnt_s, ptr @s) + store i32 %nimaxp1, ptr @asiz ret void } diff --git a/llvm/test/Transforms/InstCombine/snprintf-4.ll b/llvm/test/Transforms/InstCombine/snprintf-4.ll index 5fd797c..6f2810c 100644 --- a/llvm/test/Transforms/InstCombine/snprintf-4.ll +++ b/llvm/test/Transforms/InstCombine/snprintf-4.ll @@ -8,10 +8,10 @@ @pcnt_c = constant [3 x i8] c"%c\00" -@adst = external global [0 x i8*] +@adst = external global [0 x ptr] @asiz = external global [0 x i32] -declare i32 @snprintf(i8*, i64, i8*, ...) +declare i32 @snprintf(ptr, i64, ptr, ...) ; Verify that all snprintf calls with a bound between INT_MAX and down @@ -19,74 +19,73 @@ declare i32 @snprintf(i8*, i64, i8*, ...) define void @fold_snprintf_pcnt_c(i32 %c) { ; CHECK-LABEL: @fold_snprintf_pcnt_c( -; CHECK-NEXT: [[PDIMAX:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 0), align 8 -; CHECK-NEXT: store i8 1, i8* [[PDIMAX]], align 1 -; CHECK-NEXT: [[NUL:%.*]] = getelementptr inbounds i8, i8* [[PDIMAX]], i64 1 -; CHECK-NEXT: store i8 0, i8* [[NUL]], align 1 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 -; CHECK-NEXT: [[PD2:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; CHECK-NEXT: store i8 2, i8* [[PD2]], align 1 -; CHECK-NEXT: [[NUL1:%.*]] = getelementptr inbounds i8, i8* [[PD2]], i64 1 -; CHECK-NEXT: store i8 0, i8* [[NUL1]], align 1 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; CHECK-NEXT: [[PD2_0:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2), align 8 -; CHECK-NEXT: store i8 0, i8* [[PD2_0]], align 1 -; CHECK-NEXT: [[NUL2:%.*]] = getelementptr inbounds i8, i8* [[PD2_0]], i64 1 -; CHECK-NEXT: store i8 0, i8* [[NUL2]], align 1 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 2), align 4 -; CHECK-NEXT: [[PD1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 3), align 8 -; CHECK-NEXT: store i8 0, i8* [[PD1]], align 1 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 3), align 4 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 4), align 4 -; CHECK-NEXT: [[PD2_C:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 4), align 8 +; CHECK-NEXT: [[PDIMAX:%.*]] = load ptr, ptr @adst, align 8 +; CHECK-NEXT: store i8 1, ptr [[PDIMAX]], align 1 +; CHECK-NEXT: [[NUL:%.*]] = getelementptr inbounds i8, ptr [[PDIMAX]], i64 1 +; CHECK-NEXT: store i8 0, ptr [[NUL]], align 1 +; CHECK-NEXT: store i32 1, ptr @asiz, align 4 +; CHECK-NEXT: [[PD2:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; CHECK-NEXT: store i8 2, ptr [[PD2]], align 1 +; CHECK-NEXT: [[NUL1:%.*]] = getelementptr inbounds i8, ptr [[PD2]], i64 1 +; CHECK-NEXT: store i8 0, ptr [[NUL1]], align 1 +; CHECK-NEXT: store i32 1, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; CHECK-NEXT: [[PD2_0:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2), align 8 +; CHECK-NEXT: store i8 0, ptr [[PD2_0]], align 1 +; CHECK-NEXT: [[NUL2:%.*]] = getelementptr inbounds i8, ptr [[PD2_0]], i64 1 +; CHECK-NEXT: store i8 0, ptr [[NUL2]], align 1 +; CHECK-NEXT: store i32 1, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 2), align 4 +; CHECK-NEXT: [[PD1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 3), align 8 +; CHECK-NEXT: store i8 0, ptr [[PD1]], align 1 +; CHECK-NEXT: store i32 1, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 3), align 4 +; CHECK-NEXT: store i32 1, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 4), align 4 +; CHECK-NEXT: [[PD2_C:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 4), align 8 ; CHECK-NEXT: [[CHAR:%.*]] = trunc i32 [[C:%.*]] to i8 -; CHECK-NEXT: store i8 [[CHAR]], i8* [[PD2_C]], align 1 -; CHECK-NEXT: [[NUL3:%.*]] = getelementptr inbounds i8, i8* [[PD2_C]], i64 1 -; CHECK-NEXT: store i8 0, i8* [[NUL3]], align 1 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 4), align 4 -; CHECK-NEXT: [[PD1_C:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 5), align 8 -; CHECK-NEXT: store i8 0, i8* [[PD1_C]], align 1 -; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 5), align 4 +; CHECK-NEXT: store i8 [[CHAR]], ptr [[PD2_C]], align 1 +; CHECK-NEXT: [[NUL3:%.*]] = getelementptr inbounds i8, ptr [[PD2_C]], i64 1 +; CHECK-NEXT: store i8 0, ptr [[NUL3]], align 1 +; CHECK-NEXT: store i32 1, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 4), align 4 +; CHECK-NEXT: [[PD1_C:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 5), align 8 +; CHECK-NEXT: store i8 0, ptr [[PD1_C]], align 1 +; CHECK-NEXT: store i32 1, ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 5), align 4 ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @pcnt_c, i32 0, i32 0 ; Transform snprintf(dst, INT_MAX, "%c", 1) to memcpy(dst, "1", 2), 1. - %pdimax = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 0) - %nimax = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdimax, i64 2147483647, i8* %fmt, i32 1) - store i32 %nimax, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pdimax = load ptr, ptr @adst + %nimax = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdimax, i64 2147483647, ptr @pcnt_c, i32 1) + store i32 %nimax, ptr @asiz ; Transform snprintf(dst, 2, "%c", '\2') to memcpy(dst, "2", 2), 1. - %pd2 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 1) - %n2 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd2, i64 2, i8* %fmt, i8 2) - store i32 %n2, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 1) + %pd2 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 1) + %n2 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd2, i64 2, ptr @pcnt_c, i8 2) + store i32 %n2, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 1) ; Transform snprintf(dst, 2, "%c", '\0') to memcpy(dst, "\0", 2), 1. - %pd2_0 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 2) - %n2_0 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd2_0, i64 2, i8* %fmt, i8 0) - store i32 %n2_0, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 2) + %pd2_0 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 2) + %n2_0 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd2_0, i64 2, ptr @pcnt_c, i8 0) + store i32 %n2_0, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 2) ; Transform snprintf(dst, 1, "%c", (short)3) to memcpy(dst, "\3", 2), 1. - %pd1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 3) - %n1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd1, i64 1, i8* %fmt, i16 3) - store i32 %n1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 3) + %pd1 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 3) + %n1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd1, i64 1, ptr @pcnt_c, i16 3) + store i32 %n1, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 3) ; Fold snprintf(dst, 0, "%c", 4) to 1. - %pd0 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 4) - %n0 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd0, i64 0, i8* %fmt, i32 4) - store i32 %n0, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 4) + %pd0 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 4) + %n0 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd0, i64 0, ptr @pcnt_c, i32 4) + store i32 %n0, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 4) ; Transform snprintf(dst, 2, "%c", c) with a nonconstant c to ; dst[0] = c, dst[1] = '\0', 1. - %pd2_c = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 4) - %n2_c = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd2_c, i64 2, i8* %fmt, i32 %c) - store i32 %n2_c, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 4) + %pd2_c = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 4) + %n2_c = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd2_c, i64 2, ptr @pcnt_c, i32 %c) + store i32 %n2_c, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 4) ; Transform snprintf(dst, 1, "%c", c) with a nonconstant c to *dst = '\0', 0. - %pd1_c = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 5) - %n1_c = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pd1_c, i64 1, i8* %fmt, i32 %c) - store i32 %n1_c, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 5) + %pd1_c = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 5) + %n1_c = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pd1_c, i64 1, ptr @pcnt_c, i32 %c) + store i32 %n1_c, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 5) ret void } @@ -98,32 +97,31 @@ define void @fold_snprintf_pcnt_c(i32 %c) { define void @call_snprintf_pcnt_c_ximax(i32 %c) { ; CHECK-LABEL: @call_snprintf_pcnt_c_ximax( -; CHECK-NEXT: [[PDM1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 0), align 8 -; CHECK-NEXT: [[NM1:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDM1]], i64 -1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @pcnt_c, i64 0, i64 0), i8 0) -; CHECK-NEXT: store i32 [[NM1]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 0), align 4 -; CHECK-NEXT: [[PDIMAXP1:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 1), align 8 -; CHECK-NEXT: [[NIMAXP1:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDIMAXP1]], i64 2147483648, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @pcnt_c, i64 0, i64 0), i8 1) -; CHECK-NEXT: store i32 [[NIMAXP1]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 1), align 4 -; CHECK-NEXT: [[PDM1SL32:%.*]] = load i8*, i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @adst, i64 0, i64 2), align 8 -; CHECK-NEXT: [[NM1SL32:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[PDM1SL32]], i64 -4294967296, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @pcnt_c, i64 0, i64 0), i8 1) -; CHECK-NEXT: store i32 [[NM1SL32]], i32* getelementptr inbounds ([0 x i32], [0 x i32]* @asiz, i64 0, i64 2), align 4 +; CHECK-NEXT: [[PDM1:%.*]] = load ptr, ptr @adst, align 8 +; CHECK-NEXT: [[NM1:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDM1]], i64 -1, ptr nonnull @pcnt_c, i8 0) +; CHECK-NEXT: store i32 [[NM1]], ptr @asiz, align 4 +; CHECK-NEXT: [[PDIMAXP1:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 1), align 8 +; CHECK-NEXT: [[NIMAXP1:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDIMAXP1]], i64 2147483648, ptr nonnull @pcnt_c, i8 1) +; CHECK-NEXT: store i32 [[NIMAXP1]], ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 1), align 4 +; CHECK-NEXT: [[PDM1SL32:%.*]] = load ptr, ptr getelementptr inbounds ([0 x ptr], ptr @adst, i64 0, i64 2), align 8 +; CHECK-NEXT: [[NM1SL32:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[PDM1SL32]], i64 -4294967296, ptr nonnull @pcnt_c, i8 1) +; CHECK-NEXT: store i32 [[NM1SL32]], ptr getelementptr inbounds ([0 x i32], ptr @asiz, i64 0, i64 2), align 4 ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @pcnt_c, i32 0, i32 0 - %pdm1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 0) - %nm1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdm1, i64 -1, i8* %fmt, i8 0) - store i32 %nm1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 0) + %pdm1 = load ptr, ptr @adst + %nm1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdm1, i64 -1, ptr @pcnt_c, i8 0) + store i32 %nm1, ptr @asiz - %pdimaxp1 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 1) - %nimaxp1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdimaxp1, i64 2147483648, i8* %fmt, i8 1) - store i32 %nimaxp1, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 1) + %pdimaxp1 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 1) + %nimaxp1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdimaxp1, i64 2147483648, ptr @pcnt_c, i8 1) + store i32 %nimaxp1, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 1) ; Exercise snprintf(dst, -1LU << 32, "%c", c). - %pdm1sl32 = load i8*, i8** getelementptr ([0 x i8*], [0 x i8*]* @adst, i32 0, i32 2) - %nm1sl32 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %pdm1sl32, i64 18446744069414584320, i8* %fmt, i8 1) - store i32 %nm1sl32, i32* getelementptr ([0 x i32], [0 x i32]* @asiz, i32 0, i32 2) + %pdm1sl32 = load ptr, ptr getelementptr ([0 x ptr], ptr @adst, i32 0, i32 2) + %nm1sl32 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %pdm1sl32, i64 18446744069414584320, ptr @pcnt_c, i8 1) + store i32 %nm1sl32, ptr getelementptr ([0 x i32], ptr @asiz, i32 0, i32 2) ret void } diff --git a/llvm/test/Transforms/InstCombine/snprintf.ll b/llvm/test/Transforms/InstCombine/snprintf.ll index f6f6a6a..4e51040 100644 --- a/llvm/test/Transforms/InstCombine/snprintf.ll +++ b/llvm/test/Transforms/InstCombine/snprintf.ll @@ -8,51 +8,51 @@ @.str.4 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 -declare i32 @snprintf(i8*, i64, i8*, ...) #1 +declare i32 @snprintf(ptr, i64, ptr, ...) #1 -define void @test_not_const_fmt(i8* %buf, i8* %fmt) #0 { +define void @test_not_const_fmt(ptr %buf, ptr %fmt) #0 { ; CHECK-LABEL: @test_not_const_fmt( -; CHECK-NEXT: [[CALL:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[BUF:%.*]], i64 32, i8* [[FMT:%.*]]) +; CHECK-NEXT: [[CALL:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], i64 32, ptr [[FMT:%.*]]) ; CHECK-NEXT: ret void ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 32, i8* %fmt) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 32, ptr %fmt) #2 ret void } ; size is '0', do not add nonnull attribute -define void @test_not_const_fmt_zero_size_return_value(i8* %buf, i8* %fmt) #0 { +define void @test_not_const_fmt_zero_size_return_value(ptr %buf, ptr %fmt) #0 { ; CHECK-LABEL: @test_not_const_fmt_zero_size_return_value( -; CHECK-NEXT: [[CALL:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* [[BUF:%.*]], i64 0, i8* [[FMT:%.*]]) +; CHECK-NEXT: [[CALL:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr [[BUF:%.*]], i64 0, ptr [[FMT:%.*]]) ; CHECK-NEXT: ret void ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 0, i8* %fmt) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 0, ptr %fmt) #2 ret void } -define void @test_not_const_size(i8* %buf, i64 %size) #0 { +define void @test_not_const_size(ptr %buf, i64 %size) #0 { ; CHECK-LABEL: @test_not_const_size( -; CHECK-NEXT: [[CALL:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* [[BUF:%.*]], i64 [[SIZE:%.*]], i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) +; CHECK-NEXT: [[CALL:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr [[BUF:%.*]], i64 [[SIZE:%.*]], ptr nonnull @.str) ; CHECK-NEXT: ret void ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 %size, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 %size, ptr @.str) #2 ret void } -define i32 @test_return_value(i8* %buf) #0 { +define i32 @test_return_value(ptr %buf) #0 { ; CHECK-LABEL: @test_return_value( ; CHECK-NEXT: ret i32 3 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 0, ptr @.str) #2 ret i32 %call } -define void @test_percentage(i8* %buf) #0 { +define void @test_percentage(ptr %buf) #0 { ; CHECK-LABEL: @test_percentage( -; CHECK-NEXT: [[CALL:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* noundef nonnull dereferenceable(1) [[BUF:%.*]], i64 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)) +; CHECK-NEXT: [[CALL:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], i64 32, ptr nonnull @.str.1) ; CHECK-NEXT: ret void ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 32, ptr @.str.1) #2 ret void } @@ -60,120 +60,117 @@ define i32 @test_null_buf_return_value() #0 { ; CHECK-LABEL: @test_null_buf_return_value( ; CHECK-NEXT: ret i32 3 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @.str) #2 ret i32 %call } define i32 @test_percentage_return_value() #0 { ; CHECK-LABEL: @test_percentage_return_value( -; CHECK-NEXT: [[CALL:%.*]] = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)) +; CHECK-NEXT: [[CALL:%.*]] = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr nonnull @.str.1) ; CHECK-NEXT: ret i32 [[CALL]] ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)) #3 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @.str.1) #3 ret i32 %call } -define void @test_correct_copy(i8* %buf) #0 { +define void @test_correct_copy(ptr %buf) #0 { ; CHECK-LABEL: @test_correct_copy( -; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[BUF:%.*]] to i32* -; CHECK-NEXT: store i32 7500915, i32* [[TMP1]], align 1 +; CHECK-NEXT: store i32 7500915, ptr [[BUF:%.*]], align 1 ; CHECK-NEXT: ret void ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 32, ptr @.str) #2 ret void } -define i32 @test_char_zero_size(i8* %buf) #0 { +define i32 @test_char_zero_size(ptr %buf) #0 { ; CHECK-LABEL: @test_char_zero_size( ; CHECK-NEXT: ret i32 1 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 65) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 0, ptr @.str.2, i32 65) #2 ret i32 %call } -define i32 @test_char_small_size(i8* %buf) #0 { +define i32 @test_char_small_size(ptr %buf) #0 { ; CHECK-LABEL: @test_char_small_size( -; CHECK-NEXT: store i8 0, i8* [[BUF:%.*]], align 1 +; CHECK-NEXT: store i8 0, ptr [[BUF:%.*]], align 1 ; CHECK-NEXT: ret i32 1 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 65) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 1, ptr @.str.2, i32 65) #2 ret i32 %call } -define i32 @test_char_ok_size(i8* %buf) #0 { +define i32 @test_char_ok_size(ptr %buf) #0 { ; CHECK-LABEL: @test_char_ok_size( -; CHECK-NEXT: store i8 65, i8* [[BUF:%.*]], align 1 -; CHECK-NEXT: [[NUL:%.*]] = getelementptr inbounds i8, i8* [[BUF]], i64 1 -; CHECK-NEXT: store i8 0, i8* [[NUL]], align 1 +; CHECK-NEXT: store i8 65, ptr [[BUF:%.*]], align 1 +; CHECK-NEXT: [[NUL:%.*]] = getelementptr inbounds i8, ptr [[BUF]], i64 1 +; CHECK-NEXT: store i8 0, ptr [[NUL]], align 1 ; CHECK-NEXT: ret i32 1 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 65) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 32, ptr @.str.2, i32 65) #2 ret i32 %call } -define i32 @test_str_zero_size(i8* %buf) #0 { +define i32 @test_str_zero_size(ptr %buf) #0 { ; CHECK-LABEL: @test_str_zero_size( ; CHECK-NEXT: ret i32 3 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 0, ptr @.str.3, ptr @.str) #2 ret i32 %call } -define i32 @test_str_small_size(i8* %buf) #0 { +define i32 @test_str_small_size(ptr %buf) #0 { ; CHECK-LABEL: @test_str_small_size( -; CHECK-NEXT: store i8 0, i8* [[BUF:%.*]], align 1 +; CHECK-NEXT: store i8 0, ptr [[BUF:%.*]], align 1 ; CHECK-NEXT: ret i32 3 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 1, ptr @.str.3, ptr @.str) #2 ret i32 %call } -define i32 @test_str_ok_size(i8* %buf) #0 { +define i32 @test_str_ok_size(ptr %buf) #0 { ; CHECK-LABEL: @test_str_ok_size( -; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[BUF:%.*]] to i32* -; CHECK-NEXT: store i32 7500915, i32* [[TMP1]], align 1 +; CHECK-NEXT: store i32 7500915, ptr [[BUF:%.*]], align 1 ; CHECK-NEXT: ret i32 3 ; - %call = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) #2 + %call = call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 32, ptr @.str.3, ptr @.str) #2 ret i32 %call } ; snprintf(buf, 32, "") -> memcpy -> store -define i32 @test_str_ok_size_tail(i8* %buf) { +define i32 @test_str_ok_size_tail(ptr %buf) { ; CHECK-LABEL: @test_str_ok_size_tail( -; CHECK-NEXT: store i8 0, i8* [[BUF:%.*]], align 1 +; CHECK-NEXT: store i8 0, ptr [[BUF:%.*]], align 1 ; CHECK-NEXT: ret i32 0 ; - %1 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)) + %1 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 8, ptr @.str.4) ret i32 %1 } -define i32 @test_str_ok_size_musttail(i8* %buf, i64 %x, i8* %y, ...) { +define i32 @test_str_ok_size_musttail(ptr %buf, i64 %x, ptr %y, ...) { ; CHECK-LABEL: @test_str_ok_size_musttail( -; CHECK-NEXT: [[TMP1:%.*]] = musttail call i32 (i8*, i64, i8*, ...) @snprintf(i8* [[BUF:%.*]], i64 8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), ...) +; CHECK-NEXT: [[TMP1:%.*]] = musttail call i32 (ptr, i64, ptr, ...) @snprintf(ptr [[BUF:%.*]], i64 8, ptr nonnull @.str.4, ...) ; CHECK-NEXT: ret i32 [[TMP1]] ; - %1 = musttail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), ...) + %1 = musttail call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 8, ptr @.str.4, ...) ret i32 %1 } ; snprintf(buf, 32, "%s", "str") -> memcpy -> store -define i32 @test_str_ok_size_tail2(i8* %buf) { +define i32 @test_str_ok_size_tail2(ptr %buf) { ; CHECK-LABEL: @test_str_ok_size_tail2( -; CHECK-NEXT: [[TMP1:%.*]] = bitcast i8* [[BUF:%.*]] to i32* -; CHECK-NEXT: store i32 7500915, i32* [[TMP1]], align 1 +; CHECK-NEXT: store i32 7500915, ptr [[BUF:%.*]], align 1 ; CHECK-NEXT: ret i32 3 ; - %1 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)) + %1 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 8, ptr @.str.3, ptr @.str) ret i32 %1 } -define i32 @test_str_ok_size_musttail2(i8* %buf, i64 %x, i8* %y, ...) { +define i32 @test_str_ok_size_musttail2(ptr %buf, i64 %x, ptr %y, ...) { ; CHECK-LABEL: @test_str_ok_size_musttail2( -; CHECK-NEXT: [[TMP1:%.*]] = musttail call i32 (i8*, i64, i8*, ...) @snprintf(i8* [[BUF:%.*]], i64 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), ...) +; CHECK-NEXT: [[TMP1:%.*]] = musttail call i32 (ptr, i64, ptr, ...) @snprintf(ptr [[BUF:%.*]], i64 8, ptr nonnull @.str.3, ptr nonnull @.str, ...) ; CHECK-NEXT: ret i32 [[TMP1]] ; - %1 = musttail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %buf, i64 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), ...) + %1 = musttail call i32 (ptr, i64, ptr, ...) @snprintf(ptr %buf, i64 8, ptr @.str.3, ptr @.str, ...) ret i32 %1 } diff --git a/llvm/test/Transforms/InstCombine/sprintf-1.ll b/llvm/test/Transforms/InstCombine/sprintf-1.ll index 9a7bffc..6413338 100644 --- a/llvm/test/Transforms/InstCombine/sprintf-1.ll +++ b/llvm/test/Transforms/InstCombine/sprintf-1.ll @@ -20,168 +20,156 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3 @percent_f = constant [3 x i8] c"%f\00" @percent_s = constant [3 x i8] c"%s\00" -declare i32 @sprintf(i8*, i8*, ...) +declare i32 @sprintf(ptr, ptr, ...) ; Check sprintf(dst, fmt) -> llvm.memcpy(str, fmt, strlen(fmt) + 1, 1). -define void @test_simplify1(i8* %dst) { +define void @test_simplify1(ptr %dst) { ; CHECK-LABEL: @test_simplify1( -; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* noundef nonnull align 1 dereferenceable(13) [[DST:%.*]], i8* noundef nonnull align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 13, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(13) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(13) @hello_world, i32 13, i1 false) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @hello_world) ret void } -define void @test_simplify2(i8* %dst) { +define void @test_simplify2(ptr %dst) { ; CHECK-LABEL: @test_simplify2( -; CHECK-NEXT: store i8 0, i8* [[DST:%.*]], align 1 +; CHECK-NEXT: store i8 0, ptr [[DST:%.*]], align 1 ; CHECK-NEXT: ret void ; - %fmt = getelementptr [1 x i8], [1 x i8]* @null, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @null) ret void } -define void @test_simplify3(i8* %dst) { +define void @test_simplify3(ptr %dst) { ; CHECK-LABEL: @test_simplify3( -; CHECK-NEXT: store i8 0, i8* [[DST:%.*]], align 1 +; CHECK-NEXT: store i8 0, ptr [[DST:%.*]], align 1 ; CHECK-NEXT: ret void ; - %fmt = getelementptr [7 x i8], [7 x i8]* @null_hello, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @null_hello) ret void } -; Check sprintf(dst, "%c", chr) -> *(i8*)dst = chr; *((i8*)dst + 1) = 0. +; Check sprintf(dst, "%c", chr) -> *(ptr)dst = chr; *((ptr)dst + 1) = 0. -define void @test_simplify4(i8* %dst) { +define void @test_simplify4(ptr %dst) { ; CHECK-LABEL: @test_simplify4( -; CHECK-NEXT: store i8 104, i8* [[DST:%.*]], align 1 -; CHECK-NEXT: [[NUL:%.*]] = getelementptr inbounds i8, i8* [[DST]], i32 1 -; CHECK-NEXT: store i8 0, i8* [[NUL]], align 1 +; CHECK-NEXT: store i8 104, ptr [[DST:%.*]], align 1 +; CHECK-NEXT: [[NUL:%.*]] = getelementptr inbounds i8, ptr [[DST]], i32 1 +; CHECK-NEXT: store i8 0, ptr [[NUL]], align 1 ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_c, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8 104) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_c, i8 104) ret void } ; Check sprintf(dst, "%s", str) -> strcpy(dst, "%s", str) if result is unused. -define void @test_simplify5(i8* %dst, i8* %str) { +define void @test_simplify5(ptr %dst, ptr %str) { ; CHECK-LABEL: @test_simplify5( -; CHECK-NEXT: [[STRCPY:%.*]] = call i8* @strcpy(i8* noundef nonnull dereferenceable(1) [[DST:%.*]], i8* noundef nonnull dereferenceable(1) [[STR:%.*]]) +; CHECK-NEXT: [[STRCPY:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull dereferenceable(1) [[STR:%.*]]) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_s, ptr %str) ret void } ; Check sprintf(dst, format, ...) -> siprintf(str, format, ...) if no floating. -define void @test_simplify6(i8* %dst) { +define void @test_simplify6(ptr %dst) { ; CHECK-IPRINTF-LABEL: @test_simplify6( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (i8*, i8*, ...) @siprintf(i8* [[DST:%.*]], i8* getelementptr inbounds ([3 x i8], [3 x i8]* @percent_d, i32 0, i32 0), i32 187) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @siprintf(ptr [[DST:%.*]], ptr nonnull @percent_d, i32 187) ; CHECK-IPRINTF-NEXT: ret void ; ; WIN-LABEL: @test_simplify6( -; WIN-NEXT: [[TMP1:%.*]] = call i32 (i8*, i8*, ...) @sprintf(i8* noundef nonnull dereferenceable(1) [[DST:%.*]], i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @percent_d, i32 0, i32 0), i32 187) +; WIN-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull @percent_d, i32 187) ; WIN-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_d, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i32 187) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_d, i32 187) ret void } ; Check sprintf(dst, "%s", str) -> llvm.memcpy(dest, str, strlen(str) + 1, 1). -define i32 @test_simplify7(i8* %dst, i8* %str) { +define i32 @test_simplify7(ptr %dst, ptr %str) { ; WITHSTPCPY-LABEL: @test_simplify7( -; WITHSTPCPY-NEXT: [[STPCPY:%.*]] = call i8* @stpcpy(i8* [[DST:%.*]], i8* [[STR:%.*]]) -; WITHSTPCPY-NEXT: [[TMP1:%.*]] = ptrtoint i8* [[STPCPY]] to i32 -; WITHSTPCPY-NEXT: [[TMP2:%.*]] = ptrtoint i8* [[DST]] to i32 +; WITHSTPCPY-NEXT: [[STPCPY:%.*]] = call ptr @stpcpy(ptr [[DST:%.*]], ptr [[STR:%.*]]) +; WITHSTPCPY-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[STPCPY]] to i32 +; WITHSTPCPY-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[DST]] to i32 ; WITHSTPCPY-NEXT: [[TMP3:%.*]] = sub i32 [[TMP1]], [[TMP2]] ; WITHSTPCPY-NEXT: ret i32 [[TMP3]] ; ; NOSTPCPY-LABEL: @test_simplify7( -; NOSTPCPY-NEXT: [[STRLEN:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]]) +; NOSTPCPY-NEXT: [[STRLEN:%.*]] = call i32 @strlen(ptr noundef nonnull dereferenceable(1) [[STR:%.*]]) ; NOSTPCPY-NEXT: [[LENINC:%.*]] = add i32 [[STRLEN]], 1 -; NOSTPCPY-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false) +; NOSTPCPY-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[DST:%.*]], ptr align 1 [[STR]], i32 [[LENINC]], i1 false) ; NOSTPCPY-NEXT: ret i32 [[STRLEN]] ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0 - %r = call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str) + %r = call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_s, ptr %str) ret i32 %r } ; Check sprintf(dst, "%s", str) -> llvm.memcpy(dest, str, strlen(str) + 1, 1). -define i32 @test_simplify8(i8* %dst) { +define i32 @test_simplify8(ptr %dst) { ; CHECK-LABEL: @test_simplify8( -; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* noundef nonnull align 1 dereferenceable(13) [[DST:%.*]], i8* noundef nonnull align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 13, i1 false) +; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(13) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(13) @hello_world, i32 13, i1 false) ; CHECK-NEXT: ret i32 12 ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0 - %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - %r = call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str) + %r = call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_s, ptr @hello_world) ret i32 %r } ; Check sprintf(dst, "%s", str) -> stpcpy(dest, str) - dest -define i32 @test_simplify9(i8* %dst, i8* %str) { +define i32 @test_simplify9(ptr %dst, ptr %str) { ; CHECK-IPRINTF-LABEL: @test_simplify9( -; CHECK-IPRINTF-NEXT: [[STPCPY:%.*]] = call i8* @stpcpy(i8* [[DST:%.*]], i8* [[STR:%.*]]) -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = ptrtoint i8* [[STPCPY]] to i32 -; CHECK-IPRINTF-NEXT: [[TMP2:%.*]] = ptrtoint i8* [[DST]] to i32 +; CHECK-IPRINTF-NEXT: [[STPCPY:%.*]] = call ptr @stpcpy(ptr [[DST:%.*]], ptr [[STR:%.*]]) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[STPCPY]] to i32 +; CHECK-IPRINTF-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[DST]] to i32 ; CHECK-IPRINTF-NEXT: [[TMP3:%.*]] = sub i32 [[TMP1]], [[TMP2]] ; CHECK-IPRINTF-NEXT: ret i32 [[TMP3]] ; ; WIN-LABEL: @test_simplify9( -; WIN-NEXT: [[STRLEN:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]]) +; WIN-NEXT: [[STRLEN:%.*]] = call i32 @strlen(ptr noundef nonnull dereferenceable(1) [[STR:%.*]]) ; WIN-NEXT: [[LENINC:%.*]] = add i32 [[STRLEN]], 1 -; WIN-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false) +; WIN-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[DST:%.*]], ptr align 1 [[STR]], i32 [[LENINC]], i1 false) ; WIN-NEXT: ret i32 [[STRLEN]] ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0 - %r = call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str) + %r = call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_s, ptr %str) ret i32 %r } -define void @test_no_simplify1(i8* %dst) { +define void @test_no_simplify1(ptr %dst) { ; CHECK-LABEL: @test_no_simplify1( -; CHECK-NEXT: [[TMP1:%.*]] = call i32 (i8*, i8*, ...) @sprintf(i8* noundef nonnull dereferenceable(1) [[DST:%.*]], i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @percent_f, i32 0, i32 0), double 1.870000e+00) +; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull @percent_f, double 1.870000e+00) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_f, i32 0, i32 0 - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, double 1.87) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_f, double 1.87) ret void } -define void @test_no_simplify2(i8* %dst, i8* %fmt, double %d) { +define void @test_no_simplify2(ptr %dst, ptr %fmt, double %d) { ; CHECK-LABEL: @test_no_simplify2( -; CHECK-NEXT: [[TMP1:%.*]] = call i32 (i8*, i8*, ...) @sprintf(i8* noundef nonnull dereferenceable(1) [[DST:%.*]], i8* noundef nonnull dereferenceable(1) [[FMT:%.*]], double [[D:%.*]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull dereferenceable(1) [[FMT:%.*]], double [[D:%.*]]) ; CHECK-NEXT: ret void ; - call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, double %d) + call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr %fmt, double %d) ret void } -define i32 @test_no_simplify3(i8* %dst, i8* %str) minsize { +define i32 @test_no_simplify3(ptr %dst, ptr %str) minsize { ; CHECK-IPRINTF-LABEL: @test_no_simplify3( -; CHECK-IPRINTF-NEXT: [[STPCPY:%.*]] = call i8* @stpcpy(i8* [[DST:%.*]], i8* [[STR:%.*]]) -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = ptrtoint i8* [[STPCPY]] to i32 -; CHECK-IPRINTF-NEXT: [[TMP2:%.*]] = ptrtoint i8* [[DST]] to i32 +; CHECK-IPRINTF-NEXT: [[STPCPY:%.*]] = call ptr @stpcpy(ptr [[DST:%.*]], ptr [[STR:%.*]]) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[STPCPY]] to i32 +; CHECK-IPRINTF-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[DST]] to i32 ; CHECK-IPRINTF-NEXT: [[TMP3:%.*]] = sub i32 [[TMP1]], [[TMP2]] ; CHECK-IPRINTF-NEXT: ret i32 [[TMP3]] ; ; WIN-LABEL: @test_no_simplify3( -; WIN-NEXT: [[R:%.*]] = call i32 (i8*, i8*, ...) @sprintf(i8* noundef nonnull dereferenceable(1) [[DST:%.*]], i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @percent_s, i32 0, i32 0), i8* [[STR:%.*]]) +; WIN-NEXT: [[R:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull @percent_s, ptr [[STR:%.*]]) ; WIN-NEXT: ret i32 [[R]] ; - %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0 - %r = call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str) + %r = call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_s, ptr %str) ret i32 %r } diff --git a/llvm/test/Transforms/InstCombine/sprintf-2.ll b/llvm/test/Transforms/InstCombine/sprintf-2.ll index 7af255b79..086be81 100644 --- a/llvm/test/Transforms/InstCombine/sprintf-2.ll +++ b/llvm/test/Transforms/InstCombine/sprintf-2.ll @@ -3,7 +3,7 @@ ; are folded to constants as expected. ; RUN: opt < %s -passes=instcombine -S | FileCheck %s -declare i32 @snprintf(i8*, i64, i8*, ...) +declare i32 @snprintf(ptr, i64, ptr, ...) %struct.A = type { [5 x i8], [6 x i8], [7 x i8] } @@ -15,81 +15,78 @@ declare i32 @snprintf(i8*, i64, i8*, ...) ; Fold snprintf(0, 0, "%s", a[I].M + C) for constant I in [0, 1], ; member M in [a, b, c], and C in a valid range to a constant. -define void @fold_snprintf_member_pC(i32* %pi) { +define void @fold_snprintf_member_pC(ptr %pi) { ; CHECK-LABEL: @fold_snprintf_member_pC( -; CHECK-NEXT: store i32 1, i32* [[PI:%.*]], align 4 -; CHECK-NEXT: [[PIA0AP1:%.*]] = getelementptr i32, i32* [[PI]], i64 1 -; CHECK-NEXT: store i32 0, i32* [[PIA0AP1]], align 4 -; CHECK-NEXT: [[PIA0B:%.*]] = getelementptr i32, i32* [[PI]], i64 2 -; CHECK-NEXT: store i32 2, i32* [[PIA0B]], align 4 -; CHECK-NEXT: [[PIA0BP1:%.*]] = getelementptr i32, i32* [[PI]], i64 3 -; CHECK-NEXT: store i32 1, i32* [[PIA0BP1]], align 4 -; CHECK-NEXT: [[PIA0BP2:%.*]] = getelementptr i32, i32* [[PI]], i64 4 -; CHECK-NEXT: store i32 0, i32* [[PIA0BP2]], align 4 -; CHECK-NEXT: [[PIA0C:%.*]] = getelementptr i32, i32* [[PI]], i64 5 -; CHECK-NEXT: store i32 3, i32* [[PIA0C]], align 4 -; CHECK-NEXT: [[PIA1A:%.*]] = getelementptr i32, i32* [[PI]], i64 6 -; CHECK-NEXT: store i32 4, i32* [[PIA1A]], align 4 -; CHECK-NEXT: [[PIA1B:%.*]] = getelementptr i32, i32* [[PI]], i64 7 -; CHECK-NEXT: store i32 5, i32* [[PIA1B]], align 4 -; CHECK-NEXT: [[PIA1C:%.*]] = getelementptr i32, i32* [[PI]], i64 8 -; CHECK-NEXT: store i32 6, i32* [[PIA1C]], align 4 +; CHECK-NEXT: store i32 1, ptr [[PI:%.*]], align 4 +; CHECK-NEXT: [[PIA0AP1:%.*]] = getelementptr i32, ptr [[PI]], i64 1 +; CHECK-NEXT: store i32 0, ptr [[PIA0AP1]], align 4 +; CHECK-NEXT: [[PIA0B:%.*]] = getelementptr i32, ptr [[PI]], i64 2 +; CHECK-NEXT: store i32 2, ptr [[PIA0B]], align 4 +; CHECK-NEXT: [[PIA0BP1:%.*]] = getelementptr i32, ptr [[PI]], i64 3 +; CHECK-NEXT: store i32 1, ptr [[PIA0BP1]], align 4 +; CHECK-NEXT: [[PIA0BP2:%.*]] = getelementptr i32, ptr [[PI]], i64 4 +; CHECK-NEXT: store i32 0, ptr [[PIA0BP2]], align 4 +; CHECK-NEXT: [[PIA0C:%.*]] = getelementptr i32, ptr [[PI]], i64 5 +; CHECK-NEXT: store i32 3, ptr [[PIA0C]], align 4 +; CHECK-NEXT: [[PIA1A:%.*]] = getelementptr i32, ptr [[PI]], i64 6 +; CHECK-NEXT: store i32 4, ptr [[PIA1A]], align 4 +; CHECK-NEXT: [[PIA1B:%.*]] = getelementptr i32, ptr [[PI]], i64 7 +; CHECK-NEXT: store i32 5, ptr [[PIA1B]], align 4 +; CHECK-NEXT: [[PIA1C:%.*]] = getelementptr i32, ptr [[PI]], i64 8 +; CHECK-NEXT: store i32 6, ptr [[PIA1C]], align 4 ; CHECK-NEXT: ret void ; - %fmt = getelementptr [3 x i8], [3 x i8]* @pcnt_s, i32 0, i32 0 ; Fold snprintf(0, 0, "%s", a[0].a) to 1. - %pa0a = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 0, i32 0, i64 0 - %ia0a = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa0a) - %pia0a = getelementptr i32, i32* %pi, i32 0 - store i32 %ia0a, i32* %pia0a + %ia0a = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr @a) + store i32 %ia0a, ptr %pi ; Fold snprintf(0, 0, "%s", a[0].a) to 0. - %pa0ap1 = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 0, i32 0, i64 1 - %ia0ap1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa0ap1) - %pia0ap1 = getelementptr i32, i32* %pi, i32 1 - store i32 %ia0ap1, i32* %pia0ap1 + %pa0ap1 = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 0, i32 0, i64 1 + %ia0ap1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa0ap1) + %pia0ap1 = getelementptr i32, ptr %pi, i32 1 + store i32 %ia0ap1, ptr %pia0ap1 ; Fold snprintf(0, 0, "%s", a[0].b) to 2. - %pa0b = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 0, i32 1, i64 0 - %ia0b = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa0b) - %pia0b = getelementptr i32, i32* %pi, i32 2 - store i32 %ia0b, i32* %pia0b + %pa0b = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 0, i32 1, i64 0 + %ia0b = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa0b) + %pia0b = getelementptr i32, ptr %pi, i32 2 + store i32 %ia0b, ptr %pia0b ; Fold snprintf(0, 0, "%s", a[0].b + 1) to 1. - %pa0bp1 = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 0, i32 1, i64 1 - %ia0bp1 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa0bp1) - %pia0bp1 = getelementptr i32, i32* %pi, i32 3 - store i32 %ia0bp1, i32* %pia0bp1 + %pa0bp1 = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 0, i32 1, i64 1 + %ia0bp1 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa0bp1) + %pia0bp1 = getelementptr i32, ptr %pi, i32 3 + store i32 %ia0bp1, ptr %pia0bp1 ; Fold snprintf(0, 0, "%s", a[0].b + 2) to 0. - %pa0bp2 = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 0, i32 1, i64 2 - %ia0bp2 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa0bp2) - %pia0bp2 = getelementptr i32, i32* %pi, i32 4 - store i32 %ia0bp2, i32* %pia0bp2 + %pa0bp2 = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 0, i32 1, i64 2 + %ia0bp2 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa0bp2) + %pia0bp2 = getelementptr i32, ptr %pi, i32 4 + store i32 %ia0bp2, ptr %pia0bp2 ; Fold snprintf(0, 0, "%s", a[0].c) to 3. - %pa0c = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 0, i32 2, i64 0 - %ia0c = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa0c) - %pia0c = getelementptr i32, i32* %pi, i32 5 - store i32 %ia0c, i32* %pia0c + %pa0c = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 0, i32 2, i64 0 + %ia0c = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa0c) + %pia0c = getelementptr i32, ptr %pi, i32 5 + store i32 %ia0c, ptr %pia0c ; Fold snprintf(0, 0, "%s", a[1].a) to 4. - %pa1a = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 1, i32 0, i64 0 - %ia1a = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa1a) - %pia1a = getelementptr i32, i32* %pi, i32 6 - store i32 %ia1a, i32* %pia1a + %pa1a = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 1, i32 0, i64 0 + %ia1a = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa1a) + %pia1a = getelementptr i32, ptr %pi, i32 6 + store i32 %ia1a, ptr %pia1a ; Fold snprintf(0, 0, "%s", a[1].b) to 5. - %pa1b = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 1, i32 1, i64 0 - %ia1b = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa1b) - %pia1b = getelementptr i32, i32* %pi, i32 7 - store i32 %ia1b, i32* %pia1b + %pa1b = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 1, i32 1, i64 0 + %ia1b = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa1b) + %pia1b = getelementptr i32, ptr %pi, i32 7 + store i32 %ia1b, ptr %pia1b ; Fold snprintf(0, 0, "%s", a[1].c) to 6. - %pa1c = getelementptr [2 x %struct.A], [2 x %struct.A]* @a, i64 0, i64 1, i32 2, i64 0 - %ia1c = call i32 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* %fmt, i8* %pa1c) - %pia1c = getelementptr i32, i32* %pi, i32 8 - store i32 %ia1c, i32* %pia1c + %pa1c = getelementptr [2 x %struct.A], ptr @a, i64 0, i64 1, i32 2, i64 0 + %ia1c = call i32 (ptr, i64, ptr, ...) @snprintf(ptr null, i64 0, ptr @pcnt_s, ptr %pa1c) + %pia1c = getelementptr i32, ptr %pi, i32 8 + store i32 %ia1c, ptr %pia1c ret void } diff --git a/llvm/test/Transforms/InstCombine/sprintf-3.ll b/llvm/test/Transforms/InstCombine/sprintf-3.ll index aa883f8..f88e692 100644 --- a/llvm/test/Transforms/InstCombine/sprintf-3.ll +++ b/llvm/test/Transforms/InstCombine/sprintf-3.ll @@ -8,12 +8,12 @@ @percent_s = constant [3 x i8] c"%s\00" -declare i32 @sprintf(i8**, i32*, ...) +declare i32 @sprintf(ptr, ptr, ...) -define i32 @PR51200(i8** %p, i32* %p2) { +define i32 @PR51200(ptr %p, ptr %p2) { ; CHECK-LABEL: @PR51200( ; Don't check anything, just expect the test to compile successfully. ; - %call = call i32 (i8**, i32*, ...) @sprintf(i8** %p, i32* bitcast ([3 x i8]* @percent_s to i32*), i32* %p2) + %call = call i32 (ptr, ptr, ...) @sprintf(ptr %p, ptr @percent_s, ptr %p2) ret i32 %call } diff --git a/llvm/test/Transforms/InstCombine/sprintf-void.ll b/llvm/test/Transforms/InstCombine/sprintf-void.ll index 4d04d1c..9abe328 100644 --- a/llvm/test/Transforms/InstCombine/sprintf-void.ll +++ b/llvm/test/Transforms/InstCombine/sprintf-void.ll @@ -5,17 +5,16 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3 @hello_world = constant [13 x i8] c"hello world\0A\00" -declare void @sprintf(i8*, i8*, ...) +declare void @sprintf(ptr, ptr, ...) ; Check that a sprintf call, that would otherwise be optimized, but with ; optimized out return type, doesn't crash the optimizer. -define void @test_simplify1(i8* %dst) { +define void @test_simplify1(ptr %dst) { ; CHECK-LABEL: @test_simplify1( -; CHECK-NEXT: call void (i8*, i8*, ...) @sprintf(i8* [[DST:%.*]], i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0)) +; CHECK-NEXT: call void (ptr, ptr, ...) @sprintf(ptr [[DST:%.*]], ptr nonnull @hello_world) ; CHECK-NEXT: ret void ; - %fmt = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0 - call void (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt) + call void (ptr, ptr, ...) @sprintf(ptr %dst, ptr @hello_world) ret void } -- 2.7.4