EnzymeAD / EnzymeAD/Enzyme-JAX
maxi related simplifications
Open
Nobody has claimed this yet.
- Dominant language
- MLIR
- Stars
- 133
- Forks
- 53
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 193
Description
we should be able to get rid of most of the maxsi and even possibly if's here:
%83 = "enzymexla.gpu_wrapper"(%78, %79, %c1, %c32, %c32, %c1) ({
%85 = affine.load %memref_16[] : memref<i32, 1>
%86 = affine.load %memref_13[] : memref<i32, 1>
%87 = affine.load %memref_10[] : memref<f64, 1>
%88 = affine.load %memref_7[] : memref<i32, 1>
%89 = affine.load %memref_5[] : memref<i32, 1>
%90 = arith.index_cast %85 : i32 to index
%91 = arith.index_cast %86 : i32 to index
scf.parallel (%arg6, %arg7) = (%c0, %c0) to (%91, %90) step (%c1, %c1) {
%alloca_19 = memref.alloca() : memref<32x32xf64>
%92 = "enzymexla.memref2pointer"(%alloca_19) : (memref<32x32xf64>) -> !llvm.ptr<3>
%alloca_20 = memref.alloca() : memref<32x32xf64>
%93 = "enzymexla.memref2pointer"(%alloca_20) : (memref<32x32xf64>) -> !llvm.ptr<3>
affine.parallel (%arg8, %arg9) = (0, 0) to (32, 32) {
%94 = arith.index_castui %arg6 : index to i32
%95 = arith.index_castui %arg7 : index to i32
%96 = arith.index_castui %arg8 : index to i32
%97 = arith.index_castui %arg9 : index to i32
%98 = arith.shli %95, %c5_i32 : i32
%99 = arith.addi %98, %97 : i32
%100 = arith.shli %94, %c5_i32 : i32
%101 = arith.addi %100, %96 : i32
%102 = arith.cmpi sgt, %89, %c0_i32 : i32
%103 = scf.if %102 -> (f64) {
%107 = arith.addi %89, %c31_i32 : i32
%108 = arith.shrui %107, %c5_i32 : i32
%109 = arith.cmpi slt, %99, %88 : i32
%110 = arith.muli %89, %99 : i32
%111 = arith.cmpi slt, %101, %88 : i32
%112 = arith.maxsi %108, %c1_i32 : i32
%113 = arith.maxsi %112, %c1_i32 : i32
%114 = arith.addi %113, %c1_i32 : i32
%115:2 = scf.for %arg10 = %c1_i32 to %114 step %c1_i32 iter_args(%arg11 = %cst_2, %arg12 = %1) -> (f64, f64) : i32 {
%116 = arith.subi %arg10, %c1_i32 : i32
%117 = arith.shli %116, %c5_i32 : i32
%118 = arith.addi %117, %96 : i32
%119 = arith.cmpi slt, %118, %89 : i32
%120 = arith.andi %119, %109 : i1
scf.if %120 {
%125 = arith.index_cast %117 : i32 to index
%126 = arith.index_cast %110 : i32 to index
%127 = arith.addi %arg8, %126 : index
%128 = arith.addi %127, %125 : index
%129 = memref.load %80[%128] {alignment = 8 : i64, ordering = 0 : i64, tbaa = [#llvm.tbaa_tag<base_type = <id = "double", members = {<#llvm.tbaa_type_desc<id = "omnipotent char", members = {<#llvm.tbaa_root<id = "Simple C++ TBAA">, 0>}>, 0>}>, access_type = <id = "double", members = {<#llvm.tbaa_type_desc<id = "omnipotent char", members = {<#llvm.tbaa_root<id = "Simple C++ TBAA">, 0>}>, 0>}>, offset = 0>]} : memref<?xf64>
%130 = "enzymexla.pointer2memref"(%92) : (!llvm.ptr<3>) -> memref<?xf64, 3>
affine.store %129, %130[%arg9 * 32 + %arg8] : memref<?xf64, 3>
} else {
%125 = "enzymexla.pointer2memref"(%92) : (!llvm.ptr<3>) -> memref<?xf64, 3>
affine.store %cst_2, %125[%arg9 * 32 + %arg8] : memref<?xf64, 3>
}
%121 = arith.addi %117, %97 : i32
%122 = arith.cmpi slt, %121, %89 : i32
%123 = arith.andi %122, %111 : i1
scf.if %123 {
%125 = arith.muli %121, %88 : i32
%126 = arith.index_cast %125 : i32 to index
%127 = arith.index_cast %100 : i32 to index
%128 = arith.addi %arg8, %127 : index
%129 = arith.addi %128, %126 : index
%130 = memref.load %81[%129] {alignment = 8 : i64, ordering = 0 : i64, tbaa = [#llvm.tbaa_tag<base_type = <id = "double", members = {<#llvm.tbaa_type_desc<id = "omnipotent char", members = {<#llvm.tbaa_root<id = "Simple C++ TBAA">, 0>}>, 0>}>, access_type = <id = "double", members = {<#llvm.tbaa_type_desc<id = "omnipotent char", members = {<#llvm.tbaa_root<id = "Simple C++ TBAA">, 0>}>, 0>}>, offset = 0>]} : memref<?xf64>
%131 = "enzymexla.pointer2memref"(%93) : (!llvm.ptr<3>) -> memref<?xf64, 3>
affine.store %130, %131[%arg9 * 32 + %arg8] : memref<?xf64, 3>
} else {
%125 = "enzymexla.pointer2memref"(%93) : (!llvm.ptr<3>) -> memref<?xf64, 3>
affine.store %cst_2, %125[%arg9 * 32 + %arg8] : memref<?xf64, 3>
}
"enzymexla.barrier"(%arg8, %arg9, %c0) : (index, index, index) -> ()
%124:2 = affine.for %arg13 = 0 to 32 iter_args(%arg14 = %arg11, %arg15 = %1) -> (f64, f64) {
%125 = "enzymexla.pointer2memref"(%92) : (!llvm.ptr<3>) -> memref<?xf64, 3>
%126 = affine.load %125[%arg9 * 32 + %arg13] : memref<?xf64, 3>
%127 = "enzymexla.pointer2memref"(%93) : (!llvm.ptr<3>) -> memref<?xf64, 3>
%128 = affine.load %127[%arg13 * 32 + %arg8] : memref<?xf64, 3>
%129 = arith.mulf %126, %128 {fastmathFlags = #llvm.fastmath<contract>} : f64
%130 = arith.addf %arg14, %129 {fastmathFlags = #llvm.fastmath<contract>} : f64
affine.yield %130, %130 : f64, f64
}
"enzymexla.barrier"(%arg8, %arg9, %c0) : (index, index, index) -> ()
scf.yield %124#1, %124#1 : f64, f64
}
scf.yield %115#1 : f64
} else {
scf.yield %cst_2 : f64
}
"enzymexla.barrier"(%arg8, %arg9, %c0) : (index, index, index) -> ()
%104 = arith.cmpi slt, %99, %88 : i32
%105 = arith.cmpi slt, %101, %88 : i32
%106 = arith.andi %104, %105 : i1
scf.if %106 {
%107 = arith.mulf %87, %103 {fastmathFlags = #llvm.fastmath<contract>} : f64
%108 = arith.muli %88, %99 : i32
%109 = arith.index_cast %108 : i32 to index
%110 = arith.index_cast %100 : i32 to index
%111 = arith.addi %arg8, %110 : index
%112 = arith.addi %111, %109 : index
%113 = memref.load %82[%112] {alignment = 8 : i64, ordering = 0 : i64, tbaa = [#llvm.tbaa_tag<base_type = <id = "double", members = {<#llvm.tbaa_type_desc<id = "omnipotent char", members = {<#llvm.tbaa_root<id = "Simple C++ TBAA">, 0>}>, 0>}>, access_type = <id = "double", members = {<#llvm.tbaa_type_desc<id = "omnipotent char", members = {<#llvm.tbaa_root<id = "Simple C++ TBAA">, 0>}>, 0>}>, offset = 0>]} : memref<?xf64>
%114 = arith.addf %107, %113 {fastmathFlags = #llvm.fastmath<contract>} : f64
%115 = arith.index_cast %108 : i32 to index
%116 = arith.index_cast %100 : i32 to index
%117 = arith.index_cast %96 : i32 to index
%118 = arith.addi %116, %117 : index
%119 = arith.addi %115, %118 : index
memref.store %114, %82[%119] : memref<?xf64>
}
}
scf.reduce
}
"enzymexla.polygeist_yield"() : () -> ()
}) : (index, index, index, index, index, index) -> index
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or entry point is named; the issue contains only a generated MLIR snippet. Start by locating the code that emits the shown arith.maxsi and scf.if pattern, then establish how to validate simplifications without changing the loop behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100