;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2025 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================
;
; REQUIRES: llvm-14-plus
; RUN: igc_opt --opaque-pointers -platformbmg --igc-sink-ptr-const-add -S < %s | FileCheck %s
; ------------------------------------------------
; SinkPointerConstAdd
; ------------------------------------------------
;
; Test checks basic usage of improved clip distance feature

; Function Attrs: alwaysinline null_pointer_is_valid
define void @main(<8 x i32> %r0, i8* %privateBase) #0 {
GlobalScopeInitialization:
  %0 = call i32 @llvm.genx.GenISA.RuntimeValue.i32(i32 6)
  %1 = call i64 @llvm.genx.GenISA.RuntimeValue.i64(i32 2)
  %2 = add i32 %0, 128
  %3 = zext i32 %2 to i64
  br label %secondBB
secondBB:
  %4 = add i64 %1, %3
  %ptr = inttoptr i64 %4 to i32 addrspace(1)*
  ret void

; CHECK:   %0 = call i32 @llvm.genx.GenISA.RuntimeValue.i32(i32 6)
; CHECK-NEXT:   %1 = call i64 @llvm.genx.GenISA.RuntimeValue.i64(i32 2)
; CHECK-NEXT:   %2 = add i32 %0, 128
; CHECK-NEXT:   %3 = zext i32 %2 to i64
; CHECK-NEXT:   br label %secondBB
; CHECK: secondBB:
; CHECK-NEXT:   %4 = add i64 %1, %3
; CHECK-NEXT:   %ptr = inttoptr i64 %4 to ptr addrspace(1)
; CHECK-NEXT:   ret void
}

; Function Attrs: nounwind readnone willreturn
declare i64 @llvm.genx.GenISA.RuntimeValue.i64(i32) #1

; Function Attrs: nounwind readnone willreturn
declare i32 @llvm.genx.GenISA.RuntimeValue.i32(i32) #1

attributes #0 = { alwaysinline null_pointer_is_valid }
attributes #1 = { nounwind readnone willreturn }
attributes #2 = { noduplicate nounwind }


!igc.functions = !{!0}

!0 = !{void (<8 x i32>, i8*)* @main, !1}
!1 = !{!2}
!2 = !{!"function_type", i32 0}
!5 = !{!"argId", i32 0}
!6 = !{!"implicitArgInfoListVec[0]", !5}
!7 = !{!"implicitArgInfoList", !6}
!8 = !{!"FuncMDMap[0]", void (<8 x i32>, i8*)* @main}
!9 = !{!"FuncMDValue[0]", !7}
!10 = !{!"FuncMD", !8, !9}
!11 = !{!"ModuleMD", !10}
!IGCMetadata = !{!11}
