in reply to Compiler Optimization
I would think it would Optimize away the else, would it even optimize away the if? How can I see what is happening?
No, it isn't optimised away:
C:\test>perl -MO=Deparse if ($var || 2) { # do stuff here } else { # won't do stuff } ^Z if ($var or 2) { (); } else { (); } - syntax OK
Why not? Because (for example) $var might be a tied variable; which means that just referencing it could have (required) side-effects. Else why would the programmer have coded it that way.
O=Deparse only deparses and doesn't actually compile the code, right?
How could it deparse it before it had been compiled?
This shows that if the compiler can optimise the code, the Deparse output will reflect that:
C:\test>perl -MO=Deparse if( 2 ) { } else { } ^Z do { () }; - syntax OK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Compiler Optimization
by syphilis (Archbishop) on Feb 25, 2015 at 00:22 UTC | |
by BrowserUk (Patriarch) on Feb 25, 2015 at 01:49 UTC | |
by syphilis (Archbishop) on Feb 25, 2015 at 02:29 UTC | |
by BrowserUk (Patriarch) on Feb 25, 2015 at 02:42 UTC | |
by LanX (Saint) on Feb 25, 2015 at 02:17 UTC |