xref: /llvm-project/llvm/test/Analysis/ValueTracking/gep-negative-issue.ll (revision 7fbbbfd63899331a47a0265c45f1a2a2ae6918d4)
1; RUN: opt -passes=gvn -S < %s | FileCheck %s
2target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-p100:128:64:64-p101:128:64:64"
3target triple = "x86_64-unknown-linux-gnu"
4
5%ArrayImpl = type { i64, ptr addrspace(100), [1 x i64], [1 x i64], [1 x i64], i64, i64, ptr addrspace(100), ptr addrspace(100), i8, i64 }
6%_array = type { i64, ptr addrspace(100), i8 }
7
8define void @test(i64 %n_chpl) {
9entry:
10  ; First section is some code
11  %0 = getelementptr inbounds %_array, ptr null, i32 0, i32 1
12  %1 = load ptr addrspace(100), ptr %0
13  %2 = getelementptr inbounds %ArrayImpl, ptr addrspace(100) %1, i32 0, i32 8
14  %3 = load ptr addrspace(100), ptr addrspace(100) %2
15  %4 = getelementptr inbounds double, ptr addrspace(100) %3, i64 -1
16  ; Second section is that code repeated
17  %x0 = getelementptr inbounds %_array, ptr null, i32 0, i32 1
18  %x1 = load ptr addrspace(100), ptr %x0
19  %x2 = getelementptr inbounds %ArrayImpl, ptr addrspace(100) %x1, i32 0, i32 8
20  %x3 = load ptr addrspace(100), ptr addrspace(100) %x2
21  %x4 = getelementptr inbounds double, ptr addrspace(100) %x3, i64 -1
22  ; These two stores refer to the same memory location
23  ; Even so, they are expected to remain separate stores here
24  store double 0.000000e+00, ptr addrspace(100) %4
25  store double 0.000000e+00, ptr addrspace(100) %x4
26  ; Third section is the repeated code again, with a later store
27  ; This third section is necessary to trigger the crash
28  %y1 = load ptr addrspace(100), ptr %0
29  %y2 = getelementptr inbounds %ArrayImpl, ptr addrspace(100) %y1, i32 0, i32 8
30  %y3 = load ptr addrspace(100), ptr addrspace(100) %y2
31  %y4 = getelementptr inbounds double, ptr addrspace(100) %y3, i64 -1
32  store double 0.000000e+00, ptr addrspace(100) %y4
33  ret void
34; CHECK-LABEL: define void @test
35; CHECK: getelementptr inbounds double, ptr addrspace(100) {{%.*}}, i64 -1
36; CHECK-NEXT: store double 0.000000e+00, ptr addrspace(100) [[DST:%.*]]
37; CHECK-NEXT: store double 0.000000e+00, ptr addrspace(100) [[DST]]
38; CHECK: load
39; CHECK: getelementptr inbounds %ArrayImpl, ptr addrspace(100)
40; CHECK: load
41; CHECK: getelementptr inbounds double, ptr addrspace(100) {{%.*}}, i64 -1
42; CHECK: store double 0.000000e+00, ptr addrspace(100)
43; CHECK: ret
44}
45