[Binding] Support for general if condition
Closed this issue · 2 comments
chhzh123 commented
Sometimes we may put array element comparison as the condition of if
operation, but current implementation only allows passing in AffineExpr as condition and generate affine.if
operation, which has big limitations.
Thus, to generate more generalized code, we can use scf.if
as follows.
module {
func @kernel(%A: memref<1024xi32>) -> memref<1024xi32>
{
affine.for %i = 0 to 1024 {
%zero = arith.constant 0 : i32
%load = affine.load %A[%i] : memref<1024xi32>
%cond = arith.cmpi "sgt", %load, %zero : i32
scf.if %cond {
%a = affine.load %A[%i] : memref<1024xi32>
%add = arith.addi %a, %a: i32
affine.store %add, %A[%i] : memref<1024xi32>
}
}
return %A : memref<1024xi32>
}
}
chhzh123 commented
The Python binding of scf.if
has some problems. See the discussion in the LLVM discourse.