GLSL Compilers

If we have varyings which are being assigned value by some calculation in VS and are being passed to FS, but not used in FS, does the optimization pass takes care of it? Or it assigns the memory and performs the interpolation too?

Is it specific to GPU? how about Mali and Adreno?

It is likely that unnecessary code will be eliminated, and (unless you’re using separable programs) the determination will be made for the program as a whole, not just individual shaders. But it’s not required; §7.3.1 of the OpenGL 4.5 specification says:

Resources referenced in shader code are considered active unless the compiler and linker can conclusively determine that they have no observable effect on the results produced by the executable code of the program. For example, variables might be considered inactive if they are declared but not used in executable code, used only in a clause of an if statement that would never be executed, used only in functions that are never called, or used only in computations of temporary variables having no effect on any shader output. In cases where the compiler or linker cannot make a conclusive determination, any resource referenced by shader code will be considered active. The set of active resources for any interface is implementation-dependent because it depends on various analysis and optimizations performed by the compiler and linker.

I guess that, in order to ensure this, you can follow the steps given in this thread.
You’ll have to understand the output assembly however and as stated in the thread, outputs will be dependent on the driver.

On AMD devices, you can try this tool.