setOperand of a newly created op in matchAndRewrite

Is it safe to setOperand of a newly created op (which is created by the rewriter) in matchAndRewrite, (and we call rewriter.replaceOp to replace the original op with the new one at the end)? Is it a must to call updateRootInPlace to update operands for the newly created op?