IMO when user provide unroll pragma, compiler should always respect it.
It is not clear to me why loop unroll pass currently ensure that the unrolled loop size is limited by PragmaUnrollThreshold.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
Added some reviewers for discussion.
The max unroll threshold for pragmas was already present from the very beginning: rGff9032459976cf309eda7a12a4b9c2deb4fb9d2b
I think the limit is there just to prevent the compiler from exploding. If you try to unroll too much, you're going to end up with effectively infinite compile time and/or run out of memory.
I would expect it's unlikely to trigger the limit in practice; do you have a practical case where it matters?
We had a change to make certain kinds of instructions return InstructionCost::getMax() from getUserCost(), as we want to prevent optimizations like unrolling to happen for loops containing those instructions. (It is reverted.)
We were surprised to see that loops with user pragma were also affected. IMO it is user's responsibility to put pragmas that make sense.
IIUC if there is user pragma, we should always respect it. I don't feel too strongly about it, I mostly want to understand what's the level we want to respect user pragma to.
PragmaUnrollThreshold has other uses; are you intentionally leaving those alone?
I'm not confident it makes sense to "respect the user" here; nobody really benefits from crashing the compiler. But I don't have a strong preference here; "#pragma unroll" is rare enough that I don't expect much practical impact either way.
Yes, it is still possible that shouldPragmaUnroll returns None, e.g., when (UP.AllowRemainder || (TripMultiple % PInfo.PragmaCount == 0)) is false.
And we want to be more aggressive with unrolling limits when given an unrolling pragma.
// If the loop has an unrolling pragma, we want to be more aggressive with // unrolling limits. Set thresholds to at least the PragmaUnrollThreshold // value which is larger than the default limits.
Thanks for your input.
Oh, I see, you still want to use the PragmaUnrollThreshold limit if the user tries to full-unroll a loop that can't be fully unrolled, or something like that. That makes sense.