http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57009
Bug #: 57009 Summary: Select best typed instruction for scalar bitwise operations Classification: Unclassified Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: gli...@gcc.gnu.org Target: x86_64-linux-gnu Hello, I purposedly took almost the same title as PR 54716, because this is the same issue, but for scalars. Consider this code: union A { double d; unsigned long long i; }; bool f(double a, double b, double c){ A x, y, z; x.d = a * a; y.d = b * b; z.i = x.i & y.i; return z.d < c; } which compiles to: mulsd %xmm0, %xmm0 mulsd %xmm1, %xmm1 movq %xmm0, %rax movq %xmm1, %rdx andq %rdx, %rax movq %rax, %xmm0 ucomisd %xmm0, %xmm2 seta %al when using andpd would save 3 movq. Note that for vectors, we get nicer code thanks to Jakub's patch: mulpd %xmm1, %xmm1 mulpd %xmm0, %xmm0 andpd %xmm1, %xmm0 cmpltpd %xmm2, %xmm0 It would be nice to extend that code to scalars (including the case where one of the arguments is a constant). I hit this while experimenting for PR 56944.