; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2026 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================

; RUN: igc_opt -resolve-image-implicit-args-for-bindless --opaque-pointers -S %s | FileCheck %s

target triple = "spir64-unknown-unknown"

%spirv.Sampler = type opaque


define spir_func void @test_width(i64 %bindless_img) {
; CHECK-LABEL: @test_width(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 8, i32 8, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_width(i64 %bindless_img)
  ret void
}

define spir_func void @test_height(i64 %bindless_img) {
; CHECK-LABEL: @test_height(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 16, i32 8, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_height(i64 %bindless_img)
  ret void
}

define spir_func void @test_depth(i64 %bindless_img) {
; CHECK-LABEL: @test_depth(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 24, i32 8, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_depth(i64 %bindless_img)
  ret void
}

define spir_func void @test_mip_levels(i64 %bindless_img) {
; CHECK-LABEL: @test_mip_levels(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 52, i32 4, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_num_mip_levels(i64 %bindless_img)
  ret void
}

define spir_func void @test_channel_data_type(i64 %bindless_img) {
; CHECK-LABEL: @test_channel_data_type(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 44, i32 4, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_channel_data_type(i64 %bindless_img)
  ret void
}

define spir_func void @test_channel_order(i64 %bindless_img) {
; CHECK-LABEL: @test_channel_order(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 48, i32 4, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_channel_order(i64 %bindless_img)
  ret void
}

define spir_func void @test_1d_array_size(i64 %bindless_img) {
; CHECK-LABEL: @test_1d_array_size(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 32, i32 8, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image1d_array_size(i64 %bindless_img)
  ret void
}

define spir_func void @test_2d_array_size(i64 %bindless_img) {
; CHECK-LABEL: @test_2d_array_size(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 32, i32 8, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image2d_array_size(i64 %bindless_img)
  ret void
}

define spir_func void @test_num_samples(i64 %bindless_img) {
; CHECK-LABEL: @test_num_samples(
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[BINDLESS_IMG:%.*]], 64
; CHECK-NEXT:    [[IMAGEIMPLICITARGS:%.*]] = inttoptr i64 [[TMP1]] to ptr addrspace(393468)
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @llvm.genx.GenISA.ldraw.indexed.i32.p393468(ptr addrspace(393468) [[IMAGEIMPLICITARGS]], i32 40, i32 4, i1 false)
; CHECK-NEXT:    ret void
;
  %1 = call i32 @__builtin_IB_get_image_num_samples(i64 %bindless_img)
  ret void
}

declare spir_func i32 @__builtin_IB_get_image_width(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image_height(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image_depth(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image_num_mip_levels(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image_channel_data_type(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image_channel_order(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image1d_array_size(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image2d_array_size(i64 noundef) local_unnamed_addr
declare spir_func i32 @__builtin_IB_get_image_num_samples(i64 noundef) local_unnamed_addr

!IGCMetadata = !{!0}

!0 = !{!"ModuleMD", !1, !2}
!1 = !{!"UseBindlessImage", i1 true}
!2 = !{!"extensions", !3}
!3 = !{!"spvINTELBindlessImages", i1 true}
