[PATCH] D101149: [InstCombine][NFC] add tests for printf("%s", str) --> puts(str)/noop transformation.
Dawid Jurczak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 23 02:39:33 PDT 2021
yurai007 created this revision.
yurai007 added reviewers: xbolva00, spatel, lebedev.ri, fhahn.
yurai007 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Split off from D100724 <https://reviews.llvm.org/D100724>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D101149
Files:
llvm/test/Transforms/InstCombine/printf-2.ll
Index: llvm/test/Transforms/InstCombine/printf-2.ll
===================================================================
--- llvm/test/Transforms/InstCombine/printf-2.ll
+++ llvm/test/Transforms/InstCombine/printf-2.ll
@@ -10,6 +10,7 @@
@percent_s = constant [4 x i8] c"%s\0A\00"
@format_str = constant [3 x i8] c"%s\00"
@charstr = constant [2 x i8] c"a\00"
+ at empty = constant [1 x i8] c"\00"
declare void @printf(i8*, ...)
@@ -21,6 +22,7 @@
; CHECK: @[[PERCENT_S:[a-zA-Z0-9_$"\\.-]+]] = constant [4 x i8] c"%s\0A\00"
; CHECK: @[[FORMAT_STR:[a-zA-Z0-9_$"\\.-]+]] = constant [3 x i8] c"%s\00"
; CHECK: @[[CHARSTR:[a-zA-Z0-9_$"\\.-]+]] = constant [2 x i8] c"a\00"
+; CHECK: @[[EMPTY:[a-zA-Z0-9_$"\\.-]+]] = constant [1 x i8] zeroinitializer
; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1
;.
define void @test_simplify1() {
@@ -64,6 +66,45 @@
call void (i8*, ...) @printf(i8* %fmt, i8* %str)
ret void
}
+
+define void @test_simplify8() {
+; CHECK-LABEL: @test_simplify8(
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0))
+; CHECK-NEXT: ret void
+;
+ %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
+ %str = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str)
+ ret void
+}
+
+define void @test_simplify9() {
+; CHECK-LABEL: @test_simplify9(
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0))
+; CHECK-NEXT: ret void
+;
+ %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
+ %str = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str)
+ ret void
+}
+
+define void @test_simplify10() {
+; CHECK-LABEL: @test_simplify10(
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @empty, i32 0, i32 0), i32 42, double 0x40091EB860000000)
+; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)
+; CHECK-NEXT: call void (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @format_str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @hello_world, i32 0, i32 0), i32 42, double 0x40091EB860000000)
+; CHECK-NEXT: ret void
+;
+ %fmt = getelementptr [3 x i8], [3 x i8]* @format_str, i32 0, i32 0
+ %str1 = getelementptr [1 x i8], [1 x i8]* @empty, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str1, i32 42, double 0x40091EB860000000)
+ %str2 = getelementptr [2 x i8], [2 x i8]* @charstr, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str2, i32 42, double 0x40091EB860000000)
+ %str3 = getelementptr [13 x i8], [13 x i8]* @hello_world, i32 0, i32 0
+ call void (i8*, ...) @printf(i8* %fmt, i8* %str3, i32 42, double 0x40091EB860000000)
+ ret void
+}
;.
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nofree nounwind }
;.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101149.339957.patch
Type: text/x-patch
Size: 3346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210423/fe729bee/attachment.bin>
More information about the llvm-commits
mailing list