[GVN] Add test for load GVN with dead block (NFC)
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 6 Mar 2021 22:17:28 +0000 (23:17 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 6 Mar 2021 22:19:58 +0000 (23:19 +0100)
What this test illustrates is that GVN inserts an unnecessary
phi node initially, which prevents alias analysis from establishing
NoAlias, and MDA caches that result. We would be able to fully fold
this after another -gvn run with clean MDA.

llvm/test/Transforms/GVN/load-dead-block.ll [new file with mode: 0644]

diff --git a/llvm/test/Transforms/GVN/load-dead-block.ll b/llvm/test/Transforms/GVN/load-dead-block.ll
new file mode 100644 (file)
index 0000000..f797973
--- /dev/null
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -gvn < %s | FileCheck %s
+
+define i64 @test(i64** noalias %p, i64* noalias %q) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    store i64* [[Q:%.*]], i64** [[P:%.*]], align 8
+; CHECK-NEXT:    br i1 false, label [[IF:%.*]], label [[MERGE:%.*]]
+; CHECK:       if:
+; CHECK-NEXT:    call void @clobber(i64** [[P]])
+; CHECK-NEXT:    br label [[MERGE]]
+; CHECK:       merge:
+; CHECK-NEXT:    store i64 1, i64* [[Q]], align 4
+; CHECK-NEXT:    [[Q3:%.*]] = getelementptr i64, i64* [[Q]], i64 1
+; CHECK-NEXT:    store i64 2, i64* [[Q3]], align 4
+; CHECK-NEXT:    [[V2:%.*]] = load i64, i64* [[Q]], align 4
+; CHECK-NEXT:    ret i64 [[V2]]
+;
+entry:
+  store i64* %q, i64** %p
+  br i1 false, label %if, label %merge
+
+if:
+  call void @clobber(i64** %p)
+  br label %merge
+
+merge:
+  %q2 = load i64*, i64** %p
+  store i64 1, i64* %q2
+  %v = load i64, i64* %q
+  %q3 = getelementptr i64, i64* %q, i64 %v
+  store i64 2, i64* %q3
+  %v2 = load i64, i64* %q
+  ret i64 %v2
+}
+
+declare void @clobber(i64** %p)