I'm building a simple application to "Release". The optimization level is set to -02 (generally the most I consider safe). When looking at the disassembled code in the debugger I see this:
That was a typo in my post. I do have the optimization setting set to -O2 (capital Oh).
My original question still stands: with this level of optimization turned on, why is the compiler generating so many redundant load/store instructions?
That's what I would have expected. Perhaps I'm not settings optimizations properly. Here's how I'm doing it in the IDE:
1. Right-click on project name in the Project Explorer.
2. Choose Properties from the context menu.
3. Select C/XC Build->Settings
4. Click on XC Compiler->Optimization.
5. In the Optimization Level drop-down box, choose "Optimize more (-O2)"
6. Click "OK"
7. Clean project.
8. Build project (choosing Release rather than Debug).
When I look into Debug Configurations I see that I have "Build Configuration" set to "Release". Yet if I delete the .xe file from the "Debug" folder, clicking on Debug results in a "Program file does not exist".
Why, if I have the Build Configuration set to Release in the Debug Configuration, does the debugger look for the binary in the Debug folder? Shouldn't it look for in in Release folder?
Not answering your question directly -- but I sometimes find that the IDE will run the wrong executable.
For example, my code will be in revision 1.1 and I can compile and run in Debug. Then make changes, say up to version 1.2. Switch to release, compile, and then run. After much confusion, realize that v1.1 debug-compiled code is running.
Cleaning the project does not fix this. I used to clean, then delete the Release and Debug folders within the IDE view, then rebuild. Now, I just never switch from Release to Debug or vice versa, I just pick a configuration and stay with it.
Also, the compiler thinks it is running the correct executable -- and will point to source code as it debugs that has nothing to do with the code actually running (extremely confusing -- as during the line "x++;" you'll notice in the watch window that some other variable has now changed).
tyler wrote:Not answering your question directly -- but I sometimes find that the IDE will run the wrong executable.
For example, my code will be in revision 1.1 and I can compile and run in Debug. Then make changes, say up to version 1.2. Switch to release, compile, and then run. After much confusion, realize that v1.1 debug-compiled code is running.
This is because when you hit "Run" eclipse creates a run configuration for the binary that it finds first and runs it. It then remembers that configuration and will build it whenever you hit run. To ensure you are running a binary in a different configuration you need to create a separate "run configuration" for release and debug.
On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.