[X86] Improve optimizeCompareInstr for signed comparisons after BZHI instructions
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 7 Apr 2021 11:07:10 +0000 (12:07 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 7 Apr 2021 11:07:26 +0000 (12:07 +0100)
Extend D94856 to handle 'bzhi' instructions as well

llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/test/CodeGen/X86/bmi2.ll

index c134eaf..96af0aa 100644 (file)
@@ -4039,8 +4039,6 @@ inline static bool isDefConvertible(const MachineInstr &MI, bool &NoSignFlag,
   case X86::SAR8r1:    case X86::SAR16r1:  case X86::SAR32r1:case X86::SAR64r1:
   case X86::SHR8r1:    case X86::SHR16r1:  case X86::SHR32r1:case X86::SHR64r1:
   case X86::SHL8r1:    case X86::SHL16r1:  case X86::SHL32r1:case X86::SHL64r1:
-  case X86::BZHI32rr:  case X86::BZHI32rm:
-  case X86::BZHI64rr:  case X86::BZHI64rm:
   case X86::LZCNT16rr: case X86::LZCNT16rm:
   case X86::LZCNT32rr: case X86::LZCNT32rm:
   case X86::LZCNT64rr: case X86::LZCNT64rm:
@@ -4073,6 +4071,8 @@ inline static bool isDefConvertible(const MachineInstr &MI, bool &NoSignFlag,
   case X86::BLSFILL64rr: case X86::BLSFILL64rm:
   case X86::BLSIC32rr:   case X86::BLSIC32rm:
   case X86::BLSIC64rr:   case X86::BLSIC64rm:
+  case X86::BZHI32rr:    case X86::BZHI32rm:
+  case X86::BZHI64rr:    case X86::BZHI64rm:
   case X86::T1MSKC32rr:  case X86::T1MSKC32rm:
   case X86::T1MSKC64rr:  case X86::T1MSKC64rm:
   case X86::TZMSK32rr:   case X86::TZMSK32rm:
index 0b3a415..8c86c5e 100644 (file)
@@ -38,20 +38,18 @@ define i32 @bzhi32_load(i32* %x, i32 %y)   {
   ret i32 %tmp
 }
 
-; FIXME: PR48768 - 'bzhi' clears the overflow flag, so we don't need a separate 'test'.
+; PR48768 - 'bzhi' clears the overflow flag, so we don't need a separate 'test'.
 define i1 @bzhi32_overflow(i32 %x, i32 %y) {
 ; X86-LABEL: bzhi32_overflow:
 ; X86:       # %bb.0:
 ; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
 ; X86-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax
-; X86-NEXT:    testl %eax, %eax
 ; X86-NEXT:    setle %al
 ; X86-NEXT:    retl
 ;
 ; X64-LABEL: bzhi32_overflow:
 ; X64:       # %bb.0:
 ; X64-NEXT:    bzhil %esi, %edi, %eax
-; X64-NEXT:    testl %eax, %eax
 ; X64-NEXT:    setle %al
 ; X64-NEXT:    retq
   %tmp = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %x, i32 %y)