https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122607
Bug ID: 122607
Summary: `(plus (plus (ltu a 0) b)` split could be better
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
unsigned constexpr X = 1;
unsigned f1(unsigned a, unsigned b) {
b += a;
auto c = b < a;
b += X + c;
return b;
}
unsigned f2(unsigned a, unsigned b) {
b += a;
b += X + (b < a);
return b;
}
```
at -O2 we get:
```
Trying 42, 43 -> 24:
42: r101:SI=ltu(cc:CC_C,0)
REG_DEAD cc:CC_C
43: r101:SI=r101:SI+0x1
24: r110:SI=r101:SI+r109:SI
REG_DEAD r109:SI
REG_DEAD r101:SI
Failed to match this instruction:
(set (reg:SI 110 [ b_5 ])
(plus:SI (plus:SI (ltu:SI (reg:CC_C 66 cc)
(const_int 0 [0]))
(reg:SI 109))
(const_int 1 [0x1])))
Successfully matched this instruction:
(set (reg:SI 101 [ iftmp.0_1 ])
(ltu:SI (reg:CC_C 66 cc)
(const_int 0 [0])))
Failed to match this instruction:
(set (reg:SI 110 [ b_5 ])
(plus:SI (plus:SI (reg:SI 101 [ iftmp.0_1 ])
(reg:SI 109))
(const_int 1 [0x1])))
```
If we split instead at the it into:
(set (reg:SI 101 [ iftmp.0_1 ])
(plus:SI (ltu:SI (reg:CC_C 66 cc)
(const_int 0 [0]))
(set (reg:SI 110 [ b_5 ])
(plus:SI (reg:SI 101 [ iftmp.0_1 ])
(const_int 1 [0x1])))
This would have matched and both could match for aarch64.