GCC can't optimize out the mask (which is required to avoid UB if n may be equal or greater than 64):
#include <stdint.h>
uint64_t rol(uint64_t n, uint64_t val)
{
n &= 63;
return (val << n) | (val >> 64-n);
}
Compiles to rol(unsigned long, unsigned long):
mov rcx, rdi
mov rax, rsi
and ecx, 63
rol rax, cl
ret
Clang and ICC do get it right.