xref: /aosp_15_r20/external/llvm/test/Transforms/GVN/non-local-offset.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64"
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; GVN should ignore the store to p[1] to see that the load from p[0] is
6*9880d681SAndroid Build Coastguard Worker; fully redundant.
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @yes(
9*9880d681SAndroid Build Coastguard Worker; CHECK: if.then:
10*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 0, i32* %q
11*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Workerdefine void @yes(i1 %c, i32* %p, i32* %q) nounwind {
14*9880d681SAndroid Build Coastguard Workerentry:
15*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %p
16*9880d681SAndroid Build Coastguard Worker  %p1 = getelementptr inbounds i32, i32* %p, i64 1
17*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %p1
18*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %if.else, label %if.then
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Workerif.then:
21*9880d681SAndroid Build Coastguard Worker  %t = load i32, i32* %p
22*9880d681SAndroid Build Coastguard Worker  store i32 %t, i32* %q
23*9880d681SAndroid Build Coastguard Worker  ret void
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Workerif.else:
26*9880d681SAndroid Build Coastguard Worker  ret void
27*9880d681SAndroid Build Coastguard Worker}
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker; GVN should ignore the store to p[1] to see that the first load from p[0] is
30*9880d681SAndroid Build Coastguard Worker; fully redundant. However, the second load is larger, so it's not a simple
31*9880d681SAndroid Build Coastguard Worker; redundancy.
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @watch_out_for_size_change(
34*9880d681SAndroid Build Coastguard Worker; CHECK: if.then:
35*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 0, i32* %q
36*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret void
37*9880d681SAndroid Build Coastguard Worker; CHECK: if.else:
38*9880d681SAndroid Build Coastguard Worker; CHECK: load i64, i64* %pc
39*9880d681SAndroid Build Coastguard Worker; CHECK: store i64
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Workerdefine void @watch_out_for_size_change(i1 %c, i32* %p, i32* %q) nounwind {
42*9880d681SAndroid Build Coastguard Workerentry:
43*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* %p
44*9880d681SAndroid Build Coastguard Worker  %p1 = getelementptr inbounds i32, i32* %p, i64 1
45*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %p1
46*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %if.else, label %if.then
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Workerif.then:
49*9880d681SAndroid Build Coastguard Worker  %t = load i32, i32* %p
50*9880d681SAndroid Build Coastguard Worker  store i32 %t, i32* %q
51*9880d681SAndroid Build Coastguard Worker  ret void
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Workerif.else:
54*9880d681SAndroid Build Coastguard Worker  %pc = bitcast i32* %p to i64*
55*9880d681SAndroid Build Coastguard Worker  %qc = bitcast i32* %q to i64*
56*9880d681SAndroid Build Coastguard Worker  %t64 = load i64, i64* %pc
57*9880d681SAndroid Build Coastguard Worker  store i64 %t64, i64* %qc
58*9880d681SAndroid Build Coastguard Worker  ret void
59*9880d681SAndroid Build Coastguard Worker}
60