Files
TheRock/compiler/amd-llvm/mlir/test/Dialect/Affine/decompose-affine-ops.mlir
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

151 lines
7.2 KiB
MLIR

// RUN: mlir-opt %s -allow-unregistered-dialect -test-decompose-affine-ops -split-input-file -loop-invariant-code-motion -cse | FileCheck %s
// CHECK-DAG: #[[$c42:.*]] = affine_map<() -> (42)>
// CHECK-DAG: #[[$div32mod4:.*]] = affine_map<()[s0] -> ((s0 floordiv 32) mod 4)>
// CHECK-DAG: #[[$add:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>
// CHECK-LABEL: func.func @simple_test_1
// CHECK-SAME: %[[I0:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[I1:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[I2:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[LB:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[UB:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[STEP:[0-9a-zA-Z]+]]: index
func.func @simple_test_1(%0: index, %1: index, %2: index, %lb: index, %ub: index, %step: index) {
// CHECK: %[[c42:.*]] = affine.apply #[[$c42]]()
// CHECK: %[[R1:.*]] = affine.apply #[[$div32mod4]]()[%[[I1]]]
// CHECK: %[[a:.*]] = affine.apply #[[$add]]()[%[[c42]], %[[R1]]]
%a = affine.apply affine_map<(d0) -> ((d0 floordiv 32) mod 4 + 42)>(%1)
// CHECK: "some_side_effecting_consumer"(%[[a]]) : (index) -> ()
"some_side_effecting_consumer"(%a) : (index) -> ()
return
}
// -----
// CHECK-DAG: #[[$c42:.*]] = affine_map<() -> (42)>
// CHECK-DAG: #[[$id:.*]] = affine_map<()[s0] -> (s0)>
// CHECK-DAG: #[[$add:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>
// CHECK-DAG: #[[$div32mod4:.*]] = affine_map<()[s0] -> ((s0 floordiv 32) mod 4)>
// CHECK-LABEL: func.func @simple_test_2
// CHECK-SAME: %[[I0:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[I1:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[I2:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[LB:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[UB:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[STEP:[0-9a-zA-Z]+]]: index
func.func @simple_test_2(%0: index, %1: index, %2: index, %lb: index, %ub: index, %step: index) {
// CHECK: %[[c42:.*]] = affine.apply #[[$c42]]()
// CHECK: scf.for %[[i:.*]] =
scf.for %i = %lb to %ub step %step {
// CHECK: %[[R1:.*]] = affine.apply #[[$id]]()[%[[i]]]
// CHECK: %[[R2:.*]] = affine.apply #[[$add]]()[%[[c42]], %[[R1]]]
// CHECK: scf.for %[[j:.*]] =
scf.for %j = %lb to %ub step %step {
// CHECK: %[[R3:.*]] = affine.apply #[[$div32mod4]]()[%[[j]]]
// CHECK: %[[a:.*]] = affine.apply #[[$add]]()[%[[R2]], %[[R3]]]
%a = affine.apply affine_map<(d0)[s0] -> ((d0 floordiv 32) mod 4 + s0 + 42)>(%j)[%i]
// CHECK: "some_side_effecting_consumer"(%[[a]]) : (index) -> ()
"some_side_effecting_consumer"(%a) : (index) -> ()
}
}
return
}
// -----
// CHECK-DAG: #[[$div4:.*]] = affine_map<()[s0] -> (s0 floordiv 4)>
// CHECK-DAG: #[[$times32:.*]] = affine_map<()[s0] -> (s0 * 32)>
// CHECK-DAG: #[[$times16:.*]] = affine_map<()[s0] -> (s0 * 16)>
// CHECK-DAG: #[[$add:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>
// CHECK-DAG: #[[$div4timesm32:.*]] = affine_map<()[s0] -> ((s0 floordiv 4) * -32)>
// CHECK-DAG: #[[$times8:.*]] = affine_map<()[s0] -> (s0 * 8)>
// CHECK-DAG: #[[$id:.*]] = affine_map<()[s0] -> (s0)>
// CHECK-DAG: #[[$div32mod4:.*]] = affine_map<()[s0] -> ((s0 floordiv 32) mod 4)>
// CHECK-LABEL: func.func @larger_test
// CHECK-SAME: %[[I0:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[I1:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[I2:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[LB:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[UB:[0-9a-zA-Z]+]]: index,
// CHECK-SAME: %[[STEP:[0-9a-zA-Z]+]]: index
func.func @larger_test(%0: index, %1: index, %2: index, %lb: index, %ub: index, %step: index) {
%c2 = arith.constant 2 : index
%c6 = arith.constant 6 : index
// CHECK: %[[R0:.*]] = affine.apply #[[$div4]]()[%[[I0]]]
// CHECK-NEXT: %[[R1:.*]] = affine.apply #[[$times16]]()[%[[I1]]]
// CHECK-NEXT: %[[R2:.*]] = affine.apply #[[$add]]()[%[[R0]], %[[R1]]]
// CHECK-NEXT: %[[R3:.*]] = affine.apply #[[$times32]]()[%[[I2]]]
// I1 * 16 + I2 * 32 + I0 floordiv 4
// CHECK-NEXT: %[[b:.*]] = affine.apply #[[$add]]()[%[[R2]], %[[R3]]]
// (I0 floordiv 4) * 32
// CHECK-NEXT: %[[R5:.*]] = affine.apply #[[$div4timesm32]]()[%[[I0]]]
// 8 * I0
// CHECK-NEXT: %[[R6:.*]] = affine.apply #[[$times8]]()[%[[I0]]]
// 8 * I0 + (I0 floordiv 4) * 32
// CHECK-NEXT: %[[c:.*]] = affine.apply #[[$add]]()[%[[R5]], %[[R6]]]
// CHECK-NEXT: scf.for %[[i:.*]] =
scf.for %i = %lb to %ub step %step {
// remainder from %a not hoisted above %i.
// CHECK-NEXT: %[[R8:.*]] = affine.apply #[[$times32]]()[%[[i]]]
// CHECK-NEXT: %[[a:.*]] = affine.apply #[[$add]]()[%[[b]], %[[R8]]]
// CHECK-NEXT: scf.for %[[j:.*]] =
scf.for %j = %lb to %ub step %step {
// Gets hoisted partially to i and rest outermost.
// The hoisted part is %b.
%a = affine.apply affine_map<()[s0, s1, s2, s3] -> (s1 * 16 + s2 * 32 + s3 * 32 + s0 floordiv 4)>()[%0, %1, %2, %i]
// Gets completely hoisted
%b = affine.apply affine_map<()[s0, s1, s2] -> (s1 * 16 + s2 * 32 + s0 floordiv 4)>()[%0, %1, %2]
// Gets completely hoisted
%c = affine.apply affine_map<()[s0] -> (s0 * 8 - (s0 floordiv 4) * 32)>()[%0]
// 32 * %j + %c remains here, the rest is hoisted.
// CHECK-DAG: %[[R10:.*]] = affine.apply #[[$times32]]()[%[[j]]]
// CHECK-DAG: %[[d:.*]] = affine.apply #[[$add]]()[%[[c]], %[[R10]]]
%d = affine.apply affine_map<()[s0, s1] -> (s0 * 8 + s1 * 32 - (s0 floordiv 4) * 32)>()[%0, %j]
// CHECK-DAG: %[[idj:.*]] = affine.apply #[[$id]]()[%[[j]]]
// CHECK-NEXT: scf.for %[[k:.*]] =
scf.for %k = %lb to %ub step %step {
// CHECK-NEXT: %[[idk:.*]] = affine.apply #[[$id]]()[%[[k]]]
// CHECK-NEXT: %[[e:.*]] = affine.apply #[[$add]]()[%[[c]], %[[idk]]]
%e = affine.apply affine_map<()[s0, s1] -> (s0 + s1 * 8 - (s1 floordiv 4) * 32)>()[%k, %0]
// CHECK-NEXT: %[[R15:.*]] = affine.apply #[[$div32mod4]]()[%[[k]]]
// CHECK-NEXT: %[[f:.*]] = affine.apply #[[$add]]()[%[[idj]], %[[R15]]]
%f = affine.apply affine_map<(d0)[s0] -> ((d0 floordiv 32) mod 4 + s0)>(%k)[%j]
// CHECK-NEXT: %[[g:.*]] = affine.apply #[[$add]]()[%[[b]], %[[idk]]]
%g = affine.apply affine_map<()[s0, s1, s2, s3] -> (s0 + s2 * 16 + s3 * 32 + s1 floordiv 4)>()[%k, %0, %1, %2]
// CHECK-NEXT: "some_side_effecting_consumer"(%[[a]]) : (index) -> ()
"some_side_effecting_consumer"(%a) : (index) -> ()
// CHECK-NEXT: "some_side_effecting_consumer"(%[[b]]) : (index) -> ()
"some_side_effecting_consumer"(%b) : (index) -> ()
// CHECK-NEXT: "some_side_effecting_consumer"(%[[c]]) : (index) -> ()
"some_side_effecting_consumer"(%c) : (index) -> ()
// CHECK-NEXT: "some_side_effecting_consumer"(%[[d]]) : (index) -> ()
"some_side_effecting_consumer"(%d) : (index) -> ()
// CHECK-NEXT: "some_side_effecting_consumer"(%[[e]]) : (index) -> ()
"some_side_effecting_consumer"(%e) : (index) -> ()
// CHECK-NEXT: "some_side_effecting_consumer"(%[[f]]) : (index) -> ()
"some_side_effecting_consumer"(%f) : (index) -> ()
// CHECK-NEXT: "some_side_effecting_consumer"(%[[g]]) : (index) -> ()
"some_side_effecting_consumer"(%g) : (index) -> ()
}
}
}
return
}