Rotate on exit that actually exits the current loop.
I found this by looking this nested loop. When loop@Depth3 is processed, BB#193 is the exiting block. And when loop@Depth2 is processed, the loop is rotated w.r.t BB#193 because PreferredLoopExit is not cleared. Should not we clear PreferredLoopExit every time we process a new loop ?
BB#193: derived from LLVM BB %cleanup.i.i781
Live Ins: %RAX %RBP %RBX %RSI %R9 %R10 %R11 %R13 %R14 %R15 Predecessors according to CFG: BB#192 %RBX<def,tied1> = ADD64ri8 %RBX<kill,tied0>, 8, %EFLAGS<imp-def,dead> %RBP<def,tied1> = ADD64ri8 %RBP<kill,tied0>, 8, %EFLAGS<imp-def,dead> CMP64rr %RBX, %R15, %EFLAGS<imp-def> JB_1 <BB#192>, %EFLAGS<imp-use> JMP_1 <BB#174> Successors according to CFG: BB#192(0x7fef9fcb / 0x80000000 = 99.95%) BB#174(0x00106035 / 0x80000000 = 0.05%)
Loop at depth 2 containing: BB#191<header>,BB#192,BB#182,BB#193,BB#174,BB#175,BB#176,BB#177,BB#178,BB#179,BB#180,BB#181,BB#183,BB#187<exiting>,BB#184,BB#185,BB#186<exiting>,BB#188<exiting>,BB#189<exiting>,BB#190<latch>
Loop at depth 3 containing: BB#192<header><exiting>,BB#193<latch><exiting>