EnzymeAD / EnzymeAD/Enzyme-JAX
Missing canonicalizations (during canonicalize-scf-for)
- Dominant language
- MLIR
- Stars
- 131
- Forks
- 53
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 193
Description
```mlir
func.func @w2f(%arg0: i32) -> (i32, f32) {
%0 = ub.poison : i1
%false = arith.constant false
%cst = arith.constant 0.000000e+00 : f32
%cst_0 = arith.constant 1.000000e+00 : f32
%c0_i32 = arith.constant 0 : i32
%c1_i32 = arith.constant 1 : i32
%true = arith.constant true
%1 = ub.poison : i32
%2 = ub.poison : f32
%3:6 = scf.for %arg1 = %c0_i32 to %arg0 step %c1_i32 iter_args(%arg2 = %c0_i32, %arg3 = %cst, %arg4 = %true, %arg5 = %1, %arg6 = %2, %arg7 = %true) -> (i32, f32, i1, i32, f32, i1) : i32 {
%4:3 = scf.if %arg7 -> (i32, f32, i1) {
scf.yield %arg2, %arg3, %arg4 : i32, f32, i1
} else {
scf.yield %arg5, %arg6, %false : i32, f32, i1
}
%5 = arith.cmpi slt, %arg1, %arg0 : i32
%6 = arith.andi %5, %4#2 : i1
%7:3 = scf.if %6 -> (i32, f32, i1) {
%8 = "test.something"() : () -> i1
%9 = arith.addf %4#1, %cst_0 : f32
%10 = arith.addi %4#0, %c1_i32 : i32
scf.yield %10, %9, %8 : i32, f32, i1
} else {
scf.yield %1, %2, %0 : i32, f32, i1
}
scf.yield %7#0, %7#1, %7#2, %arg2, %arg3, %4#2 : i32, f32, i1, i32, f32, i1
}
return %3#3, %3#4 : i32, f32
}
```
pattern1:
```
if A {
B
} else {
false
}
->
A & B
```
pattern2:
an induction var whose only use is being and'd against another induction var can be replaced with a new induction var where the and happens before the loop, and before the yield (if the two inputs are both constants, or the same, this is beneficial), akin to rotation
pattern3:
if a result of an if is used in another if whose and is dependant on the same cond var, we can assume it comes from the same true side
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.