[GPU] Fix integer reduction identities at the element bit width (#25176)

The reduction helper builds integer min/max identities from fixed
`int64_t` limits and uses `1` for AND. Those values can change meaning
when converted to a narrower type. The shared signed/unsigned cases also
give the wrong identities for unsigned `i64` reductions.

This patch builds the identities with `APInt` at the element's bit width
and gives signed and unsigned min/max their own cases. Unsigned minimum
and AND use all ones; unsigned maximum uses zero. The floating-point
cases and index-attribute storage width stay unchanged.

Fixes #25153.

The added cases live in the existing common and AMD wide-shuffle tests.
They cover `i8`, `i16`, `i32`, and `i64`, and check that the reduction
actually uses the expected constant. The existing scan, mask, and
argcompare checks pass too.

Assisted-by: OpenAI Codex

Signed-off-by: Demetrios Agourakis <demetrios@agourakis.med.br>
diff --git a/compiler/src/iree/compiler/Codegen/Common/GPU/test/gpu_nested_layout_vector_distribution_multi_reduce.mlir b/compiler/src/iree/compiler/Codegen/Common/GPU/test/gpu_nested_layout_vector_distribution_multi_reduce.mlir
index d2310a9..c4aa37b 100644
--- a/compiler/src/iree/compiler/Codegen/Common/GPU/test/gpu_nested_layout_vector_distribution_multi_reduce.mlir
+++ b/compiler/src/iree/compiler/Codegen/Common/GPU/test/gpu_nested_layout_vector_distribution_multi_reduce.mlir
@@ -312,3 +312,378 @@
 // enough threads on the reduction dimension to do a subgroup reduce.
 // CHECK: vector.transfer_read %{{.*}}[%{{.*}}, %[[C0]]]
 // CHECK-NOT: gpu.subgroup_reduce
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxsi_i8
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-128> : vector<2x1x1xi8>
+// CHECK: vector.multi_reduction <maxsi>, {{.*}}, [[IDENTITY]]
+func.func @maxsi_i8(%arg0: vector<32x32xi8>, %arg1: vector<32xi8>) -> vector<32xi8> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi8>
+  %0 = vector.multi_reduction <maxsi>, %arg0l, %arg1 [1] : vector<32x32xi8> to vector<32xi8>
+  return %0 : vector<32xi8>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minsi_i8
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<127> : vector<2x1x1xi8>
+// CHECK: vector.multi_reduction <minsi>, {{.*}}, [[IDENTITY]]
+func.func @minsi_i8(%arg0: vector<32x32xi8>, %arg1: vector<32xi8>) -> vector<32xi8> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi8>
+  %0 = vector.multi_reduction <minsi>, %arg0l, %arg1 [1] : vector<32x32xi8> to vector<32xi8>
+  return %0 : vector<32xi8>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxui_i8
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<0> : vector<2x1x1xi8>
+// CHECK: vector.multi_reduction <maxui>, {{.*}}, [[IDENTITY]]
+func.func @maxui_i8(%arg0: vector<32x32xi8>, %arg1: vector<32xi8>) -> vector<32xi8> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi8>
+  %0 = vector.multi_reduction <maxui>, %arg0l, %arg1 [1] : vector<32x32xi8> to vector<32xi8>
+  return %0 : vector<32xi8>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minui_i8
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi8>
+// CHECK: vector.multi_reduction <minui>, {{.*}}, [[IDENTITY]]
+func.func @minui_i8(%arg0: vector<32x32xi8>, %arg1: vector<32xi8>) -> vector<32xi8> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi8>
+  %0 = vector.multi_reduction <minui>, %arg0l, %arg1 [1] : vector<32x32xi8> to vector<32xi8>
+  return %0 : vector<32xi8>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @and_i8
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi8>
+// CHECK: vector.multi_reduction <and>, {{.*}}, [[IDENTITY]]
+func.func @and_i8(%arg0: vector<32x32xi8>, %arg1: vector<32xi8>) -> vector<32xi8> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi8>
+  %0 = vector.multi_reduction <and>, %arg0l, %arg1 [1] : vector<32x32xi8> to vector<32xi8>
+  return %0 : vector<32xi8>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxsi_i16
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-32768> : vector<2x1x1xi16>
+// CHECK: vector.multi_reduction <maxsi>, {{.*}}, [[IDENTITY]]
+func.func @maxsi_i16(%arg0: vector<32x32xi16>, %arg1: vector<32xi16>) -> vector<32xi16> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi16>
+  %0 = vector.multi_reduction <maxsi>, %arg0l, %arg1 [1] : vector<32x32xi16> to vector<32xi16>
+  return %0 : vector<32xi16>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minsi_i16
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<32767> : vector<2x1x1xi16>
+// CHECK: vector.multi_reduction <minsi>, {{.*}}, [[IDENTITY]]
+func.func @minsi_i16(%arg0: vector<32x32xi16>, %arg1: vector<32xi16>) -> vector<32xi16> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi16>
+  %0 = vector.multi_reduction <minsi>, %arg0l, %arg1 [1] : vector<32x32xi16> to vector<32xi16>
+  return %0 : vector<32xi16>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxui_i16
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<0> : vector<2x1x1xi16>
+// CHECK: vector.multi_reduction <maxui>, {{.*}}, [[IDENTITY]]
+func.func @maxui_i16(%arg0: vector<32x32xi16>, %arg1: vector<32xi16>) -> vector<32xi16> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi16>
+  %0 = vector.multi_reduction <maxui>, %arg0l, %arg1 [1] : vector<32x32xi16> to vector<32xi16>
+  return %0 : vector<32xi16>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minui_i16
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi16>
+// CHECK: vector.multi_reduction <minui>, {{.*}}, [[IDENTITY]]
+func.func @minui_i16(%arg0: vector<32x32xi16>, %arg1: vector<32xi16>) -> vector<32xi16> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi16>
+  %0 = vector.multi_reduction <minui>, %arg0l, %arg1 [1] : vector<32x32xi16> to vector<32xi16>
+  return %0 : vector<32xi16>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @and_i16
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi16>
+// CHECK: vector.multi_reduction <and>, {{.*}}, [[IDENTITY]]
+func.func @and_i16(%arg0: vector<32x32xi16>, %arg1: vector<32xi16>) -> vector<32xi16> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi16>
+  %0 = vector.multi_reduction <and>, %arg0l, %arg1 [1] : vector<32x32xi16> to vector<32xi16>
+  return %0 : vector<32xi16>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxsi_i32
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-2147483648> : vector<2x1x1xi32>
+// CHECK: vector.multi_reduction <maxsi>, {{.*}}, [[IDENTITY]]
+func.func @maxsi_i32(%arg0: vector<32x32xi32>, %arg1: vector<32xi32>) -> vector<32xi32> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi32>
+  %0 = vector.multi_reduction <maxsi>, %arg0l, %arg1 [1] : vector<32x32xi32> to vector<32xi32>
+  return %0 : vector<32xi32>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minsi_i32
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<2147483647> : vector<2x1x1xi32>
+// CHECK: vector.multi_reduction <minsi>, {{.*}}, [[IDENTITY]]
+func.func @minsi_i32(%arg0: vector<32x32xi32>, %arg1: vector<32xi32>) -> vector<32xi32> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi32>
+  %0 = vector.multi_reduction <minsi>, %arg0l, %arg1 [1] : vector<32x32xi32> to vector<32xi32>
+  return %0 : vector<32xi32>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxui_i32
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<0> : vector<2x1x1xi32>
+// CHECK: vector.multi_reduction <maxui>, {{.*}}, [[IDENTITY]]
+func.func @maxui_i32(%arg0: vector<32x32xi32>, %arg1: vector<32xi32>) -> vector<32xi32> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi32>
+  %0 = vector.multi_reduction <maxui>, %arg0l, %arg1 [1] : vector<32x32xi32> to vector<32xi32>
+  return %0 : vector<32xi32>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minui_i32
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi32>
+// CHECK: vector.multi_reduction <minui>, {{.*}}, [[IDENTITY]]
+func.func @minui_i32(%arg0: vector<32x32xi32>, %arg1: vector<32xi32>) -> vector<32xi32> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi32>
+  %0 = vector.multi_reduction <minui>, %arg0l, %arg1 [1] : vector<32x32xi32> to vector<32xi32>
+  return %0 : vector<32xi32>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @and_i32
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi32>
+// CHECK: vector.multi_reduction <and>, {{.*}}, [[IDENTITY]]
+func.func @and_i32(%arg0: vector<32x32xi32>, %arg1: vector<32xi32>) -> vector<32xi32> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi32>
+  %0 = vector.multi_reduction <and>, %arg0l, %arg1 [1] : vector<32x32xi32> to vector<32xi32>
+  return %0 : vector<32xi32>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
diff --git a/compiler/src/iree/compiler/Codegen/LLVMGPU/test/ROCDL/gpu_nested_layout_vector_distribution_wide_shuffle.mlir b/compiler/src/iree/compiler/Codegen/LLVMGPU/test/ROCDL/gpu_nested_layout_vector_distribution_wide_shuffle.mlir
index d87e7b0..4f86049 100644
--- a/compiler/src/iree/compiler/Codegen/LLVMGPU/test/ROCDL/gpu_nested_layout_vector_distribution_wide_shuffle.mlir
+++ b/compiler/src/iree/compiler/Codegen/LLVMGPU/test/ROCDL/gpu_nested_layout_vector_distribution_wide_shuffle.mlir
@@ -210,3 +210,128 @@
 
 // CHECK: vector.scan
 // CHECK-NOT: iree_gpu.subgroup_scan
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxsi_i64
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-9223372036854775808> : vector<2x1x1xi64>
+// CHECK: vector.multi_reduction <maxsi>, {{.*}}, [[IDENTITY]]
+func.func @maxsi_i64(%arg0: vector<32x32xi64>, %arg1: vector<32xi64>) -> vector<32xi64> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi64>
+  %0 = vector.multi_reduction <maxsi>, %arg0l, %arg1 [1] : vector<32x32xi64> to vector<32xi64>
+  return %0 : vector<32xi64>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minsi_i64
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<9223372036854775807> : vector<2x1x1xi64>
+// CHECK: vector.multi_reduction <minsi>, {{.*}}, [[IDENTITY]]
+func.func @minsi_i64(%arg0: vector<32x32xi64>, %arg1: vector<32xi64>) -> vector<32xi64> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi64>
+  %0 = vector.multi_reduction <minsi>, %arg0l, %arg1 [1] : vector<32x32xi64> to vector<32xi64>
+  return %0 : vector<32xi64>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @maxui_i64
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<0> : vector<2x1x1xi64>
+// CHECK: vector.multi_reduction <maxui>, {{.*}}, [[IDENTITY]]
+func.func @maxui_i64(%arg0: vector<32x32xi64>, %arg1: vector<32xi64>) -> vector<32xi64> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi64>
+  %0 = vector.multi_reduction <maxui>, %arg0l, %arg1 [1] : vector<32x32xi64> to vector<32xi64>
+  return %0 : vector<32xi64>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @minui_i64
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi64>
+// CHECK: vector.multi_reduction <minui>, {{.*}}, [[IDENTITY]]
+func.func @minui_i64(%arg0: vector<32x32xi64>, %arg1: vector<32xi64>) -> vector<32xi64> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi64>
+  %0 = vector.multi_reduction <minui>, %arg0l, %arg1 [1] : vector<32x32xi64> to vector<32xi64>
+  return %0 : vector<32xi64>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
+
+// -----
+
+#nested = #iree_vector_ext.nested_layout<
+  subgroup_tile = [1, 1], batch_tile = [2, 2],
+  outer_tile = [1, 1], thread_tile = [16, 4],
+  element_tile = [1, 4], subgroup_strides = [1, 1],
+  thread_strides = [1, 16]>
+
+// CHECK-LABEL: func @and_i64
+// CHECK: [[IDENTITY:%.*]] = arith.constant dense<-1> : vector<2x1x1xi64>
+// CHECK: vector.multi_reduction <and>, {{.*}}, [[IDENTITY]]
+func.func @and_i64(%arg0: vector<32x32xi64>, %arg1: vector<32xi64>) -> vector<32xi64> {
+  %arg0l = iree_vector_ext.to_layout %arg0 to layout(#nested) : vector<32x32xi64>
+  %0 = vector.multi_reduction <and>, %arg0l, %arg1 [1] : vector<32x32xi64> to vector<32xi64>
+  return %0 : vector<32xi64>
+}
+
+builtin.module attributes { transform.with_named_sequence } {
+  transform.named_sequence @__transform_main(%variant_op: !transform.any_op {transform.readonly}) {
+    %func = transform.structured.match ops{["func.func"]} in %variant_op : (!transform.any_op) -> !transform.any_op
+    transform.iree.test_gpu_vector_distribution %func : !transform.any_op
+    transform.yield
+  }
+}
diff --git a/compiler/src/iree/compiler/Codegen/Utils/GPUUtils.cpp b/compiler/src/iree/compiler/Codegen/Utils/GPUUtils.cpp
index 1e539bc..e539fd5 100644
--- a/compiler/src/iree/compiler/Codegen/Utils/GPUUtils.cpp
+++ b/compiler/src/iree/compiler/Codegen/Utils/GPUUtils.cpp
@@ -12,6 +12,7 @@
 #include "iree/compiler/Codegen/Utils/MarkerUtils.h"
 #include "iree/compiler/Codegen/Utils/Utils.h"
 #include "iree/compiler/Dialect/HAL/IR/HALTypes.h"
+#include "llvm/ADT/APInt.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DebugLog.h"
@@ -526,6 +527,10 @@
 static TypedAttr getCombiningKindIdentity(OpBuilder &builder,
                                           vector::CombiningKind combiningKind,
                                           Type type) {
+  auto getIntegerBitWidth = [type]() {
+    return type.isIndex() ? IndexType::kInternalStorageBitWidth
+                          : cast<IntegerType>(type).getWidth();
+  };
   switch (combiningKind) {
   case vector::CombiningKind::ADD:
     return builder.getZeroAttr(type);
@@ -536,13 +541,17 @@
     return builder.getFloatAttr(type, 1);
   }
   case vector::CombiningKind::MINUI:
-  case vector::CombiningKind::MINSI:
-    return builder.getIntegerAttr(type, std::numeric_limits<int64_t>::max());
-  case vector::CombiningKind::MAXUI:
-  case vector::CombiningKind::MAXSI:
-    return builder.getIntegerAttr(type, std::numeric_limits<int64_t>::min());
   case vector::CombiningKind::AND:
-    return builder.getIntegerAttr(type, 1);
+    return builder.getIntegerAttr(type,
+                                  APInt::getAllOnes(getIntegerBitWidth()));
+  case vector::CombiningKind::MINSI:
+    return builder.getIntegerAttr(
+        type, APInt::getSignedMaxValue(getIntegerBitWidth()));
+  case vector::CombiningKind::MAXUI:
+    return builder.getZeroAttr(type);
+  case vector::CombiningKind::MAXSI:
+    return builder.getIntegerAttr(
+        type, APInt::getSignedMinValue(getIntegerBitWidth()));
   case vector::CombiningKind::OR:
   case vector::CombiningKind::XOR:
     return builder.getZeroAttr(type);