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

            Bug ID: 127970
           Summary: wrong code at -O1 and above: _Decimal64 (x == C) ? C :
                    x returns x, changing the quantum exponent
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

int main(void) {
  volatile _Decimal64 v = 1.00DD;
  _Decimal64 x = v, c = 1.0DD, r = x == c ? c : x;
  return __builtin_memcmp(&r, &c, sizeof r) != 0;
}

godbolt: https://godbolt.org/z/rzPE41qcT

With -O0 it returns 0, but with GCC -O{1,2,3,s,g} it returns 1: x == 1.0DD is
true, but r gets x (1.00DD, equal value, different quantum exponent) instead of
the constant 1.0DD. -fno-tree-dominator-opts avoids it.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to