Question: How do I show a show home page if a user requests login page with a valid session using spring security?

Answer: 
Checking a variable for logging is perfectly find. Even if the code doesn't get optimised out, checking a boolean condition is almost a no-op and you are very prematurely optimising.

But to answer your question, it probably gets optimised out.
if the statement is unreachable this will always give compile time error..... 

eg. if you use return statemnt b4 any code this will give compile time error.

but if you use this type of code

if(aBoolean){
 //do something
}

these will not be avoided by java or not removed byjava........