xref: /llvm-project/llvm/test/CodeGen/BPF/addr-space-simplify-3.ll (revision 2aacb56e8361213c1bd69c2ceafdea3aa0ca9125)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2; RUN: opt -passes=bpf-aspace-simplify -mtriple=bpf-pc-linux -S < %s | FileCheck %s
3
4; Check that when bpf-aspace-simplify pass modifies chain
5; 'cast M->N -> GEP -> cast N->M' it does not remove GEP,
6; when that GEP is used by some other instruction.
7
8define dso_local ptr addrspace(1) @test (ptr addrspace(1) %p) {
9; CHECK-LABEL: define dso_local ptr addrspace(1) @test(
10; CHECK-SAME: ptr addrspace(1) [[P:%.*]]) {
11; CHECK-NEXT:  entry:
12; CHECK-NEXT:    [[A:%.*]] = addrspacecast ptr addrspace(1) [[P]] to ptr
13; CHECK-NEXT:    [[B:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 8
14; CHECK-NEXT:    [[B1:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[P]], i64 8
15; CHECK-NEXT:    call void @sink(ptr [[B]])
16; CHECK-NEXT:    ret ptr addrspace(1) [[B1]]
17;
18  entry:
19  %a = addrspacecast ptr addrspace(1) %p to ptr
20  %b = getelementptr inbounds i8, ptr %a, i64 8
21  %c = addrspacecast ptr %b to ptr addrspace(1)
22  call void @sink(ptr %b)
23  ret ptr addrspace(1) %c
24}
25
26declare dso_local void @sink(ptr)
27