[llvm] 0f80d59 - [IPSCCP] Add test case for PR46717 for argmemonly handling.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 09:28:42 PDT 2020


Author: Florian Hahn
Date: 2020-07-23T17:25:26+01:00
New Revision: 0f80d598b0c5d8d480db4f360c3cb5fe49ab86a3

URL: https://github.com/llvm/llvm-project/commit/0f80d598b0c5d8d480db4f360c3cb5fe49ab86a3
DIFF: https://github.com/llvm/llvm-project/commit/0f80d598b0c5d8d480db4f360c3cb5fe49ab86a3.diff

LOG: [IPSCCP] Add test case for PR46717 for argmemonly handling.

Added: 
    llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll b/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll
new file mode 100644
index 000000000000..898a61aee2e4
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll
@@ -0,0 +1,130 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes
+; RUN: opt -ipsccp -S %s | FileCheck %s
+
+; Test cases to ensure argmemonly/inaccessiblemem_or_argmemonly attributes are
+; dropped, if a function argument is replaced by a constant.
+;
+; PR46717
+
+ at g = internal global i32 0
+
+; Here the pointer argument %arg will be replaced by a constant. We need to
+; drop argmemonly.
+define internal void @ptrarg.1(i32* %arg, i32 %val) argmemonly nounwind {
+; CHECK: Function Attrs: argmemonly nounwind
+; CHECK-LABEL: @ptrarg.1(
+; CHECK-NEXT:    store i32 10, i32* @g, align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 %val, i32* %arg
+  ret void
+}
+
+define i32 @caller.1(i32 %n) {
+; CHECK-LABEL: @caller.1(
+; CHECK-NEXT:    store i32 1, i32* @g, align 4
+; CHECK-NEXT:    tail call void @ptrarg.1(i32* @g, i32 10)
+; CHECK-NEXT:    [[G_VAL:%.*]] = load i32, i32* @g, align 4
+; CHECK-NEXT:    ret i32 [[G_VAL]]
+;
+  store i32 1, i32* @g
+  tail call void @ptrarg.1(i32* @g, i32 10)
+  %g.val = load i32, i32* @g
+  ret i32 %g.val
+}
+
+
+; Here only the non-pointer argument %val is replaced, no need
+; to drop the argmemonly attribute.
+define internal void @ptrarg.2(i32* %arg, i32 %val) argmemonly nounwind {
+; CHECK: Function Attrs: argmemonly nounwind
+; CHECK-LABEL: @ptrarg.2(
+; CHECK-NEXT:    store i32 10, i32* [[ARG:%.*]], align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 %val, i32* %arg
+  ret void
+}
+
+define void @caller.2(i32* %ptr) {
+; CHECK-LABEL: @caller.2(
+; CHECK-NEXT:    tail call void @ptrarg.2(i32* [[PTR:%.*]], i32 10)
+; CHECK-NEXT:    ret void
+;
+  tail call void @ptrarg.2(i32* %ptr, i32 10)
+  ret void
+}
+
+
+; Here the pointer argument %arg will be replaced by a constant. We need to
+; drop inaccessiblemem_or_argmemonly.
+define internal void @ptrarg.3(i32* %arg, i32 %val) inaccessiblemem_or_argmemonly nounwind {
+; CHECK: Function Attrs: inaccessiblemem_or_argmemonly nounwind
+; CHECK-LABEL: @ptrarg.3(
+; CHECK-NEXT:    store i32 10, i32* @g, align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 %val, i32* %arg
+  ret void
+}
+
+define i32 @caller.3(i32 %n) {
+; CHECK-LABEL: @caller.3(
+; CHECK-NEXT:    store i32 1, i32* @g, align 4
+; CHECK-NEXT:    tail call void @ptrarg.3(i32* @g, i32 10)
+; CHECK-NEXT:    [[G_VAL:%.*]] = load i32, i32* @g, align 4
+; CHECK-NEXT:    ret i32 [[G_VAL]]
+;
+  store i32 1, i32* @g
+  tail call void @ptrarg.3(i32* @g, i32 10)
+  %g.val = load i32, i32* @g
+  ret i32 %g.val
+}
+
+
+; Here only the non-pointer argument %val is replaced, no need
+; to drop the inaccessiblemem_or_argmemonly attribute.
+define internal void @ptrarg.4(i32* %arg, i32 %val) inaccessiblemem_or_argmemonly nounwind {
+; CHECK: Function Attrs: inaccessiblemem_or_argmemonly nounwind
+; CHECK-LABEL: @ptrarg.4(
+; CHECK-NEXT:    store i32 10, i32* [[ARG:%.*]], align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 %val, i32* %arg
+  ret void
+}
+
+define void @caller.4(i32* %ptr) {
+; CHECK-LABEL: @caller.4(
+; CHECK-NEXT:    tail call void @ptrarg.4(i32* [[PTR:%.*]], i32 10)
+; CHECK-NEXT:    ret void
+;
+  tail call void @ptrarg.4(i32* %ptr, i32 10)
+  ret void
+}
+
+
+; Here the pointer argument %arg will be replaced by a constant. We need to
+; drop inaccessiblemem_or_argmemonly.
+define internal void @ptrarg.5(i32* %arg, i32 %val) argmemonly inaccessiblemem_or_argmemonly nounwind {
+; CHECK: Function Attrs: argmemonly inaccessiblemem_or_argmemonly nounwind
+; CHECK-LABEL: @ptrarg.5(
+; CHECK-NEXT:    store i32 10, i32* @g, align 4
+; CHECK-NEXT:    ret void
+;
+  store i32 %val, i32* %arg
+  ret void
+}
+
+define i32 @caller.5(i32 %n) {
+; CHECK-LABEL: @caller.5(
+; CHECK-NEXT:    store i32 1, i32* @g, align 4
+; CHECK-NEXT:    tail call void @ptrarg.5(i32* @g, i32 10)
+; CHECK-NEXT:    [[G_VAL:%.*]] = load i32, i32* @g, align 4
+; CHECK-NEXT:    ret i32 [[G_VAL]]
+;
+  store i32 1, i32* @g
+  tail call void @ptrarg.5(i32* @g, i32 10)
+  %g.val = load i32, i32* @g
+  ret i32 %g.val
+}


        


More information about the llvm-commits mailing list