diff --git a/mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp b/mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp @@ -552,13 +552,11 @@ /// Determine which OpOperand* will alias with `result` if the op is bufferized /// in place. -/// Return None if the owner of `opOperand` does not have known -/// bufferization aliasing behavior, which indicates that the op must allocate -/// all of its tensor results. /// TODO: in the future this may need to evolve towards a list of OpOperand*. -static Optional getAliasingOpOperand(OpResult result) { +static OpOperand *getAliasingOpOperand(OpResult result) { + // Unknown ops are handled conservatively and never bufferize in-place. if (!hasKnownBufferizationAliasingBehavior(result.getDefiningOp())) - return None; + return nullptr; return TypeSwitch(result.getDefiningOp()) .Case([&](tensor::CastOp op) { return &op->getOpOperand(0); }) .Case([&](ConstantOp op) { return nullptr; }) @@ -1118,9 +1116,8 @@ Operation *candidateOp = mit->v.getDefiningOp(); if (!candidateOp) continue; - auto maybeAliasingOperand = getAliasingOpOperand(mit->v.cast()); - if (!maybeAliasingOperand || !*maybeAliasingOperand || - !bufferizesToMemoryWrite(**maybeAliasingOperand)) + OpOperand *operand = getAliasingOpOperand(mit->v.cast()); + if (!operand || !bufferizesToMemoryWrite(*operand)) continue; LDBG("---->clobbering candidate: " << printOperationInfo(candidateOp) << '\n'); @@ -1406,9 +1403,9 @@ bool skipCopy = false) { OpBuilder::InsertionGuard guard(b); Operation *op = result.getOwner(); - Optional maybeOperand = getAliasingOpOperand(result); + OpOperand *maybeOperand = getAliasingOpOperand(result); assert(maybeOperand && "corresponding OpOperand not found"); - Value operand = (*maybeOperand)->get(); + Value operand = maybeOperand->get(); Value operandBuffer = lookup(bvm, operand); assert(operandBuffer && "operand buffer not found");