[llvm] r338612 - [X86] Add test cases for the patterns used by __builtin_ffs.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 1 11:38:43 PDT 2018
Author: ctopper
Date: Wed Aug 1 11:38:43 2018
New Revision: 338612
URL: http://llvm.org/viewvc/llvm-project?rev=338612&view=rev
Log:
[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.
Modified:
llvm/trunk/test/CodeGen/X86/dagcombine-select.ll
Modified: llvm/trunk/test/CodeGen/X86/dagcombine-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dagcombine-select.ll?rev=338612&r1=338611&r2=338612&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dagcombine-select.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dagcombine-select.ll Wed Aug 1 11:38:43 2018
@@ -378,3 +378,52 @@ define i32 @cttz_32_ne_select(i32 %v) no
%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
+}
More information about the llvm-commits
mailing list