XC16 Compiler Warnings: "Optimization may eliminate reads and/or writes to register variables"
This is a warning and not an error. The message indicates the internal register usage when used as volatile variables. The compiler's optimization may insert code, which prevents atomic access to these registers (i.e., it may take more time than expected to access these registers).
You can suppress warnings by unchecking the Additional Warnings checkbox under:
Project Properties > xc16-gcc > Option Categories = Preprocessing and messages > Additional Warnings