AffineCFG: MoveSIToFPToAffine causes infinite loop when sitofp operand is a valid symbol in scope
help wanted
The `MoveSIToFPToAffine` pattern in the `affine-cfg` pass enters an infinite loop when the `arith.sitofp` operand is an arithmetic op (`arith.muli`) defined outside the affine loop, making it already a valid symbol in the affine scope.
The minimal reproducible example is:
```
// RUN: enzymexlamlir-opt --affine-cfg %s
func.func @repro(%arg0: i32, %arg1: i32) -> f64 {
%cst = arith.constant 0.0 : f64
%res = affine.for %iv = 0 to 10 iter_args(%acc = %cst) -> (f64) {
%mul = arith.muli %arg0, %arg1 : i32
%fp = arith.sitofp %mul : i32 to f64
%add = arith.addf %acc, %fp : f64
affine.yield %add : f64
}
return %res : f64
}
```
I was thought pre-decompose the top-level arithmetic op in MoveSIToFPToAffine before calling fully2ComposeAffineMapAndOperands. For example, decompose `muli(%arg0, %arg1)` into `map = ()[s0, s1] -> (s0 * s1)`, `operands = {%arg0, %arg1}` instead of `map = ()[s0] -> (s0)`, `operands = {muli}`. This produces a non-identity `affine.apply` that won't be folded, breaking the cycle. However, this duplicates logic already present in `AffineApplyNormalizer`.
Could anyone suggest a better solution?
3 条评论