Bug in ComputeSpeculationCost in SimplifyCFG?

I am trying to understand the cost returned by ComputeSpeculationCost function in SimplifyCFG. It appears even when it returns TCC_Expensive (which means “prohibitively expensive”), the caller may proceed with a transform, because TCC_Expensive is not really a high cost, but its value is 4.

For example when DominatesMergePoint calls this, it may still move ahead because TCC_Expensive cost may be less than CostRemaining. Looking thru the history, it appears this behavior changed with r228826 (http://llvm.org/viewvc/llvm-project?view=revision&revision=228826), when this API was moved to use TargetTransformInfo for cost analysis instead of the hard-coded cost estimates.

Is this a bug?

Thanks,

Gautam

It looks dubious, yes… although I’m not sure it’s actually possible to cause issues in practice with the default thresholds. Patch welcome. -Eli