From b98f6099a5e639dbcf02486b6cbd7063d880ec26 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 20 Jun 2019 06:45:01 +0000 Subject: [PATCH] [X86] Add test cases showing missed opportunities to use the C flag from the BLSI instruction to avoid a TEST instruction git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363909 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/X86/bmi.ll | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/CodeGen/X86/bmi.ll b/test/CodeGen/X86/bmi.ll index c2d13c29710..cdad570226c 100644 --- a/test/CodeGen/X86/bmi.ll +++ b/test/CodeGen/X86/bmi.ll @@ -1223,3 +1223,68 @@ define void @pr42118_i64(i64 %x) { ret void } + +define i32 @blsi_cflag_32(i32 %x, i32 %y) nounwind { +; X86-LABEL: blsi_cflag_32: +; X86: # %bb.0: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: testl %eax, %eax +; X86-NEXT: jne .LBB50_1 +; X86-NEXT: # %bb.2: +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: retl +; X86-NEXT: .LBB50_1: +; X86-NEXT: blsil %eax, %eax +; X86-NEXT: retl +; +; X64-LABEL: blsi_cflag_32: +; X64: # %bb.0: +; X64-NEXT: blsil %edi, %eax +; X64-NEXT: testl %edi, %edi +; X64-NEXT: cmovel %esi, %eax +; X64-NEXT: retq + %tobool = icmp eq i32 %x, 0 + %sub = sub nsw i32 0, %x + %and = and i32 %sub, %x + %cond = select i1 %tobool, i32 %y, i32 %and + ret i32 %cond +} + +define i64 @blsi_cflag_64(i64 %x, i64 %y) nounwind { +; X86-LABEL: blsi_cflag_64: +; X86: # %bb.0: +; X86-NEXT: pushl %edi +; X86-NEXT: pushl %esi +; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NEXT: xorl %edx, %edx +; X86-NEXT: movl %ecx, %eax +; X86-NEXT: negl %eax +; X86-NEXT: sbbl %esi, %edx +; X86-NEXT: movl %ecx, %edi +; X86-NEXT: orl %esi, %edi +; X86-NEXT: jne .LBB51_1 +; X86-NEXT: # %bb.2: +; X86-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax +; X86-NEXT: jmp .LBB51_3 +; X86-NEXT: .LBB51_1: +; X86-NEXT: andl %esi, %edx +; X86-NEXT: andl %ecx, %eax +; X86-NEXT: .LBB51_3: +; X86-NEXT: popl %esi +; X86-NEXT: popl %edi +; X86-NEXT: retl +; +; X64-LABEL: blsi_cflag_64: +; X64: # %bb.0: +; X64-NEXT: blsiq %rdi, %rax +; X64-NEXT: testq %rdi, %rdi +; X64-NEXT: cmoveq %rsi, %rax +; X64-NEXT: retq + %tobool = icmp eq i64 %x, 0 + %sub = sub nsw i64 0, %x + %and = and i64 %sub, %x + %cond = select i1 %tobool, i64 %y, i64 %and + ret i64 %cond +} -- 2.40.0