[PATCH] D95138: [SLC] Baseline test for missed strcpy optimizations in non-zero AS

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 04:19:39 PST 2021


arichardson created this revision.
arichardson updated this revision to Diff 318834.
arichardson added a comment.
arichardson retitled this revision from "[SLC] Add a baseline test showing missed optimizations for non-zero AS" to "[SLC] Add a test showing missed strcpy optimizations for non-zero AS".
arichardson edited the summary of this revision.
arichardson updated this revision to Diff 318835.
arichardson edited the summary of this revision.
Herald added a subscriber: hiraditya.
arichardson updated this revision to Diff 318952.
arichardson updated this revision to Diff 318954.
arichardson retitled this revision from "[SLC] Add a test showing missed strcpy optimizations for non-zero AS" to "[SLC] Baseline test for missed strcpy optimizations in non-zero AS".
arichardson published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

simplify test.
AS0 is already tested in other files so no need to include it here.
This also means we no longer need sed


arichardson added a comment.

simplify test case (no more need for sed)


arichardson added a comment.

"fix" failing strncpy_chk-2.ll


arichardson added a comment.

update


This will be fixed in D95142 <https://reviews.llvm.org/D95142>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95138

Files:
  llvm/test/Transforms/InstCombine/strcpy-nonzero-as.ll


Index: llvm/test/Transforms/InstCombine/strcpy-nonzero-as.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/strcpy-nonzero-as.ll
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
+; Test that the strcpy library call simplifier also works when the string
+; libcall arguments are in a non-zero address space.
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-m:e-p200:128:128:128:64-p:64:64-A200-P200-G200"
+
+ at str = private unnamed_addr addrspace(200) constant [17 x i8] c"exactly 16 chars\00", align 1
+
+declare i8 addrspace(200)* @strcpy(i8 addrspace(200)*, i8 addrspace(200)*) addrspace(200)
+declare i8 addrspace(200)* @stpcpy(i8 addrspace(200)*, i8 addrspace(200)*) addrspace(200)
+declare i8 addrspace(200)* @strncpy(i8 addrspace(200)*, i8 addrspace(200)*, i64) addrspace(200)
+declare i8 addrspace(200)* @stpncpy(i8 addrspace(200)*, i8 addrspace(200)*, i64) addrspace(200)
+
+; TODO: this should be converted to a memcpy
+define void @test_strcpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
+; CHECK-LABEL: define {{[^@]+}}@test_strcpy_to_memcpy
+; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0:#.*]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = call addrspace(200) i8 addrspace(200)* @strcpy(i8 addrspace(200)* [[DST]], i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0))
+; CHECK-NEXT:    ret void
+;
+entry:
+  %call = call i8 addrspace(200)* @strcpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0))
+  ret void
+}
+
+; TODO: this should be converted to a memcpy
+define void @test_stpcpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
+; CHECK-LABEL: define {{[^@]+}}@test_stpcpy_to_memcpy
+; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = call addrspace(200) i8 addrspace(200)* @stpcpy(i8 addrspace(200)* [[DST]], i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0))
+; CHECK-NEXT:    ret void
+;
+entry:
+  %call = call i8 addrspace(200)* @stpcpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0))
+  ret void
+}
+
+; TODO: this should be converted to a memcpy
+define void @test_strncpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
+; CHECK-LABEL: define {{[^@]+}}@test_strncpy_to_memcpy
+; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = call addrspace(200) i8 addrspace(200)* @strncpy(i8 addrspace(200)* [[DST]], i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)
+; CHECK-NEXT:    ret void
+;
+entry:
+  %call = call i8 addrspace(200)* @strncpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)
+  ret void
+}
+
+; Note: stpncpy is not handled by SimplifyLibcalls yet, so this should not be changed.
+define void @test_stpncpy_to_memcpy(i8 addrspace(200)* %dst) addrspace(200) nounwind {
+; CHECK-LABEL: define {{[^@]+}}@test_stpncpy_to_memcpy
+; CHECK-SAME: (i8 addrspace(200)* [[DST:%.*]]) addrspace(200) [[ATTR0]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CALL:%.*]] = call addrspace(200) i8 addrspace(200)* @stpncpy(i8 addrspace(200)* [[DST]], i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)
+; CHECK-NEXT:    ret void
+;
+entry:
+  %call = call i8 addrspace(200)* @stpncpy(i8 addrspace(200)* %dst, i8 addrspace(200)* getelementptr inbounds ([17 x i8], [17 x i8] addrspace(200)* @str, i64 0, i64 0), i64 17)
+  ret void
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95138.318954.patch
Type: text/x-patch
Size: 4029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210125/f01c45ac/attachment.bin>


More information about the llvm-commits mailing list