From 5f319fc444ca6c4b6b3905a026534d6d90acd37e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 6 Mar 2021 23:17:28 +0100 Subject: [PATCH] [GVN] Add test for load GVN with dead block (NFC) 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 | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 llvm/test/Transforms/GVN/load-dead-block.ll diff --git a/llvm/test/Transforms/GVN/load-dead-block.ll b/llvm/test/Transforms/GVN/load-dead-block.ll new file mode 100644 index 0000000..f797973 --- /dev/null +++ b/llvm/test/Transforms/GVN/load-dead-block.ll @@ -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) -- 2.7.4