Skip to content

Commit

Permalink
[X86] Add second PR47603 test case
Browse files Browse the repository at this point in the history
We had coverage for the xor(trunc(xor(x,31)),31) case but not xor(zext(xor(x,31)),31)
  • Loading branch information
RKSimon committed Apr 5, 2021
1 parent 4dd3e0f commit 2523fe8
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions llvm/test/CodeGen/X86/clz.ll
Expand Up @@ -1061,27 +1061,27 @@ define i64 @cttz_i64_zero_test_knownneverzero(i64 %n) {
}

; Ensure we fold away the XOR(TRUNC(XOR(BSR(X),31)),31).
define i8 @PR47603(i32 %0) {
; X86-LABEL: PR47603:
define i8 @PR47603_trunc(i32 %0) {
; X86-LABEL: PR47603_trunc:
; X86: # %bb.0:
; X86-NEXT: bsrl {{[0-9]+}}(%esp), %eax
; X86-NEXT: # kill: def $al killed $al killed $eax
; X86-NEXT: retl
;
; X64-LABEL: PR47603:
; X64-LABEL: PR47603_trunc:
; X64: # %bb.0:
; X64-NEXT: bsrl %edi, %eax
; X64-NEXT: # kill: def $al killed $al killed $eax
; X64-NEXT: retq
;
; X86-CLZ-LABEL: PR47603:
; X86-CLZ-LABEL: PR47603_trunc:
; X86-CLZ: # %bb.0:
; X86-CLZ-NEXT: lzcntl {{[0-9]+}}(%esp), %eax
; X86-CLZ-NEXT: xorb $31, %al
; X86-CLZ-NEXT: # kill: def $al killed $al killed $eax
; X86-CLZ-NEXT: retl
;
; X64-CLZ-LABEL: PR47603:
; X64-CLZ-LABEL: PR47603_trunc:
; X64-CLZ: # %bb.0:
; X64-CLZ-NEXT: lzcntl %edi, %eax
; X64-CLZ-NEXT: xorb $31, %al
Expand All @@ -1092,3 +1092,43 @@ define i8 @PR47603(i32 %0) {
%4 = trunc i32 %3 to i8
ret i8 %4
}

; Ensure we fold away the XOR(ZEXT(XOR(BSR(X),31)),31).
define i32 @PR47603_zext(i32 %a0, [32 x i8]* %a1) {
; X86-LABEL: PR47603_zext:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: bsrl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movsbl (%eax,%ecx), %eax
; X86-NEXT: retl
;
; X64-LABEL: PR47603_zext:
; X64: # %bb.0:
; X64-NEXT: bsrl %edi, %eax
; X64-NEXT: xorl $31, %eax
; X64-NEXT: xorq $31, %rax
; X64-NEXT: movsbl (%rsi,%rax), %eax
; X64-NEXT: retq
;
; X86-CLZ-LABEL: PR47603_zext:
; X86-CLZ: # %bb.0:
; X86-CLZ-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-CLZ-NEXT: lzcntl {{[0-9]+}}(%esp), %ecx
; X86-CLZ-NEXT: xorl $31, %ecx
; X86-CLZ-NEXT: movsbl (%eax,%ecx), %eax
; X86-CLZ-NEXT: retl
;
; X64-CLZ-LABEL: PR47603_zext:
; X64-CLZ: # %bb.0:
; X64-CLZ-NEXT: lzcntl %edi, %eax
; X64-CLZ-NEXT: xorq $31, %rax
; X64-CLZ-NEXT: movsbl (%rsi,%rax), %eax
; X64-CLZ-NEXT: retq
%ctlz = tail call i32 @llvm.ctlz.i32(i32 %a0, i1 true)
%xor = xor i32 %ctlz, 31
%zext = zext i32 %xor to i64
%gep = getelementptr inbounds [32 x i8], [32 x i8]* %a1, i64 0, i64 %zext
%load = load i8, i8* %gep, align 1
%sext = sext i8 %load to i32
ret i32 %sext
}

0 comments on commit 2523fe8

Please sign in to comment.