https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129023
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:1ebf5b5172007fe281e257df2cf1dc20f777e816 commit r17-6720-g1ebf5b5172007fe281e257df2cf1dc20f777e816 Author: Jakub Jelinek <[email protected]> Date: Thu Nov 26 09:36:53 2026 +0100 internal-fn: Fix up __builtin_clmulg PR128545 optimization [PR129023] The comment: T r = x; for (unsigned i = 1; i < M; i = i + i) r ^= r << i; return r << N; in the code is correct (where M is cnt and N is tz), but I have actually not implemented it like that, but as T r = x; unsigned i = 1; do { r ^= r << i; i = i + i; } while (i < M); return r << N; Now if M (cnt) is bigger than 1, there is difference, but for cnt == 1 we should just return x << N; As M (cnt) is compile time constant, we can just emit just the shifting for cnt == 1 and this patch also avoids RTL garbage that needs to be cleaned up later for cnt == 2, where we need exactly one iteration, so doing (x ^ (x << 1)) << N is simpler. 2026-11-26 Jakub Jelinek <[email protected]> PR middle-end/129023 * internal-fn.cc (expand_clmul): For cnt == 1, just shift res left by tz, without any loop. For cnt == 2, unroll the loop by hand. * c-c++-common/builtin-clmulg-5.c: New test. Reviewed-by: Richard Biener <[email protected]>
