Loop invariant values and scalarization overhead

Hi

Recently we have had some discussion about the scalarization overhead and loop invariant values. Before I propose a patch for this I would like to know if this is needed and wanted right now.

Basically, getOperandsScalarizationOverhead() could be improved to check for a loop invariant value, just like it checks for a constant.

In order to do this, I imagine that the Loop* pointer should be passed to that function, so that

bool IsLoopInvariant = (L != nullptr && !L->contains(A));

Just like a constant, this value would never need to be extracted from a vector operand.

This would involve passing the Loop* pointer to many of the TTI cost functions, it seems.

As a good side effect of this is that some cost functions could become loop aware. For instance, on SystemZ a vector permute can be done with a constant mask, which cost is 0 if inside a loop, since it would be hoisted out of the loop. If not in a loop, that instruction should probably also be included in the cost.

Any other related issues?

I don't know if this would mean any improvements right now on benchmarks, but if there is a general agreement that this should be done, I would be happy to do so.

/Jonas