https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111561

            Bug ID: 111561
           Summary: Missed optimization of available expression in if
                    condition
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, we found some optimizations (regarding Available Expression in If
condition) that GCC may have missed. We would greatly appreicate if you can
take a look and let us know what you think.

Here are two examples:

Example 1:
https://godbolt.org/z/vjWM5c93j

Given the following code: 
```c++
extern int var_26;
extern int var_29;
void test(int var_1, int var_2, int var_3) {
    var_29 = (var_1 + var_2) ? var_1 : var_2;  //line 4
    var_26 = var_1 + (var_2 + var_3); //can be replaced with the value at line
4
}
```

We note that `var_1+var_2` at line 5 in the test code can be replaced with the
value at line 4, but gcc-trunk -O3 does not:
```asm
test(int, int, int):
        mov     eax, edi
        add     eax, esi
        mov     eax, edi
        cmove   eax, esi
        add     esi, edx
        add     esi, edi
        mov     DWORD PTR var_29[rip], eax
        mov     DWORD PTR var_26[rip], esi
        ret
```


Example 2:
https://godbolt.org/z/31d8v453v

Given the following code: 
```c++
extern int var_24;
extern int var_25;
void test(int var_0, int var_1, int var_12) {
    var_24 = (var_1 + var_12 + var_0) ? 1 : 2;
    var_25 = var_12 + var_0;
}
```

We note that `var_12+var_0` at line 5 in the test code can be replaced with the
value at line 4, but gcc-trunk -O3 does not:
```asm
test(int, int, int):
        add     esi, edx
        xor     eax, eax
        add     esi, edi
        sete    al
        add     edx, edi
        add     eax, 1
        mov     DWORD PTR var_25[rip], edx
        mov     DWORD PTR var_24[rip], eax
        ret
```

Thank you very much for your time and effort! We look forward to hearing from
you.
  • [Bug tree-optimization/1... 652023330028 at smail dot nju.edu.cn via Gcc-bugs

Reply via email to