[Patch] Faulty conditional jump logic
Original Reporter info from Mantis: CuriousKit @CuriousKit
-
Reporter name: J. Gareth Moreton
Original Reporter info from Mantis: CuriousKit @CuriousKit
- Reporter name: J. Gareth Moreton
Description:
This patch fixes some faulty jump logic in the "Dominated conditional jump" and the "condition_in" function. The following are fixed:
- The "Dominated conditional jump" had the subset check between the two jumps back-to-front.
- The "jmp&LtPos;cond> before jmp&LtPos;inv_cond>" had the subset check between the two jumps back-to-front, and wasn't quite correct in cases where &LtPos;inv_cond> was a subset of the 2nd jump's conditions (rather than being exactly the same).
- "RemoveInstruction" and "RemoveCurrentP" inserted in the global jump optimisations where possible to reduce code maintenance.
x86-specific:
- "condition_in" incorrectly said "NE" was a subset of "L", "G", "A" and "B" (for example, if %reg = 0 and "cmp $1,%reg" is called, jne will branch, but jg will not. Treat "not equal" as equivalent to "less than OR greater than" or "above OR below").
- "condition_in" didn't consider "A", "B", "L" and "G" to be subsets of "NE".
- "condition_in" didn't consider "A" and "AE" to be subsets of "NC" (in regards to checking flags, B and C (and NB and NC) are interchangeable).
- "condition_in" incorrectly said "E" was a subset of "NB" (though logically sound when it comes to comparing numerical values, the conditions don't share flags. That is, E checks ZF = 0, while NB/NC check CF = 0).
Steps to reproduce:
Apply patch and confirm correct compilation on all platforms.
Additional information:
I'm amazed this issue hasn't caused problems before. It only came about when I was experimenting with a new peephole optimisation for x86.
If present in 3.2.0 or 3.2.2 (I can't remember as this optimisation of mine is quite old now), it may need to be backported.
Mantis conversion info:
- Mantis ID: 38985
- OS: Microsoft Windows
- OS Build: 10 Home
- Build: r49494
- Platform: Cross-platform (x86 especially)
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 49576 (#94a15faa)