[llvm] 96aa76a - [X86] Add test showing poor bitselect between constants on BMI targets

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 07:32:18 PST 2023


Author: Simon Pilgrim
Date: 2023-02-26T15:32:04Z
New Revision: 96aa76aa716d577d31a2831c8d3a85ddd6b3de80

URL: https://github.com/llvm/llvm-project/commit/96aa76aa716d577d31a2831c8d3a85ddd6b3de80
DIFF: https://github.com/llvm/llvm-project/commit/96aa76aa716d577d31a2831c8d3a85ddd6b3de80.diff

LOG: [X86] Add test showing poor bitselect between constants on BMI targets

bitselect(52,-6553,m) -> xor(and(xor(52,-6553),m),52) folds much better than or(and(52,not(m)),and(-6553,m))

Added: 
    

Modified: 
    llvm/test/CodeGen/X86/bitselect.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/X86/bitselect.ll b/llvm/test/CodeGen/X86/bitselect.ll
index 5f1f6bd83a9a..2922113b14ea 100644
--- a/llvm/test/CodeGen/X86/bitselect.ll
+++ b/llvm/test/CodeGen/X86/bitselect.ll
@@ -200,3 +200,39 @@ define i128 @bitselect_i128(i128 %a, i128 %b, i128 %m) nounwind {
   %or = or i128 %ma, %mb
   ret i128 %or
 }
+
+;
+; Bitselect between constants
+;
+
+; bitselect(52, -6553, m)
+; TODO: Non-BMI canonicalization is actually better.
+define i32 @bitselect_constants_i32(i32 %m) nounwind {
+; X86-LABEL: bitselect_constants_i32:
+; X86:       # %bb.0:
+; X86-NEXT:    movl $-6573, %eax # imm = 0xE653
+; X86-NEXT:    andl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:    xorl $52, %eax
+; X86-NEXT:    retl
+;
+; X64-NOBMI-LABEL: bitselect_constants_i32:
+; X64-NOBMI:       # %bb.0:
+; X64-NOBMI-NEXT:    movl %edi, %eax
+; X64-NOBMI-NEXT:    andl $-6573, %eax # imm = 0xE653
+; X64-NOBMI-NEXT:    xorl $52, %eax
+; X64-NOBMI-NEXT:    retq
+;
+; X64-BMI-LABEL: bitselect_constants_i32:
+; X64-BMI:       # %bb.0:
+; X64-BMI-NEXT:    movl %edi, %eax
+; X64-BMI-NEXT:    notl %eax
+; X64-BMI-NEXT:    andl $52, %eax
+; X64-BMI-NEXT:    andl $-6553, %edi # imm = 0xE667
+; X64-BMI-NEXT:    orl %edi, %eax
+; X64-BMI-NEXT:    retq
+  %not = xor i32 %m, -1
+  %ma = and i32 52, %not
+  %mb = and i32 -6553, %m
+  %or = or i32 %ma, %mb
+  ret i32 %or
+}


        


More information about the llvm-commits mailing list