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

--- Comment #4 from Yi <652023330028 at smail dot nju.edu.cn> ---
(In reply to Andrew Pinski from comment #1)
> The problem is in this case:
>     e=a+b+c;  //line 5
>     f=d+b+c;  //"b+c" can be replaced with the value at line 5
> 
> at the gimple level, b+c could introduce an signed integer overflow. And we
> don't want to introduce that.
> 
> 
> If you had used unsigned, rather than int, the optimization would have been
> done as we do reassociate unsigned integers just fine.


Thank you very much for your quick reply!
But example 1 in Bug 111561 does not seem to be well resolved.
https://godbolt.org/z/cM4n8qvrh
Given the following code: 
```c++
extern unsigned var_26;
extern unsigned var_29;
void test(unsigned var_1, unsigned var_2, unsigned var_3) {
    var_29 = (var_1 + var_2) ? var_1 : var_2;
    var_26 = var_1 + (var_2 + var_3);
}

```

```asm
test(unsigned int, unsigned int, unsigned 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
```

So does Bug 111562 .

Reply via email to