Regarding MIPS PIC code:

Currently the MIPS compiler loads gp at the beginning of a function even if it never needs it.
Similarly it reloads gp after function calls even if it is never used again.

I need to check if in the function there are any variable references using the GOT.

Is there any magic function or variable that will tell me this answer beyond just me going through all the IR for the function?