From dc1d07e63dc48e2e3176257ed9b75e736fdb5cc2 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 22 Nov 2026 22:09:42 -0800 Subject: [PATCH] Fixture: kernel_agx_shfl's companions, its inventory rows and its golden printout scripts/regen-air-fixtures compiled kernel_agx_shfl on the M3 (Apple metal 32023.922, SDK 27.2, recorded in TOOLCHAIN as this fixture's toolchain; LLVM 21.1.8): .ll and .air.ll, the calls of the declared agx_shfl renamed to llvm.agx2.shfl, which metal-as declares nounwind speculatable memory(none). bless_engine_inventory adds exactly its four rows (both companions, both entries), each ok on all 15 profiles, and moves no other cell; the air_input bless adds its printout and changes no other (job m3-max-69866). --- .../fixtures/public/engine/TOOLCHAIN | 1 + .../public/engine/kernel_agx_shfl.air.ll | 176 ++++++++++++++++ .../fixtures/public/engine/kernel_agx_shfl.ll | 177 ++++++++++++++++ .../tests/air_input/kernel_agx_shfl.txt | 189 ++++++++++++++++++ .../public_fixture_expectations_engine.tsv | 4 + 5 files changed, 547 insertions(+) create mode 100644 crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.air.ll create mode 100644 crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.ll create mode 100644 crates/metal2vulkan/tests/air_input/kernel_agx_shfl.txt diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN index 9017d88e2..3413d8732 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN +++ b/crates/metal2vulkan-validation/fixtures/public/engine/TOOLCHAIN @@ -195,6 +195,7 @@ fixture icb_vertex_encode_textured: metal: Apple metal version 32023.922 (metalf fixture ido_draw_order: metal: Apple metal version 32023.921 (metalfe-32023.921.6); macosx-sdk: 27.0 (26A425) fixture ipo_primitive_order: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture ipr_reads: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) +fixture kernel_agx_shfl: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture kernel_bit_manipulation: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture kernel_block_read: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) fixture kernel_convert_rounding_modes: metal: Apple metal version 32023.922 (metalfe-32023.922.4); macosx-sdk: 27.2 (26B118) diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.air.ll b/crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.air.ll new file mode 100644 index 000000000..3f3878b01 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.air.ll @@ -0,0 +1,176 @@ +; Generated by scripts/regen-air-fixtures from kernel_agx_shfl.metal (typed pointers; xcrun metal-as reassembles it). Do not edit. +; ModuleID = '-' +source_filename = "-" +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" +target triple = "air64_v28-apple-macosx26.0.0" + +%"struct.metal::_atomic" = type { i32 } + +; Function Attrs: convergent mustprogress nounwind +define void @agx_shfl_pairs(i32 addrspace(1)* nocapture noundef readonly "air-buffer-no-alias" %0, i32 addrspace(1)* nocapture noundef writeonly "air-buffer-no-alias" %1, i32 noundef %2) local_unnamed_addr #0 { + %4 = zext i32 %2 to i64 + %5 = getelementptr inbounds i32, i32 addrspace(1)* %0, i64 %4 + %6 = load i32, i32 addrspace(1)* %5, align 4, !tbaa !26, !alias.scope !30, !noalias !33 + %7 = trunc i32 %6 to i16 + %8 = lshr i32 %6, 16 + %9 = trunc i32 %8 to i16 + %10 = tail call i32 @llvm.agx2.shfl(i16 noundef zeroext %7, i16 noundef zeroext %9) #4 + %11 = getelementptr inbounds i32, i32 addrspace(1)* %1, i64 %4 + store i32 %10, i32 addrspace(1)* %11, align 4, !tbaa !26, !alias.scope !33, !noalias !30 + ret void +} + +; Function Attrs: argmemonly mustprogress nocallback nofree nosync nounwind willreturn +declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 + +; Function Attrs: convergent +declare i32 @llvm.agx2.shfl(i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2 + +; Function Attrs: argmemonly mustprogress nocallback nofree nosync nounwind willreturn +declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 + +; Function Attrs: convergent mustprogress nounwind +define void @agx_shfl_sweep(%"struct.metal::_atomic" addrspace(1)* nocapture noundef "air-buffer-no-alias" %0, i32 noundef %1) local_unnamed_addr #0 { + %3 = alloca [4 x i16], align 2 + %4 = alloca [4 x i16], align 2 + %5 = trunc i32 %1 to i16 + %6 = bitcast [4 x i16]* %3 to i8* + call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %6) #5 + %7 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 0 + store i16 %5, i16* %7, align 2, !tbaa !35 + %8 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 1 + store i16 0, i16* %8, align 2, !tbaa !35 + %9 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 2 + store i16 %5, i16* %9, align 2, !tbaa !35 + %10 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 3 + store i16 %5, i16* %10, align 2, !tbaa !35 + %11 = bitcast [4 x i16]* %4 to i8* + call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %11) #5 + %12 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 0 + store i16 0, i16* %12, align 2, !tbaa !35 + %13 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 1 + store i16 %5, i16* %13, align 2, !tbaa !35 + %14 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 2 + %15 = xor i16 %5, -1 + store i16 %15, i16* %14, align 2, !tbaa !35 + %16 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 3 + %17 = mul i16 %5, -25033 + %18 = add i16 %17, 12345 + store i16 %18, i16* %16, align 2, !tbaa !35 + %19 = shl i32 %1, 2 + br label %27 + +20: ; preds = %55 + %21 = getelementptr inbounds %"struct.metal::_atomic", %"struct.metal::_atomic" addrspace(1)* %0, i64 0, i32 0 + %22 = tail call i32 @air.atomic.global.add.u.i32(i32 addrspace(1)* nocapture %21, i32 %58, i32 0, i32 2, i1 true) #6 + %23 = getelementptr inbounds %"struct.metal::_atomic", %"struct.metal::_atomic" addrspace(1)* %0, i64 1, i32 0 + %24 = tail call i32 @air.atomic.global.add.u.i32(i32 addrspace(1)* nocapture %23, i32 %59, i32 0, i32 2, i1 true) #6 + %25 = getelementptr inbounds %"struct.metal::_atomic", %"struct.metal::_atomic" addrspace(1)* %0, i64 2, i32 0 + %26 = tail call i32 @air.atomic.global.add.u.i32(i32 addrspace(1)* nocapture %25, i32 %63, i32 0, i32 2, i1 true) #6 + call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %11) #5 + call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %6) #5 + ret void + +27: ; preds = %2, %55 + %28 = phi i32 [ 0, %2 ], [ %58, %55 ] + %29 = phi i32 [ 0, %2 ], [ %60, %55 ] + %30 = phi i32 [ 0, %2 ], [ %63, %55 ] + %31 = phi i32 [ 0, %2 ], [ %59, %55 ] + %32 = zext i32 %29 to i64 + %33 = getelementptr inbounds [4 x i16], [4 x i16]* %3, i64 0, i64 %32 + %34 = load i16, i16* %33, align 2, !tbaa !35 + %35 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 %32 + %36 = load i16, i16* %35, align 2, !tbaa !35 + %37 = tail call i32 @llvm.agx2.shfl(i16 noundef zeroext %34, i16 noundef zeroext %36) #4 + %38 = zext i16 %34 to i32 + %39 = zext i16 %36 to i32 + br label %40 + +40: ; preds = %40, %27 + %41 = phi i32 [ 0, %27 ], [ %53, %40 ] + %42 = phi i32 [ 0, %27 ], [ %52, %40 ] + %43 = lshr i32 %38, %41 + %44 = and i32 %43, 1 + %45 = shl nuw nsw i32 %41, 1 + %46 = shl nuw nsw i32 %44, %45 + %47 = or i32 %46, %42 + %48 = lshr i32 %39, %41 + %49 = and i32 %48, 1 + %50 = or i32 %45, 1 + %51 = shl nuw i32 %49, %50 + %52 = or i32 %47, %51 + %53 = add nuw nsw i32 %41, 1 + %54 = icmp eq i32 %53, 16 + br i1 %54, label %55, label %40, !llvm.loop !37 + +55: ; preds = %40 + %56 = icmp ne i32 %37, %52 + %57 = zext i1 %56 to i32 + %58 = add i32 %28, %57 + %59 = add i32 %37, %31 + %60 = add i32 %29, 1 + %61 = add i32 %60, %19 + %62 = mul i32 %37, %61 + %63 = add i32 %62, %30 + %64 = icmp eq i32 %60, 4 + br i1 %64, label %20, label %27, !llvm.loop !39 +} + +; Function Attrs: mustprogress nounwind willreturn +declare i32 @air.atomic.global.add.u.i32(i32 addrspace(1)* nocapture, i32, i32, i32, i1) local_unnamed_addr #3 + +attributes #0 = { convergent mustprogress nounwind "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { argmemonly mustprogress nocallback nofree nosync nounwind willreturn } +attributes #2 = { convergent "approx-func-fp-math"="true" "frame-pointer"="all" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #3 = { mustprogress nounwind willreturn } +attributes #4 = { convergent nobuiltin nounwind "no-builtins" } +attributes #5 = { nounwind } +attributes #6 = { nounwind willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9, !15} +!air.compile_options = !{!20, !21, !22} +!llvm.ident = !{!23} +!air.version = !{!24} +!air.language_version = !{!25} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{void (i32 addrspace(1)*, i32 addrspace(1)*, i32)* @agx_shfl_pairs, !10, !11} +!10 = !{} +!11 = !{!12, !13, !14} +!12 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"in"} +!13 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"out"} +!14 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"i"} +!15 = !{void (%"struct.metal::_atomic" addrspace(1)*, i32)* @agx_shfl_sweep, !10, !16} +!16 = !{!17, !19} +!17 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.struct_type_info", !18, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"metal::_atomic", !"air.arg_name", !"out"} +!18 = !{i32 0, i32 4, i32 0, !"uint", !"__s"} +!19 = !{i32 1, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} +!20 = !{!"air.compile.denorms_disable"} +!21 = !{!"air.compile.fast_math_enable"} +!22 = !{!"air.compile.framebuffer_fetch_enable"} +!23 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!24 = !{i32 2, i32 8, i32 0} +!25 = !{!"Metal", i32 4, i32 0, i32 0} +!26 = !{!27, !27, i64 0} +!27 = !{!"int", !28, i64 0} +!28 = !{!"omnipotent char", !29, i64 0} +!29 = !{!"Simple C++ TBAA"} +!30 = !{!31} +!31 = distinct !{!31, !32, !"air-alias-scope-arg(0)"} +!32 = distinct !{!32, !"air-alias-scopes(agx_shfl_pairs)"} +!33 = !{!34} +!34 = distinct !{!34, !32, !"air-alias-scope-arg(1)"} +!35 = !{!36, !36, i64 0} +!36 = !{!"short", !28, i64 0} +!37 = distinct !{!37, !38} +!38 = !{!"llvm.loop.mustprogress"} +!39 = distinct !{!39, !38} diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.ll b/crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.ll new file mode 100644 index 000000000..3099209cb --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/kernel_agx_shfl.ll @@ -0,0 +1,177 @@ +; Generated by scripts/regen-air-fixtures from kernel_agx_shfl.metal (llvm-dis of kernel_agx_shfl.air). Do not edit. +; ModuleID = '' +source_filename = "-" +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32" +target triple = "air64_v28-apple-macosx26.0.0" + +%"struct.metal::_atomic" = type { i32 } + +; Function Attrs: convergent mustprogress nounwind +define void @agx_shfl_pairs(ptr addrspace(1) noundef readonly captures(none) "air-buffer-no-alias" %0, ptr addrspace(1) noundef writeonly captures(none) "air-buffer-no-alias" %1, i32 noundef %2) local_unnamed_addr #0 { + %4 = zext i32 %2 to i64 + %5 = getelementptr inbounds i32, ptr addrspace(1) %0, i64 %4 + %6 = load i32, ptr addrspace(1) %5, align 4, !tbaa !26, !alias.scope !30, !noalias !33 + %7 = trunc i32 %6 to i16 + %8 = lshr i32 %6, 16 + %9 = trunc i32 %8 to i16 + %10 = tail call i32 @llvm.agx2.shfl(i16 noundef zeroext %7, i16 noundef zeroext %9) #4 + %11 = getelementptr inbounds i32, ptr addrspace(1) %1, i64 %4 + store i32 %10, ptr addrspace(1) %11, align 4, !tbaa !26, !alias.scope !33, !noalias !30 + ret void +} + +; Function Attrs: nounwind speculatable memory(none) +; Unknown intrinsic +declare i32 @llvm.agx2.shfl(i16, i16) local_unnamed_addr #1 + +; Function Attrs: convergent mustprogress nounwind +define void @agx_shfl_sweep(ptr addrspace(1) noundef captures(none) "air-buffer-no-alias" %0, i32 noundef %1) local_unnamed_addr #0 { + %3 = alloca [4 x i16], align 2 + %4 = alloca [4 x i16], align 2 + %5 = trunc i32 %1 to i16 + %6 = bitcast ptr %3 to ptr + call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5 + %7 = getelementptr inbounds [4 x i16], ptr %3, i64 0, i64 0 + store i16 %5, ptr %7, align 2, !tbaa !35 + %8 = getelementptr inbounds [4 x i16], ptr %3, i64 0, i64 1 + store i16 0, ptr %8, align 2, !tbaa !35 + %9 = getelementptr inbounds [4 x i16], ptr %3, i64 0, i64 2 + store i16 %5, ptr %9, align 2, !tbaa !35 + %10 = getelementptr inbounds [4 x i16], ptr %3, i64 0, i64 3 + store i16 %5, ptr %10, align 2, !tbaa !35 + %11 = bitcast ptr %4 to ptr + call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #5 + %12 = getelementptr inbounds [4 x i16], ptr %4, i64 0, i64 0 + store i16 0, ptr %12, align 2, !tbaa !35 + %13 = getelementptr inbounds [4 x i16], ptr %4, i64 0, i64 1 + store i16 %5, ptr %13, align 2, !tbaa !35 + %14 = getelementptr inbounds [4 x i16], ptr %4, i64 0, i64 2 + %15 = xor i16 %5, -1 + store i16 %15, ptr %14, align 2, !tbaa !35 + %16 = getelementptr inbounds [4 x i16], ptr %4, i64 0, i64 3 + %17 = mul i16 %5, -25033 + %18 = add i16 %17, 12345 + store i16 %18, ptr %16, align 2, !tbaa !35 + %19 = shl i32 %1, 2 + br label %27 + +20: ; preds = %55 + %21 = getelementptr inbounds %"struct.metal::_atomic", ptr addrspace(1) %0, i64 0, i32 0 + %22 = tail call i32 @air.atomic.global.add.u.i32(ptr addrspace(1) captures(none) %21, i32 %58, i32 0, i32 2, i1 true) #6 + %23 = getelementptr inbounds %"struct.metal::_atomic", ptr addrspace(1) %0, i64 1, i32 0 + %24 = tail call i32 @air.atomic.global.add.u.i32(ptr addrspace(1) captures(none) %23, i32 %59, i32 0, i32 2, i1 true) #6 + %25 = getelementptr inbounds %"struct.metal::_atomic", ptr addrspace(1) %0, i64 2, i32 0 + %26 = tail call i32 @air.atomic.global.add.u.i32(ptr addrspace(1) captures(none) %25, i32 %63, i32 0, i32 2, i1 true) #6 + call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #5 + call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5 + ret void + +27: ; preds = %55, %2 + %28 = phi i32 [ 0, %2 ], [ %58, %55 ] + %29 = phi i32 [ 0, %2 ], [ %60, %55 ] + %30 = phi i32 [ 0, %2 ], [ %63, %55 ] + %31 = phi i32 [ 0, %2 ], [ %59, %55 ] + %32 = zext i32 %29 to i64 + %33 = getelementptr inbounds [4 x i16], ptr %3, i64 0, i64 %32 + %34 = load i16, ptr %33, align 2, !tbaa !35 + %35 = getelementptr inbounds [4 x i16], ptr %4, i64 0, i64 %32 + %36 = load i16, ptr %35, align 2, !tbaa !35 + %37 = tail call i32 @llvm.agx2.shfl(i16 noundef zeroext %34, i16 noundef zeroext %36) #4 + %38 = zext i16 %34 to i32 + %39 = zext i16 %36 to i32 + br label %40 + +40: ; preds = %40, %27 + %41 = phi i32 [ 0, %27 ], [ %53, %40 ] + %42 = phi i32 [ 0, %27 ], [ %52, %40 ] + %43 = lshr i32 %38, %41 + %44 = and i32 %43, 1 + %45 = shl nuw nsw i32 %41, 1 + %46 = shl nuw nsw i32 %44, %45 + %47 = or i32 %46, %42 + %48 = lshr i32 %39, %41 + %49 = and i32 %48, 1 + %50 = or i32 %45, 1 + %51 = shl nuw i32 %49, %50 + %52 = or i32 %47, %51 + %53 = add nuw nsw i32 %41, 1 + %54 = icmp eq i32 %53, 16 + br i1 %54, label %55, label %40, !llvm.loop !37 + +55: ; preds = %40 + %56 = icmp ne i32 %37, %52 + %57 = zext i1 %56 to i32 + %58 = add i32 %28, %57 + %59 = add i32 %37, %31 + %60 = add i32 %29, 1 + %61 = add i32 %60, %19 + %62 = mul i32 %37, %61 + %63 = add i32 %62, %30 + %64 = icmp eq i32 %60, 4 + br i1 %64, label %20, label %27, !llvm.loop !39 +} + +; Function Attrs: mustprogress nounwind willreturn +declare i32 @air.atomic.global.add.u.i32(ptr addrspace(1) captures(none), i32, i32, i32, i1) local_unnamed_addr #2 + +; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) +declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #3 + +; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) +declare void @llvm.lifetime.end.p0(i64 immarg, ptr captures(none)) #3 + +attributes #0 = { convergent mustprogress nounwind "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" } +attributes #1 = { nounwind speculatable memory(none) } +attributes #2 = { mustprogress nounwind willreturn } +attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) } +attributes #4 = { convergent nobuiltin nounwind "no-builtins" } +attributes #5 = { nounwind } +attributes #6 = { nounwind willreturn } + +!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} +!air.kernel = !{!9, !15} +!air.compile_options = !{!20, !21, !22} +!llvm.ident = !{!23} +!air.version = !{!24} +!air.language_version = !{!25} + +!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 27, i32 2]} +!1 = !{i32 1, !"wchar_size", i32 4} +!2 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 7, !"air.max_device_buffers", i32 31} +!4 = !{i32 7, !"air.max_constant_buffers", i32 31} +!5 = !{i32 7, !"air.max_threadgroup_buffers", i32 31} +!6 = !{i32 7, !"air.max_textures", i32 128} +!7 = !{i32 7, !"air.max_read_write_textures", i32 8} +!8 = !{i32 7, !"air.max_samplers", i32 16} +!9 = !{ptr @agx_shfl_pairs, !10, !11} +!10 = !{} +!11 = !{!12, !13, !14} +!12 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"in"} +!13 = !{i32 1, !"air.buffer", !"air.location_index", i32 1, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"uint", !"air.arg_name", !"out"} +!14 = !{i32 2, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"i"} +!15 = !{ptr @agx_shfl_sweep, !10, !16} +!16 = !{!17, !19} +!17 = !{i32 0, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.struct_type_info", !18, !"air.arg_type_size", i32 4, !"air.arg_type_align_size", i32 4, !"air.arg_type_name", !"metal::_atomic", !"air.arg_name", !"out"} +!18 = !{i32 0, i32 4, i32 0, !"uint", !"__s"} +!19 = !{i32 1, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint", !"air.arg_name", !"t"} +!20 = !{!"air.compile.denorms_disable"} +!21 = !{!"air.compile.fast_math_enable"} +!22 = !{!"air.compile.framebuffer_fetch_enable"} +!23 = !{!"Apple metal version 32023.922 (metalfe-32023.922.4)"} +!24 = !{i32 2, i32 8, i32 0} +!25 = !{!"Metal", i32 4, i32 0, i32 0} +!26 = !{!27, !27, i64 0} +!27 = !{!"int", !28, i64 0} +!28 = !{!"omnipotent char", !29, i64 0} +!29 = !{!"Simple C++ TBAA"} +!30 = !{!31} +!31 = distinct !{!31, !32, !"air-alias-scope-arg(0)"} +!32 = distinct !{!32, !"air-alias-scopes(agx_shfl_pairs)"} +!33 = !{!34} +!34 = distinct !{!34, !32, !"air-alias-scope-arg(1)"} +!35 = !{!36, !36, i64 0} +!36 = !{!"short", !28, i64 0} +!37 = distinct !{!37, !38} +!38 = !{!"llvm.loop.mustprogress"} +!39 = distinct !{!39, !38} diff --git a/crates/metal2vulkan/tests/air_input/kernel_agx_shfl.txt b/crates/metal2vulkan/tests/air_input/kernel_agx_shfl.txt new file mode 100644 index 000000000..154fc2549 --- /dev/null +++ b/crates/metal2vulkan/tests/air_input/kernel_agx_shfl.txt @@ -0,0 +1,189 @@ +target triple = "air64_v28-apple-macosx26.0.0" +source_filename = "-" +; datalayout DataLayout { endian: Little, pointers: {0: PointerSpec { size_bits: 64, abi_bits: 64, pref_bits: 64, index_bits: 64 }}, ints: {1: AlignSpec { abi_bits: 8, pref_bits: 8 }, 8: AlignSpec { abi_bits: 8, pref_bits: 8 }, 16: AlignSpec { abi_bits: 16, pref_bits: 16 }, 32: AlignSpec { abi_bits: 32, pref_bits: 32 }, 64: AlignSpec { abi_bits: 64, pref_bits: 64 }}, floats: {16: AlignSpec { abi_bits: 16, pref_bits: 16 }, 32: AlignSpec { abi_bits: 32, pref_bits: 32 }, 64: AlignSpec { abi_bits: 64, pref_bits: 64 }, 128: AlignSpec { abi_bits: 128, pref_bits: 128 }}, vectors: {16: AlignSpec { abi_bits: 16, pref_bits: 16 }, 24: AlignSpec { abi_bits: 32, pref_bits: 32 }, 32: AlignSpec { abi_bits: 32, pref_bits: 32 }, 48: AlignSpec { abi_bits: 64, pref_bits: 64 }, 64: AlignSpec { abi_bits: 64, pref_bits: 64 }, 96: AlignSpec { abi_bits: 128, pref_bits: 128 }, 128: AlignSpec { abi_bits: 128, pref_bits: 128 }, 192: AlignSpec { abi_bits: 256, pref_bits: 256 }, 256: AlignSpec { abi_bits: 256, pref_bits: 256 }, 512: AlignSpec { abi_bits: 512, pref_bits: 512 }, 1024: AlignSpec { abi_bits: 1024, pref_bits: 1024 }}, aggregate: AlignSpec { abi_bits: 0, pref_bits: 64 }, native_ints: [8, 16, 32], stack_align_bits: None, alloca_space: 0, program_space: 0, globals_space: 0, mangling: None, fn_ptr_align: None, non_integral: [] } +%t4 = type void (ptr addrspace(1), ptr addrspace(1), i32) +%t6 = type i32 (i16, i16) +%t7 = type void (ptr addrspace(1), i32) +%t9 = type i32 (ptr addrspace(1), i32, i32, i32, i1) +%t12 = type [2 x i32] +%t13 = type [4 x i16] +%t15 = type { i32 } ; "struct.metal::_atomic" +c6 = %t12 [27, 2] + +define %t4 @f0 "agx_shfl_pairs" convergent "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins"="" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" %a0( Ref nocapture "air-buffer-no-alias"="" ) %a1( Mod nocapture "air-buffer-no-alias"="" ) { +bb0: + %i0 = zext %a2 to i64 + %i1 = getelementptr inbounds i32, %a0, %i0 + %i2 = load i32, %i1, align 4 + %i3 = trunc %i2 to i16 + %i4 = lshr i32 %i2, i32 16 + %i5 = trunc %i4 to i16 + %i6 = tail call i32 @f1 [llvm Agx(Shfl)](%i3, %i5) convergent "no-builtins"="" + %i7 = getelementptr inbounds i32, %a1, %i0 + store %i6, %i7, align 4 + ret void +} + +declare %t6 @f1 "llvm.agx2.shfl" memory(NoModRef, NoModRef, NoModRef) + +define %t7 @f2 "agx_shfl_sweep" convergent "approx-func-fp-math"="true" "frame-pointer"="all" "min-legal-vector-width"="0" "no-builtins"="" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="true" %a0( nocapture "air-buffer-no-alias"="" ) { +bb0: + %i0 = alloca %t13, i32 1, align 2 + %i1 = alloca %t13, i32 1, align 2 + %i2 = trunc %a1 to i16 + %i3 = bitcast %i0 to ptr addrspace(0) + %i4 = getelementptr inbounds %t13, %i0, i64 0, i64 0 + store %i2, %i4, align 2 + %i6 = getelementptr inbounds %t13, %i0, i64 0, i64 1 + store i16 0, %i6, align 2 + %i8 = getelementptr inbounds %t13, %i0, i64 0, i64 2 + store %i2, %i8, align 2 + %i10 = getelementptr inbounds %t13, %i0, i64 0, i64 3 + store %i2, %i10, align 2 + %i12 = bitcast %i1 to ptr addrspace(0) + %i13 = getelementptr inbounds %t13, %i1, i64 0, i64 0 + store i16 0, %i13, align 2 + %i15 = getelementptr inbounds %t13, %i1, i64 0, i64 1 + store %i2, %i15, align 2 + %i17 = getelementptr inbounds %t13, %i1, i64 0, i64 2 + %i18 = xor i16 %i2, i16 65535 + store %i18, %i17, align 2 + %i20 = getelementptr inbounds %t13, %i1, i64 0, i64 3 + %i21 = mul i16 %i2, i16 40503 + %i22 = add i16 %i21, i16 12345 + store %i22, %i20, align 2 + %i24 = shl i32 %a1, i32 2 + br bb2 +bb1: + %i26 = getelementptr inbounds %t15, %a0, i64 0, i32 0 + %i27 = tail call i32 @f3 [air Atomic(Atomic { space: Global, op: Add, sign: Some(Unsigned), ty: NumTy { elem: I32, lanes: 1 }, order: Relaxed, failure: None, scope: Device, volatile: true, fetch: true, flags: None, stated_volatile: true })](%i26, %i63, i32 0, i32 2, i1 1) arg0( nocapture ) + %i28 = getelementptr inbounds %t15, %a0, i64 1, i32 0 + %i29 = tail call i32 @f3 [air Atomic(Atomic { space: Global, op: Add, sign: Some(Unsigned), ty: NumTy { elem: I32, lanes: 1 }, order: Relaxed, failure: None, scope: Device, volatile: true, fetch: true, flags: None, stated_volatile: true })](%i28, %i64, i32 0, i32 2, i1 1) arg0( nocapture ) + %i30 = getelementptr inbounds %t15, %a0, i64 2, i32 0 + %i31 = tail call i32 @f3 [air Atomic(Atomic { space: Global, op: Add, sign: Some(Unsigned), ty: NumTy { elem: I32, lanes: 1 }, order: Relaxed, failure: None, scope: Device, volatile: true, fetch: true, flags: None, stated_volatile: true })](%i30, %i68, i32 0, i32 2, i1 1) arg0( nocapture ) + ret void +bb2: + %i33 = phi i32 [i32 0, bb0], [%i63, bb4] + %i34 = phi i32 [i32 0, bb0], [%i65, bb4] + %i35 = phi i32 [i32 0, bb0], [%i68, bb4] + %i36 = phi i32 [i32 0, bb0], [%i64, bb4] + %i37 = zext %i34 to i64 + %i38 = getelementptr inbounds %t13, %i0, i64 0, %i37 + %i39 = load i16, %i38, align 2 + %i40 = getelementptr inbounds %t13, %i1, i64 0, %i37 + %i41 = load i16, %i40, align 2 + %i42 = tail call i32 @f1 [llvm Agx(Shfl)](%i39, %i41) convergent "no-builtins"="" + %i43 = zext %i39 to i32 + %i44 = zext %i41 to i32 + br bb3 +bb3: + %i46 = phi i32 [i32 0, bb2], [%i58, bb3] + %i47 = phi i32 [i32 0, bb2], [%i57, bb3] + %i48 = lshr i32 %i43, %i46 + %i49 = and i32 %i48, i32 1 + %i50 = shl nuw nsw i32 %i46, i32 1 + %i51 = shl nuw nsw i32 %i49, %i50 + %i52 = or i32 %i51, %i47 + %i53 = lshr i32 %i44, %i46 + %i54 = and i32 %i53, i32 1 + %i55 = or i32 %i50, i32 1 + %i56 = shl nuw i32 %i54, %i55 + %i57 = or i32 %i52, %i56 + %i58 = add nuw nsw i32 %i46, i32 1 + %i59 = icmp eq %i58, i32 16 + br %i59, bb4, bb3, !llvm.loop LoopHints { unroll: Default, must_progress: true } +bb4: + %i61 = icmp ne %i42, %i57 + %i62 = zext %i61 to i32 + %i63 = add i32 %i33, %i62 + %i64 = add i32 %i42, %i36 + %i65 = add i32 %i34, i32 1 + %i66 = add i32 %i65, %i24 + %i67 = mul i32 %i42, %i66 + %i68 = add i32 %i67, %i35 + %i69 = icmp eq %i65, i32 4 + br %i69, bb1, bb2, !llvm.loop LoopHints { unroll: Default, must_progress: true } +} + +declare %t9 @f3 "air.atomic.global.add.u.i32" %a0( nocapture ) +!md0 = !"SDK Version" +!md1 = !"wchar_size" +!md2 = !"frame-pointer" +!md3 = !"air.max_device_buffers" +!md4 = !"air.max_constant_buffers" +!md5 = !"air.max_threadgroup_buffers" +!md6 = !"air.max_textures" +!md7 = !"air.max_read_write_textures" +!md8 = !"air.max_samplers" +!md9 = !"air.buffer" +!md10 = !"air.location_index" +!md11 = !"air.read" +!md12 = !"air.address_space" +!md13 = !"air.arg_type_size" +!md14 = !"air.arg_type_align_size" +!md15 = !"air.arg_type_name" +!md16 = !"uint" +!md17 = !"air.arg_name" +!md18 = !"in" +!md19 = !"air.read_write" +!md20 = !"out" +!md21 = !"air.thread_position_in_grid" +!md22 = !"i" +!md23 = !"air.struct_type_info" +!md24 = !"__s" +!md25 = !"metal::_atomic" +!md26 = !"t" +!md27 = !"air.compile.denorms_disable" +!md28 = !"air.compile.fast_math_enable" +!md29 = !"air.compile.framebuffer_fetch_enable" +!md30 = !"Apple metal version 32023.922 (metalfe-32023.922.4)" +!md31 = !"Metal" +!md32 = !"omnipotent char" +!md33 = !"Simple C++ TBAA" +!md34 = i32 2 +!md35 = %t12 c6 +!md36 = i32 1 +!md37 = i32 4 +!md38 = i32 7 +!md39 = i32 31 +!md40 = i32 128 +!md41 = i32 8 +!md42 = i32 16 +!md43 = ptr addrspace(0) @f0 +!md44 = i32 0 +!md45 = ptr addrspace(0) @f2 +!md46 = i64 0 +!md47 = !{!md34, !md0, !md35} +!md48 = !{!md36, !md1, !md37} +!md49 = !{!md38, !md2, !md34} +!md50 = !{!md38, !md3, !md39} +!md51 = !{!md38, !md4, !md39} +!md52 = !{!md38, !md5, !md39} +!md53 = !{!md38, !md6, !md40} +!md54 = !{!md38, !md7, !md41} +!md55 = !{!md38, !md8, !md42} +!md56 = !{} +!md57 = !{!md44, !md9, !md10, !md44, !md36, !md11, !md12, !md36, !md13, !md37, !md14, !md37, !md15, !md16, !md17, !md18} +!md58 = !{!md36, !md9, !md10, !md36, !md36, !md19, !md12, !md36, !md13, !md37, !md14, !md37, !md15, !md16, !md17, !md20} +!md59 = !{!md34, !md21, !md15, !md16, !md17, !md22} +!md60 = !{!md57, !md58, !md59} +!md61 = !{!md43, !md56, !md60} +!md62 = !{!md44, !md37, !md44, !md16, !md24} +!md63 = !{!md44, !md9, !md10, !md44, !md36, !md19, !md12, !md36, !md23, !md62, !md13, !md37, !md14, !md37, !md15, !md25, !md17, !md20} +!md64 = !{!md36, !md21, !md15, !md16, !md17, !md26} +!md65 = !{!md63, !md64} +!md66 = !{!md45, !md56, !md65} +!md67 = !{!md27} +!md68 = !{!md28} +!md69 = !{!md29} +!md70 = !{!md30} +!md71 = !{!md34, !md41, !md44} +!md72 = !{!md31, !md37, !md44, !md44} +!md73 = !{!md33} +!md74 = !{!md32, !md73, !md46} +!"llvm.module.flags" = !{!md47, !md48, !md49, !md50, !md51, !md52, !md53, !md54, !md55} +!"air.kernel" = !{!md61, !md66} +!"air.compile_options" = !{!md67, !md68, !md69} +!"llvm.ident" = !{!md70} +!"air.version" = !{!md71} +!"air.language_version" = !{!md72} diff --git a/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv b/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv index a1a9f9d9a..0d615650c 100644 --- a/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv +++ b/crates/metal2vulkan/tests/public_fixture_expectations_engine.tsv @@ -1594,6 +1594,10 @@ engine/k7_tess_triangle_domain.air.ll k7_tess_triangle_domain NeedsInput{VertexD engine/k7_tess_triangle_domain.ll k7_tess_triangle_domain NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} engine/k7_tess_triangle_probe.air.ll k7_tess_triangle_probe NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} engine/k7_tess_triangle_probe.ll k7_tess_triangle_probe NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} NeedsInput{VertexDescriptor { attribute: 0 }} +engine/kernel_agx_shfl.air.ll agx_shfl_pairs ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/kernel_agx_shfl.air.ll agx_shfl_sweep ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/kernel_agx_shfl.ll agx_shfl_pairs ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok +engine/kernel_agx_shfl.ll agx_shfl_sweep ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/kernel_bit_manipulation.air.ll bit_ops ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/kernel_bit_manipulation.ll bit_ops ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok engine/kernel_block_read.air.ll br_2x1 ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok