Andreas Schwab and Gunther Nikl have pointed out that GCC will incorrectly create "on purpose" impossible branch instructions.
Reason Summary: - GCC is able to simplify certain compares. - GCC seems to be unable to correctly rewrite the corresponding branch instructions. - GCC thereby generates branches that are by definition impossible to do. Example: void foo (unsigned long j) { unsigned int i; for (i = 0; i < (j>>5); ++i) ; } In this example the generated code does include a compare with a variable that is ZERO. GCC correctly knows that it can simplify a compare against ZERO. But GCC fails to correctly adapt the condition codes. Background: A compare of two unsigned variables can set the CARRY flag. A compare against ZERO can never set the CARRY flag. While GCC recognizes that it can rewrite a CMP with 0 , GCC does not rewrite the branch that checks for the Carry. GCC hereby creates branches that include conditions that are known to be impossible at compile time. > The following link should be the thread about this issue > http://gcc.gnu.org/ml/gcc/2003-10/msg01236.html The problem that we describe here leads to the following: GCC creates branches that include impossible conditions. GCC does not remove the impossible conditions. GCC wants to rewrite the CMP with 0 with a more efficient code. But the 68K backend need to forbid this. Normally it would be possible to leave the CMP 0,variable simply away. And all branches that test for a condition that could actually be set by a cmp with 0 would be possible to evaluate. But as GCC writes branches which include known impossible conditions leaving the cmp away is not possible. The CMP with 0 is explicitly needed to ensure that all flags are cleared to ensure that the branches to known impossible conditions are not taken. It would be great if you could fix the reason for this instead curing the sympton. As this would allow the backend to really remove the unneeded CMP instructions thereby generating smaller and faster code. Many thanks in advance Gunnar von Boehn -- Summary: GCC generates impossible BRANCH instruction Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gunnar at greyhound-data dot com GCC build triplet: m68k-linux-gnu GCC host triplet: m68k-linux-gnu GCC target triplet: m68k-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36772