Adding a new result to an operation without creating the operation again

Community,

I have faced this situation where I would like to add a new result (similar to an input operand) to an operation without creating a new operation using builder? For, e.g., consider the following loop.

%final = affine.for %i1 = 0 to 100 iter_arg(%sum=%initial) β†’ (i32) {
%sum_updated = std.add %sum, 1 : i32
affine.yield %sum_updated
}

Let us say that I have a handler to the above for-loop, and now I would like to add a new result (e.g., multiply) to the for-loop without creating the for-op again.

%final,%mul_final = affine.for %i1 = 0 to 100 iter_arg(%sum=%initial, %mul=%initial) β†’ (i32, i32) {
%sum_updated = std.add %sum, 1 : i32
%mul_updated = std.mul %mul, 2 : i32
affine.yield %sum_updated, %mul_updated
}

I looked at the AffineFor op, base class Operation – I see methods to insertOperands, but I don’t see methods to add results to the operation. Is it fundamentally prohibited as per the design principles, or is there a workaround without creating the for-op, adding new result, and then cloning the entire loop body?

Thanks,
Prasanth

I faced a similar situation recently, and concluded there was no way to add new results to an operation. If there is a neat way to do this, I’m all ears, but in my case I created a new operation with all the result types.

It is not possible to change the number of results of an operation. You’ll need to create a new operation for that.

– River

1 Like

Thanks @mikeurbach and @River707 for the quick replies!