https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94850
Bug ID: 94850 Summary: Failure to optimize operation corresponding to shrd to shrd Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- struct testStruct { uint64_t a; uint64_t b; }; uint64_t f(testStruct t, int x) { return ((t.a << (64 - x)) | (t.b >> (x))); } LLVM produces this : f(testStruct, int): # @f(testStruct, int) mov ecx, edx mov rax, rsi shrd rax, rdi, cl ret GCC produces this : f(testStruct, int): mov ecx, 64 mov rax, rsi sub ecx, edx sal rdi, cl mov ecx, edx shr rax, cl or rax, rdi ret A similar optimization can be done for shld for this code : uint64_t f(uint64_t a, uint64_t b, int x) { return ((a << (x)) | (b >> (64 - x))); }