From ffb8eb30ff85d5d2ffbfbebc36b0f2002dc3aa99 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 1 Aug 2018 18:38:43 +0000 Subject: [PATCH] [X86] Add test cases for the patterns used by __builtin_ffs. We previously had tests for "__builtin_ffs + 5", but the SelectinoDAG without an extra addition came out slightly different. llvm-svn: 338612 --- llvm/test/CodeGen/X86/dagcombine-select.ll | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/llvm/test/CodeGen/X86/dagcombine-select.ll b/llvm/test/CodeGen/X86/dagcombine-select.ll index 1ef6cfd..50d2809 100644 --- a/llvm/test/CodeGen/X86/dagcombine-select.ll +++ b/llvm/test/CodeGen/X86/dagcombine-select.ll @@ -378,3 +378,52 @@ define i32 @cttz_32_ne_select(i32 %v) nounwind { %add = select i1 %tobool, i32 %.op, i32 5 ret i32 %add } + +; This matches the pattern emitted for __builtin_ffs +define i32 @cttz_32_eq_select_ffs(i32 %v) nounwind { +; NOBMI-LABEL: cttz_32_eq_select_ffs: +; NOBMI: # %bb.0: +; NOBMI-NEXT: bsfl %edi, %eax +; NOBMI-NEXT: incl %eax +; NOBMI-NEXT: testl %edi, %edi +; NOBMI-NEXT: cmovel %edi, %eax +; NOBMI-NEXT: retq +; +; BMI-LABEL: cttz_32_eq_select_ffs: +; BMI: # %bb.0: +; BMI-NEXT: tzcntl %edi, %eax +; BMI-NEXT: incl %eax +; BMI-NEXT: testl %edi, %edi +; BMI-NEXT: cmovel %edi, %eax +; BMI-NEXT: retq + + %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true) + %tobool = icmp eq i32 %v, 0 + %.op = add nuw nsw i32 %cnt, 1 + %add = select i1 %tobool, i32 0, i32 %.op + ret i32 %add +} + +define i32 @cttz_32_ne_select_ffs(i32 %v) nounwind { +; NOBMI-LABEL: cttz_32_ne_select_ffs: +; NOBMI: # %bb.0: +; NOBMI-NEXT: bsfl %edi, %eax +; NOBMI-NEXT: incl %eax +; NOBMI-NEXT: testl %edi, %edi +; NOBMI-NEXT: cmovel %edi, %eax +; NOBMI-NEXT: retq +; +; BMI-LABEL: cttz_32_ne_select_ffs: +; BMI: # %bb.0: +; BMI-NEXT: tzcntl %edi, %eax +; BMI-NEXT: incl %eax +; BMI-NEXT: testl %edi, %edi +; BMI-NEXT: cmovel %edi, %eax +; BMI-NEXT: retq + + %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true) + %tobool = icmp ne i32 %v, 0 + %.op = add nuw nsw i32 %cnt, 1 + %add = select i1 %tobool, i32 %.op, i32 0 + ret i32 %add +} -- 2.7.4