summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-08-01 18:38:43 +0000
committerCraig Topper <craig.topper@intel.com>2018-08-01 18:38:43 +0000
commitffb8eb30ff85d5d2ffbfbebc36b0f2002dc3aa99 (patch)
tree99eac15ef21c467223cc8f62ff6266d97a527cf4
parent95d8c464d8ff334e7ceaa1630a6d39a5cb72e69c (diff)
downloadbcm5719-llvm-ffb8eb30ff85d5d2ffbfbebc36b0f2002dc3aa99.tar.gz
bcm5719-llvm-ffb8eb30ff85d5d2ffbfbebc36b0f2002dc3aa99.zip
[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
-rw-r--r--llvm/test/CodeGen/X86/dagcombine-select.ll49
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/X86/dagcombine-select.ll b/llvm/test/CodeGen/X86/dagcombine-select.ll
index 1ef6cfdfd40..50d2809e008 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
+}
OpenPOWER on IntegriCloud