[llvm] 5832587 - [X86] Improve optimizeCompareInstr for signed comparisons after BZHI instructions

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 7 04:13:56 PDT 2021


Author: Simon Pilgrim
Date: 2021-04-07T12:07:26+01:00
New Revision: 583258723fe22cbb8b10d4a21b50a486b2df59ed

URL: https://github.com/llvm/llvm-project/commit/583258723fe22cbb8b10d4a21b50a486b2df59ed
DIFF: https://github.com/llvm/llvm-project/commit/583258723fe22cbb8b10d4a21b50a486b2df59ed.diff

LOG: [X86] Improve optimizeCompareInstr for signed comparisons after BZHI instructions

Extend D94856 to handle 'bzhi' instructions as well

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index c134eafb49b2..96af0aaab7b9 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -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:

diff  --git a/llvm/test/CodeGen/X86/bmi2.ll b/llvm/test/CodeGen/X86/bmi2.ll
index 0b3a415a18ee..8c86c5eb3007 100644
--- a/llvm/test/CodeGen/X86/bmi2.ll
+++ b/llvm/test/CodeGen/X86/bmi2.ll
@@ -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)


        


More information about the llvm-commits mailing list