From 0f80d598b0c5d8d480db4f360c3cb5fe49ab86a3 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Thu, 23 Jul 2020 17:17:40 +0100 Subject: [PATCH] [IPSCCP] Add test case for PR46717 for argmemonly handling. --- llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 llvm/test/Transforms/SCCP/ipscp-drop-argmemonly.ll 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 0000000..898a61a --- /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 + +@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 +} -- 2.7.4