[llvm] 05c912a - [InstCombine][NFC] add tests for printf("%s", str) --> puts(str)/noop transformation.
Dávid Bolvanský via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 23 05:27:30 PDT 2021
Author: Dawid Jurczak
Date: 2021-04-23T14:27:16+02:00
New Revision: 05c912a439cc5ef0f76888e59188582f35fdc0bc
URL: https://github.com/llvm/llvm-project/commit/05c912a439cc5ef0f76888e59188582f35fdc0bc
DIFF: https://github.com/llvm/llvm-project/commit/05c912a439cc5ef0f76888e59188582f35fdc0bc.diff
LOG: [InstCombine][NFC] add tests for printf("%s", str) --> puts(str)/noop transformation.
Split off from D100724.
Reviewed By: xbolva00
Differential Revision: https://reviews.llvm.org/D101149
Added:
Modified:
llvm/test/Transforms/InstCombine/printf-2.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/printf-2.ll b/llvm/test/Transforms/InstCombine/printf-2.ll
index 16caf3420f98..7c9d5bd2fac2 100644
--- a/llvm/test/Transforms/InstCombine/printf-2.ll
+++ b/llvm/test/Transforms/InstCombine/printf-2.ll
@@ -10,6 +10,7 @@ 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 [4 x i8] c"%s\0A\00"
@format_str = constant [3 x i8] c"%s\00"
@charstr = constant [2 x i8] c"a\00"
+ at empty = constant [1 x i8] c"\00"
declare void @printf(i8*, ...)
@@ -21,6 +22,7 @@ declare void @printf(i8*, ...)
; CHECK: @[[PERCENT_S:[a-zA-Z0-9_$"\\.-]+]] = constant [4 x i8] c"%s\0A\00"
; CHECK: @[[FORMAT_STR:[a-zA-Z0-9_$"\\.-]+]] = constant [3 x i8] c"%s\00"
; CHECK: @[[CHARSTR:[a-zA-Z0-9_$"\\.-]+]] = constant [2 x i8] c"a\00"
+; CHECK: @[[EMPTY:[a-zA-Z0-9_$"\\.-]+]] = constant [1 x i8] zeroinitializer
; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1
;.
define void @test_simplify1() {
@@ -64,6 +66,45 @@ define void @test_simplify7() {
call void (i8*, ...) @printf(i8* %fmt, i8* %str)
ret void
}
+
+define void @test_simplify8() {
+; CHECK-LABEL: @test_simplify8(
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0))
+; CHECK-NEXT: ret void
+;
+ %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
+ %str = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str)
+ ret void
+}
+
+define void @test_simplify9() {
+; CHECK-LABEL: @test_simplify9(
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0))
+; CHECK-NEXT: ret void
+;
+ %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
+ %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str)
+ ret void
+}
+
+define void @test_simplify10() {
+; CHECK-LABEL: @test_simplify10(
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0), i32 42, double 0x40091EB860000000)
+; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 42, double 0x40091EB860000000)
+; CHECK-NEXT: ret void
+;
+ %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
+ %str1 = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str1, i32 42, double 0x40091EB860000000)
+ %str2 = getelementptr [2 x i8], [2 x i8]* @charstr, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str2, i32 42, double 0x40091EB860000000)
+ %str3 = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str3, i32 42, double 0x40091EB860000000)
+ ret void
+}
;.
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nofree nounwind }
;.
More information about the llvm-commits
mailing list