First off: the only way to answer performance question is to measure it. Try it yourself and you'll find out.
As for what the compiler does: I remind you that "if" is just a conditional goto. When you have
if (x)
Y();
else
Z();
Q();
the compiler generates that as either:
evaluate x
branch to LABEL1 if result was false
call Y
branch to LABEL2
LABEL1:
call Z
LABEL2:
call Q
or
evaluate !x
branch to LABEL1 if result was true
depending on whether it is easier to generate the code to elicit the "normal" or "inverted" result for whatever "x" happens to be. For example, if you have if (a<=b)
it might be easier to generate it as (if !(a>b))
. Or vice versa; it depends on the details of the exact code being compiled.
Regardless, I suspect you have bigger fish to fry. If you care about performance, use a profiler and find the slowest thing and then fix that. It makes no sense whatsoever to be worried about nanosecond optimizations when you probably are wasting entire milliseconds somewhere else in your program.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…