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

            Bug ID: 129223
           Summary: ce2 creates `(x == 0 ? x : 0)` and does not simplify
                    it
           Product: gcc
           Version: 17.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: ---
            Target: loongarch

As reported in
https://gcc.gnu.org/pipermail/gcc-patches/2026-December/742072.html

CE2 creates:

     (set (reg:DI 128)
          (if_then_else:DI
            (eq:DI (reg/v:DI 82 [c]) (const_int 0))
            (reg/v:DI 82 [c])
            (const_int 0)))

But does not simplify that to just:
(set (reg:DI 128)
     (const_int 0))


A testcase:
```

     void g (unsigned short, unsigned short);

     void
     f (unsigned short v, unsigned y)
     {
       if (v)
         v = y + 1 - v;
       g (1, v << y);
     }
```

```
(insn 107 106 108 2 (set (reg:DI 132)
        (if_then_else:DI (eq:DI (reg/v:DI 85 [ vD.3821 ])
                (const_int 0 [0]))
            (reg/v:DI 85 [ vD.3821 ])
            (const_int 0 [0]))) "/app/example.cpp":9:8 191 {*seleqdi_using_di}
     (nil))
```

https://godbolt.org/z/TxGT9Wz7z

Reply via email to