https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110369
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[14 Regression] wrong code |[14 Regression] wrong code
|on x86_64-linux-gnu |on x86_64-linux-gnu with
| |sel-scheduling
Component|tree-optimization |rtl-optimization
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The first difference (after my patch) is in VRP:
Before:
```
Folding statement: f_14 = f_20 + 1;
Loops range found for f_20: [irange] int [0, 1] NONZERO 0x1 and calculated
range :[irange] int [0, 1] NONZERO 0x1
Matching expression match.pd:2404, gimple-match.cc:852
Matching expression match.pd:2407, gimple-match.cc:925
Matching expression match.pd:2414, gimple-match.cc:985
Matching expression match.pd:1924, gimple-match.cc:802
Matching expression match.pd:1896, gimple-match.cc:720
Global Exported: f_14 = [irange] int [1, 2] NONZERO 0x3
Folded into: f_14 = _18 ? 1 : 2;
```
After:
```
Folding statement: f_14 = f_20 + 1;
Loops range found for f_20: [irange] int [0, 1] NONZERO 0x1 and calculated
range :[irange] int [0, 1] NONZERO 0x1
Matching expression match.pd:2404, gimple-match.cc:852
Matching expression match.pd:2407, gimple-match.cc:925
Matching expression match.pd:2414, gimple-match.cc:985
Matching expression match.pd:1924, gimple-match.cc:802
Applying pattern match.pd:4720, gimple-match.cc:11377
Applying pattern match.pd:3998, gimple-match.cc:39957
gimple_simplified to _8 = f_20 + 1;
f_14 = _8;
Registering value_relation (_8 > f_20) (bb12) at _8 = f_20 + 1;
Registering value_relation (f_14 == _8) (bb12) at f_14 = _8;
Global Exported: f_14 = [irange] int [1, 2] NONZERO 0x3
Folded into: f_14 = _8;
```
Note _18 is defined as:
_18 = f_20 == 0;
Which is ok and 100% correct.
And then another difference:
Before:
```
Folding statement: if (f_14 != 2)
Visiting conditional with predicate: if (f_14 != 2)
With known ranges
f_14: [irange] int [1, 2] NONZERO 0x3
Predicate evaluates to: DON'T KNOW
Matching expression match.pd:2404, gimple-match.cc:852
Matching expression match.pd:2407, gimple-match.cc:925
Matching expression match.pd:2414, gimple-match.cc:985
Applying pattern match.pd:5945, gimple-match.cc:24663
Matching expression match.pd:1924, gimple-match.cc:802
Applying pattern match.pd:4600, gimple-match.cc:176366
Applying pattern match.pd:3998, gimple-match.cc:39802
gimple_simplified to if (_18 != 0)
Folded into: if (_18 != 0)
```
After:
```
Folding statement: if (f_14 != 2)
Visiting conditional with predicate: if (f_14 != 2)
With known ranges
f_14: [irange] int [1, 2] NONZERO 0x3
Predicate evaluates to: DON'T KNOW
Matching expression match.pd:2404, gimple-match.cc:852
Matching expression match.pd:2407, gimple-match.cc:925
Matching expression match.pd:2414, gimple-match.cc:985
Not folded
```
I don't get why VRP folded it differently.
Anyways we just have a missed optimization inside VRP after my commit, not
wrong code.
The wrong code is due to sel scheduling.
The code at .optimized:
Before:
```
if (f_20 == 0)
```
After:
```
# RANGE [irange] int [-INF, +INF] NONZERO 0x3
_8 = f_20 + 1;
if (_8 != 2)
```
(which is basically f_21 != 1 or rather f_21 == 0 here)