[llvm] r246781 - [x86] enable machine combiner reassociations for scalar 'xor' insts

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 09:36:16 PDT 2015


Author: spatel
Date: Thu Sep  3 11:36:16 2015
New Revision: 246781

URL: http://llvm.org/viewvc/llvm-project?rev=246781&view=rev
Log:
[x86] enable machine combiner reassociations for scalar 'xor' insts

Modified:
    llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
    llvm/trunk/test/CodeGen/X86/machine-combiner-int.ll

Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=246781&r1=246780&r2=246781&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Thu Sep  3 11:36:16 2015
@@ -6401,6 +6401,10 @@ static bool isAssociativeAndCommutative(
   case X86::OR16rr:
   case X86::OR32rr:
   case X86::OR64rr:
+  case X86::XOR8rr:
+  case X86::XOR16rr:
+  case X86::XOR32rr:
+  case X86::XOR64rr:
   case X86::IMUL16rr:
   case X86::IMUL32rr:
   case X86::IMUL64rr:

Modified: llvm/trunk/test/CodeGen/X86/machine-combiner-int.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/machine-combiner-int.ll?rev=246781&r1=246780&r2=246781&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/machine-combiner-int.ll (original)
+++ llvm/trunk/test/CodeGen/X86/machine-combiner-int.ll Thu Sep  3 11:36:16 2015
@@ -145,3 +145,50 @@ define i64 @reassociate_ors_i64(i64 %x0,
   ret i64 %t2
 }
 
+; Verify that integer 'xors' are reassociated. The first 'xor' in
+; each test should be independent of the result of the preceding sub.
+
+define i8 @reassociate_xors_i8(i8 %x0, i8 %x1, i8 %x2, i8 %x3) {
+; CHECK-LABEL: reassociate_xors_i8:
+; CHECK:       # BB#0:
+; CHECK-NEXT:    subb  %sil, %dil
+; CHECK-NEXT:    xorb  %cl, %dl
+; CHECK-NEXT:    xorb  %dil, %dl
+; CHECK_NEXT:    movb  %dx, %ax
+; CHECK_NEXT:    retq
+  %t0 = sub i8 %x0, %x1
+  %t1 = xor i8 %x2, %t0
+  %t2 = xor i8 %x3, %t1
+  ret i8 %t2
+}
+
+; TODO: No way to test i16? These appear to always get promoted to i32.
+
+define i32 @reassociate_xors_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
+; CHECK-LABEL: reassociate_xors_i32:
+; CHECK:       # BB#0:
+; CHECK-NEXT:    subl  %esi, %edi
+; CHECK-NEXT:    xorl  %ecx, %edx
+; CHECK-NEXT:    xorl  %edi, %edx
+; CHECK_NEXT:    movl  %edx, %eax
+; CHECK_NEXT:    retq
+  %t0 = sub i32 %x0, %x1
+  %t1 = xor i32 %x2, %t0
+  %t2 = xor i32 %x3, %t1
+  ret i32 %t2
+}
+
+define i64 @reassociate_xors_i64(i64 %x0, i64 %x1, i64 %x2, i64 %x3) {
+; CHECK-LABEL: reassociate_xors_i64:
+; CHECK:       # BB#0:
+; CHECK-NEXT:    subq  %rsi, %rdi
+; CHECK-NEXT:    xorq  %rcx, %rdx
+; CHECK-NEXT:    xorq  %rdi, %rdx
+; CHECK-NEXT:    movq  %rdx, %rax
+; CHECK_NEXT:    retq
+  %t0 = sub i64 %x0, %x1
+  %t1 = xor i64 %x2, %t0
+  %t2 = xor i64 %x3, %t1
+  ret i64 %t2
+}
+




More information about the llvm-commits mailing list