Why do compilers remove dead code? (Why is it worth it?)











up vote
-2
down vote

favorite












By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).



I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.



Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.



Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)



P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.










share|improve this question


















  • 2




    If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
    – Ryan Pierce Williams
    Nov 11 at 11:20












  • @RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
    – v6ak
    Nov 11 at 11:27






  • 1




    it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
    – hanshenrik
    Nov 11 at 11:28










  • @v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
    – Ryan Pierce Williams
    Nov 11 at 11:29






  • 1




    @hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
    – Hadi Brais
    Nov 13 at 0:01















up vote
-2
down vote

favorite












By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).



I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.



Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.



Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)



P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.










share|improve this question


















  • 2




    If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
    – Ryan Pierce Williams
    Nov 11 at 11:20












  • @RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
    – v6ak
    Nov 11 at 11:27






  • 1




    it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
    – hanshenrik
    Nov 11 at 11:28










  • @v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
    – Ryan Pierce Williams
    Nov 11 at 11:29






  • 1




    @hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
    – Hadi Brais
    Nov 13 at 0:01













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).



I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.



Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.



Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)



P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.










share|improve this question













By dead code, I mean some reachable code that has no impact of the result (except time or space requirements).



I understand that dead code elimination might improve app performance. I can understand even some theoretical examples. But even after considering inlining, it looks like this should be rarely an issue. Overall, it looks like there is much effort for something with a little effect. It suggests using such an effort for some other optimizations could bring more value.



Maybe I have overseen some reason why dead code occurs and maybe someone will be able to show realistic examples of dead code.



Or maybe dead code elimination is rather a byproduct of some other optimizations. (In other words, there are some other optimizations analyzing code flow, so that dead code elimination is quite easy to implement.)



P.S.: I know, this question is a bit on the edge of opinion-based questions. I believe this question is OK, because one can point to some evidence, e.g., on some realistic code where DCE helps or to some kind of optimization that helps with implementation of dead code elimination.







optimization compiler-optimization dead-code






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 11:16









v6ak

1,25821024




1,25821024








  • 2




    If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
    – Ryan Pierce Williams
    Nov 11 at 11:20












  • @RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
    – v6ak
    Nov 11 at 11:27






  • 1




    it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
    – hanshenrik
    Nov 11 at 11:28










  • @v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
    – Ryan Pierce Williams
    Nov 11 at 11:29






  • 1




    @hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
    – Hadi Brais
    Nov 13 at 0:01














  • 2




    If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
    – Ryan Pierce Williams
    Nov 11 at 11:20












  • @RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
    – v6ak
    Nov 11 at 11:27






  • 1




    it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
    – hanshenrik
    Nov 11 at 11:28










  • @v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
    – Ryan Pierce Williams
    Nov 11 at 11:29






  • 1




    @hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
    – Hadi Brais
    Nov 13 at 0:01








2




2




If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20






If the code has no effect, why keep it? A single location that has useless code may not appear to have much of an effect, but removing all useless code from all programs as a standard policy will likely have a definite performance impact in both speed and memory for the overall system. It's a good default policy.
– Ryan Pierce Williams
Nov 11 at 11:20














@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27




@RyanPierceWilliams Sure, it is good to use it when it is implemented. I just doubt it is a common issue. Imagine you are involved in compiler development. You are about to decide if your team will spend time of this optimization or on some other kind of optimization. And someone like me objects: DCE has a little effect and it is a theoretical issue. Other optimizations will have deeper effect. How would you advocate spending the time on DCE?
– v6ak
Nov 11 at 11:27




1




1




it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28




it saves disk space and ram and startup time and makes the cpu prefetcher's job easier..
– hanshenrik
Nov 11 at 11:28












@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29




@v6ak You need to pick and choose your battles of course. If there are other areas to improve that will provide you with greater performance returns then do those first.
– Ryan Pierce Williams
Nov 11 at 11:29




1




1




@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01




@hanshenrik The OP is not asking whether DCE is useful, the question perhaps can be stated more clearly as "how significant is the performance improvement gained from DCE relative to other compiler optimizations when applied on real programs?" Also, regarding your comment, I don't see how it can make the CPU instruction prefetcher easier (I think you're talking about the instruction cache prefetcher). Also, saving disk space, while true, is not really the most important benefit of DCE. Saving startup time is also not necessarily true. Wikipedia has a very brief but good intro to DCE.
– Hadi Brais
Nov 13 at 0:01

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248175%2fwhy-do-compilers-remove-dead-code-why-is-it-worth-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248175%2fwhy-do-compilers-remove-dead-code-why-is-it-worth-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ