For loops: pre-calculating upper bound

When optimizing code I regularly come to the following conclusion:

Dim ub As Integer = CalculateUpperBoundMethod() For i As Integer = 0 To ub
is slower than

For i As Integer = 0 To CalculateUpperBoundMethod()

This didn’t use to be that way with earlier versions (pre 2015 or so). Is this due to the LLVM compiler?

Another thing which seems to have changed is calling a method to get the array for a For…Each loop at the top of the loop:

Dim mis() As Xojo.Core.MethodInfo = ti.MethodInfo() For Each mi As Xojo.Core.MethodInfo In mis
is slower than

For Each mi As Xojo.Core.MethodInfo In ti.MethodInfo()

Does the parser or the LLVM compiler optimize this by recognizing that the array doesn’t change within the loop and therefore ti.MethodInfo() needs to get called only once?

Actually, the LLVM compiler could probably precalculate and be faster.

If you are talking about 32 bit, I am surprised of the changes you describe. AFAIK the upper bound has always been evaluated at each round. And BTW LLVM is used only for 64 bit.

Would you have a test project handy ?