Skip to content

Commit

Permalink
[X86] Add test cases for PR46203. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
topperc committed Jun 5, 2020
1 parent b6c8854 commit 8b05b6d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions llvm/test/CodeGen/X86/dagcombine-select.ll
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,54 @@ define i32 @cttz_32_ne_select_ffs(i32 %v) nounwind {
%add = select i1 %tobool, i32 %.op, i32 0
ret i32 %add
}

; This matches the pattern emitted for __builtin_ffs - 1
define i32 @cttz_32_eq_select_ffs_m1(i32 %v) nounwind {
; NOBMI-LABEL: cttz_32_eq_select_ffs_m1:
; NOBMI: # %bb.0:
; NOBMI-NEXT: bsfl %edi, %ecx
; NOBMI-NEXT: xorl %eax, %eax
; NOBMI-NEXT: cmpl $1, %edi
; NOBMI-NEXT: sbbl %eax, %eax
; NOBMI-NEXT: orl %ecx, %eax
; NOBMI-NEXT: retq
;
; BMI-LABEL: cttz_32_eq_select_ffs_m1:
; BMI: # %bb.0:
; BMI-NEXT: tzcntl %edi, %ecx
; BMI-NEXT: xorl %eax, %eax
; BMI-NEXT: cmpl $1, %edi
; BMI-NEXT: sbbl %eax, %eax
; BMI-NEXT: orl %ecx, %eax
; BMI-NEXT: retq

%cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
%tobool = icmp eq i32 %v, 0
%sel = select i1 %tobool, i32 -1, i32 %cnt
ret i32 %sel
}

define i32 @cttz_32_ne_select_ffs_m1(i32 %v) nounwind {
; NOBMI-LABEL: cttz_32_ne_select_ffs_m1:
; NOBMI: # %bb.0:
; NOBMI-NEXT: bsfl %edi, %ecx
; NOBMI-NEXT: xorl %eax, %eax
; NOBMI-NEXT: cmpl $1, %edi
; NOBMI-NEXT: sbbl %eax, %eax
; NOBMI-NEXT: orl %ecx, %eax
; NOBMI-NEXT: retq
;
; BMI-LABEL: cttz_32_ne_select_ffs_m1:
; BMI: # %bb.0:
; BMI-NEXT: tzcntl %edi, %ecx
; BMI-NEXT: xorl %eax, %eax
; BMI-NEXT: cmpl $1, %edi
; BMI-NEXT: sbbl %eax, %eax
; BMI-NEXT: orl %ecx, %eax
; BMI-NEXT: retq

%cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
%tobool = icmp ne i32 %v, 0
%sel = select i1 %tobool, i32 %cnt, i32 -1
ret i32 %sel
}

0 comments on commit 8b05b6d

Please sign in to comment.