1 ; Test if the !invariant.load metadata is maintained by GVN.
2 ; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
4 define i32 @test1(i32* nocapture %p, i8* nocapture %q) {
6 ; CHECK: %x = load i32* %p, align 4, !invariant.load !0
9 %x = load i32* %p, align 4, !invariant.load !0
10 %conv = trunc i32 %x to i8
11 store i8 %conv, i8* %q, align 1
12 %y = load i32* %p, align 4, !invariant.load !0
17 define i32 @test2(i32* nocapture %p, i8* nocapture %q) {
19 ; CHECK-NOT: !invariant.load
20 ; CHECK-NOT: %y = load
22 %x = load i32* %p, align 4
23 %conv = trunc i32 %x to i8
24 store i8 %conv, i8* %q, align 1
25 %y = load i32* %p, align 4, !invariant.load !0
30 ; With the invariant.load metadata, what would otherwise
31 ; be a case for PRE becomes a full redundancy.
32 define i32 @test3(i1 %cnd, i32* %p, i32* %q) {
37 br i1 %cnd, label %bb1, label %bb2
44 %v2 = load i32* %p, !invariant.load !0
45 %res = sub i32 %v1, %v2
49 ; This test is here to document a case which doesn't optimize
50 ; as well as it could.
51 define i32 @test4(i1 %cnd, i32* %p, i32* %q) {
53 ; %v2 is redundant, but GVN currently doesn't catch that
55 %v1 = load i32* %p, !invariant.load !0
56 br i1 %cnd, label %bb1, label %bb2
64 %res = sub i32 %v1, %v2