Skip to content

Commit

Permalink
[GVN] Add test for load GVN with dead block (NFC)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Mar 6, 2021
1 parent e6a1044 commit 5f319fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions llvm/test/Transforms/GVN/load-dead-block.ll
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5f319fc

Please sign in to comment.