I noticed while improving forwprop, that fold_stmt sometimes would return true even if there was no change that happened. These fixes 3 of those places. In the first one we had: ``` tmp = a ? b : c if (tmp != 0) ```
And match and simplify would return the same thing but that was just because of the order of patterns in match.pd. The second one is that we would return true when simplifying: ``` if (0 != 0) ``` and ``` if (1 != 0) ``` as we would do constant folding on the comparison and then change it back to. This has an early out so that we don't even waste time going through constant folding. The 3rd and final one of this branch is related to the first one where we had: ``` if (bool != 0) ``` and the comparison would simplify back to `bool` which then gets placed back into the GIMPLE_COND as `bool != 0`. So we need to reject it while placing it back into the GIMPLE_COND if the variable didn't change. There is a 4th patch which I am working on dealing with trapping math and comparisons. I am trying to figure out the best way of implementing it. Thanks, Andrew Pinski Andrew Pinski (3): match: Move `(cmp (cond @0 @1 @2) @3)` simplification after the bool compare simplifcation gimple-fold: Return early for GIMPLE_COND with true/false gimple-fold: Don't replace `bool_var != 0` with `bool_var` inside GIMPLE_COND gcc/gimple-fold.cc | 25 ++++++++++++++++++++----- gcc/match.pd | 31 +++++++++++++++++-------------- 2 files changed, 37 insertions(+), 19 deletions(-) -- 2.43.0