[llvm] 97e06a0 - [GVN] Add tests for captured-before analysis (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 06:19:41 PDT 2023
Author: Nikita Popov
Date: 2023-10-20T15:18:57+02:00
New Revision: 97e06a0d83a55ff67e5fd0c7328233c44415de33
URL: https://github.com/llvm/llvm-project/commit/97e06a0d83a55ff67e5fd0c7328233c44415de33
DIFF: https://github.com/llvm/llvm-project/commit/97e06a0d83a55ff67e5fd0c7328233c44415de33.diff
LOG: [GVN] Add tests for captured-before analysis (NFC)
Added:
llvm/test/Transforms/GVN/captured-before.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/GVN/captured-before.ll b/llvm/test/Transforms/GVN/captured-before.ll
new file mode 100644
index 000000000000000..4e025b3f772e103
--- /dev/null
+++ b/llvm/test/Transforms/GVN/captured-before.ll
@@ -0,0 +1,80 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt -S -passes=gvn < %s | FileCheck %s
+
+declare void @capture(ptr)
+declare void @some_call()
+
+define i32 @test_call_before_capture(ptr %p) {
+; CHECK-LABEL: define i32 @test_call_before_capture(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT: store i32 123, ptr [[A]], align 4
+; CHECK-NEXT: call void @some_call()
+; CHECK-NEXT: call void @capture(ptr [[A]])
+; CHECK-NEXT: ret i32 123
+;
+ %a = alloca i32
+ store i32 123, ptr %a
+ call void @some_call()
+ %v = load i32, ptr %a
+ call void @capture(ptr %a)
+ ret i32 %v
+}
+
+define i32 @test_call_after_capture(ptr %p) {
+; CHECK-LABEL: define i32 @test_call_after_capture(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT: store i32 123, ptr [[A]], align 4
+; CHECK-NEXT: call void @capture(ptr [[A]])
+; CHECK-NEXT: call void @some_call()
+; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT: ret i32 [[V]]
+;
+ %a = alloca i32
+ store i32 123, ptr %a
+ call void @capture(ptr %a)
+ call void @some_call()
+ %v = load i32, ptr %a
+ ret i32 %v
+}
+
+define i32 @test_store_before_capture(ptr %p) {
+; CHECK-LABEL: define i32 @test_store_before_capture(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT: store i32 123, ptr [[A]], align 4
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-NEXT: store i32 42, ptr [[P2]], align 4
+; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT: call void @capture(ptr [[A]])
+; CHECK-NEXT: ret i32 [[V]]
+;
+ %a = alloca i32
+ store i32 123, ptr %a
+ %p2 = load ptr, ptr %p
+ store i32 42, ptr %p2
+ %v = load i32, ptr %a
+ call void @capture(ptr %a)
+ ret i32 %v
+}
+
+define i32 @test_store_after_capture(ptr %p) {
+; CHECK-LABEL: define i32 @test_store_after_capture(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT: store i32 123, ptr [[A]], align 4
+; CHECK-NEXT: call void @capture(ptr [[A]])
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-NEXT: store i32 42, ptr [[P2]], align 4
+; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT: ret i32 [[V]]
+;
+ %a = alloca i32
+ store i32 123, ptr %a
+ call void @capture(ptr %a)
+ %p2 = load ptr, ptr %p
+ store i32 42, ptr %p2
+ %v = load i32, ptr %a
+ ret i32 %v
+}
More information about the llvm-commits
mailing list