[Proposal] Introducing the concept of invalid costs to the IR cost model

Makes sense. I personally greatly prefer having a type rather than a static constexpr int CostUnfathomable = 10000.

I think the type should have arithmetic operators defined such that an “invalid cost” on either side results in an invalid cost (similar to how NaN infects floats), and an implicit conversion that constructs a valid cost. Then I could just do:


Cost c = 7;

// c is a valid cost of 7 here

c = c + someFuncThatReturnsInvalidCost();

Cost d = 2 + c;

// d and c are both invalid costs here

This way, basically no existing code has to change. I’m actually a little disappointed that llvm::Optional doesn’t already have this behavior (with arithmetic operators guarded by enable_if).

Thanks,

Christopher Tetreault