How must a subsidy received for an investment be treated in calculating internal rate of return (IRR): by lowering the amount of the investment or by lowering the average cost of project financing? Should IRR be compared to the average cost of company financing or to the average cost of financing for the project at hand?

A subsidy must be deducted from the amount of the investment, thus reducing the initial outlay, rather than lowering the cost of capital, for three reasons:
1) IRR measures the return on capital committed by investors, both shareholders and creditors. If some of the resources are contributed by public authorities in the form of subsidies, that is that much less capital committed by private-sector partners. It is therefore justified to reduce the amount of investment before calculating IRR.
2) Lowering the required rate of return on an asset to reflect the subsidy can create the impression that the investment has been reduced by the subsidy, whereas it has lowered just the initial disbursement, with no change to the risk on future cash flow. But, in fact, the required rate of return is correlated solely to the asset's level of risk;
3) It's easier to calculate that way! For the same conclusion: to invest or not to invest.

The internal rate of return on the investment, minus the subsidy, is to be compared with the company's weighted average cost of capital (assuming that the project presents the same risk as the company's current risk level). Indeed, it is a mistake to compare the IRR of this investment with the cost of financing arranged for the project. It is the overall cost and not the marginal cost that must serve as a basis.
If the company takes on additional debt at an after-tax rate of 5%, for example, to finance a new investment, this debt must not merely pay 5%-plus to be acceptable, as the company was only able to raise debt at 5% because it had a level of equity (which, in theory, serves as a guarantee to bankers, who otherwise would have charged a higher rate of interest), which must be compensated accordingly. The return on the investment must therefore cover the cost of debt, as ell as the cost of equity, i.e., the weighted average cost of capital. And it is with that that the IRR of the investment must be compared.
If the project now presents a different level of risk than the company, a higher level, say, then a higher returned must be required than the company's cost of capital. This reflects a greater risk, which, if the investment is made, will increase the required rate of return of investors in the company, as its risk profile is now greater.