Are you getting any codes on the check engine light?
I had virtually the same issue on my 2006 M6, mine wouldnt rev past ~4500 while riding without stumble and backfire. Got intermittent codes, seemed like timing was way off. Showed 95 ohms on crank sensor whether at ECU plug or sensor plug, indicating harness wires OK. Changed crank sensor anyway, didn't help. Then swapped in a different ECU, same stumble with codes flashing now and then. Stator resistance values all seem within spec. Injectors same, in-spec. Power valves cleaned and cables adjusted. Tail-light wiring ok. Switches Ok, Headlights worked. So I pulled airbox, intake boots to check reed valves and injectors, all looked fine. Wondered if other issues such as bad TPS, Coil, etc. might cause problems... BUT finally changed the Exhaust Temp Sensor and everything seems right - power is there, no codes!!
Good luck!!