You can’t access SSA values outside of the region they are defined. You can either return the value through the if and through the for, or use something like a memref with loads and stores.
These values are conceptually constant variables, so you can’t assign %8 a new value once it has been created. Instead you would create a value %8, then you would create an if/else block that returns either %8 or %24, then you can use the returned value. In this setup, the values are defined only once as required by SSA, and the values are not used outside of the region they are defined in as mentioned by Mehdi.
Thank you very much for your reply. I was trying to say that ‘rev (%8)’ was declared and MLIR allocate a register for it. But inside for and if while I am assigning the ‘AddF’ result to it, it was creating a new register (%24). As you and Tres explained the reason, now I understand the issue and I will work to resolve it.
Thank you very much for your response. You are right, I was confused SSA values and constant op. I was thinking about doing a = a + b. But now I understand that as %8 was declared as constant, I can’t modify it further.
Value res = b.create<arith::MulFOp>(loc, var3, var4);
auto temp = builder.create<memref::LoadOp>(loc, rev, index.getResult());
auto v = b.create<arith::AddFOp>(loc, temp, res);
builder.create<memref::StoreOp>(loc, v.getResult(), rev, index.getResult());