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

--- Comment #2 from Avi Kivity <avi at scylladb dot com> ---
(testq/jle sequence)

The jle itself is from libstdc++:

```
      // Overload for pointers.
      template<typename _Tp, typename _Up>
        static _Up*
        __uninit_copy(_Tp* __first, _Tp* __last, _Up* __result)
        {
          // Ensure that we don't successfully memcpy in cases that should be
          // ill-formed because is_constructible<_Up, _Tp&> is false.
          typedef __typeof__(static_cast<_Up>(*__first)) __check
            __attribute__((__unused__));

          const ptrdiff_t __n = __last - __first;
          if (__builtin_expect(__n > 0, true))
            {
              __builtin_memcpy(__result, __first, __n * sizeof(_Tp));
              __result += __n;
            }
          return __result;
        }
    };
```

ptrdiff_t is signed, and the compiler believes you so it has to check.


I believe it's undefined to have __last not be reachable by incrementing
__first, so != would be fine here. Or not comparing and calling memcpy()
directly (which I see first compares against a bunch of small values before
detecting zero, I can't make up my mind if it's better to check in libstdc++ or
not).

I'll file an issue for the peephole optimization. It's a little tricky since
salq doesn't set the flags like other instructions.

Reply via email to