Loop peeling is currently performed as part of UnrollLoop(). The whole setup is somewhat odd, here is my current understanding of the situation:
- Outside test scenarios, peeling will always be performed as part of an unroll with Count=1: https://github.com/llvm/llvm-project/blob/ffb48d48e45c72ed81dda4983ccb06e800cdbbd0/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L873-L879
- Of course, unrolling with count one does not do a great deal. My deduced reason for doing this is to run simplifyLoopAfterUnroll(), without which many tests indeed fail.
- When testing, it's possible to specify both -unroll-peel-count and -unroll-count, in which case both peeling and unrolling will be performed. However, if you actually try to do this, you apparently run into this miscompile: https://bugs.llvm.org/show_bug.cgi?id=45939 / D80080
Based on that reasoning (and suggested by @efriedma on the referenced review) I've moved the peeling code out of UnrollLoop() into tryToUnrollLoop(). An error is thrown if a test explicitly requests to perform both peeling and unrolling.
TBH the way peeling is implemented has left me very confused, so I'm not sure I'm doing the right thing here.
In the future, we really should pull out a function with the other loop simplification, and use that here, but that's for the future.