[Binding] Incorrect AffineIfOp condition
Closed this issue · 0 comments
chhzh123 commented
The current make_if
facility in build_ir.py
generates the following code (or similar to this one), which contains explicit comparison and cast operations, and cannot pass the MLIR verification.
#set = affine_set<(d0): (d0 - 1 == 0)>
module {
func @kernel(%A: memref<1024xi32>) -> memref<1024xi32>
{
affine.for %i = 0 to 1024 {
%zero = arith.constant 0 : i32
%ii = arith.index_cast %i : index to i32
%cond = arith.cmpi "sgt", %ii, %zero : i32
%condi = arith.index_cast %cond : i1 to index
affine.if #set(%condi) {
%a = affine.load %A[%i] : memref<1024xi32>
%add = arith.addi %a, %a: i32
affine.store %add, %A[%i] : memref<1024xi32>
}
}
return %A : memref<1024xi32>
}
}
The verifier says
loc("../test/if.mlir":25:13): error: 'affine.if' op operand cannot be used as a dimension id
The correct way should be like
#set = affine_set<(d0): (d0 >= 0)>
module {
func @kernel(%A: memref<1024xi32>) -> memref<1024xi32>
{
affine.for %i = 0 to 1024 {
affine.if #set(%i) {
%a = affine.load %A[%i] : memref<1024xi32>
%add = arith.addi %a, %a: i32
affine.store %add, %A[%i] : memref<1024xi32>
}
}
return %A : memref<1024xi32>
}
}
It needs to directly generate condition expression in the affine_set
.