llvm/llvm/test/CodeGen/BPF/addr-space-simplify-4.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt -passes=bpf-aspace-simplify -mtriple=bpf-pc-linux -S < %s | FileCheck %s

; Check that bpf-aspace-simplify pass simplifies chain
; 'cast K->M -> cast M->N -> GEP -> cast N->M -> cast M->K'.

define dso_local ptr addrspace(2) @test (ptr addrspace(2) %p) {
; CHECK-LABEL: define dso_local ptr addrspace(2) @test(
; CHECK-SAME: ptr addrspace(2) [[P:%.*]]) {
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[C12:%.*]] = getelementptr inbounds i8, ptr addrspace(2) [[P]], i64 8
; CHECK-NEXT:    ret ptr addrspace(2) [[C12]]
;
  entry:
  %a = addrspacecast ptr addrspace(2) %p to ptr addrspace(1)
  %b = addrspacecast ptr addrspace(1) %a to ptr
  %c = getelementptr inbounds i8, ptr %b, i64 8
  %d = addrspacecast ptr %c to ptr addrspace(1)
  %e = addrspacecast ptr addrspace (1) %d to ptr addrspace(2)
  ret ptr addrspace(2) %e
}