summaryrefslogtreecommitdiff
path: root/test/CodeGen/X86/sbb.ll
diff options
context:
space:
mode:
Diffstat (limited to 'test/CodeGen/X86/sbb.ll')
-rw-r--r--test/CodeGen/X86/sbb.ll138
1 files changed, 138 insertions, 0 deletions
diff --git a/test/CodeGen/X86/sbb.ll b/test/CodeGen/X86/sbb.ll
new file mode 100644
index 0000000000000..bc00fc7c66ad7
--- /dev/null
+++ b/test/CodeGen/X86/sbb.ll
@@ -0,0 +1,138 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
+
+; Vary the operand sizes for extra coverage, but the transform should be identical in all cases.
+
+; (X == 0) ? 0 : -1 --> (X == 0) - 1
+
+define i8 @i8_select_0_or_neg1(i8 %x) {
+; CHECK-LABEL: i8_select_0_or_neg1:
+; CHECK: # BB#0:
+; CHECK-NEXT: negb %dil
+; CHECK-NEXT: sbbb %al, %al
+; CHECK-NEXT: retq
+ %cmp = icmp eq i8 %x, 0
+ %sel = select i1 %cmp, i8 0, i8 -1
+ ret i8 %sel
+}
+
+; (X == 0) ? 0 : -1 --> (X == 0) - 1
+
+define i16 @i16_select_0_or_neg1_as_math(i16 %x) {
+; CHECK-LABEL: i16_select_0_or_neg1_as_math:
+; CHECK: # BB#0:
+; CHECK-NEXT: negw %di
+; CHECK-NEXT: sbbw %ax, %ax
+; CHECK-NEXT: retq
+ %cmp = icmp eq i16 %x, 0
+ %ext = zext i1 %cmp to i16
+ %add = add i16 %ext, -1
+ ret i16 %add
+}
+
+; (X != 0) ? -1 : 0 --> 0 - (X != 0)
+
+define i32 @i32_select_0_or_neg1_commuted(i32 %x) {
+; CHECK-LABEL: i32_select_0_or_neg1_commuted:
+; CHECK: # BB#0:
+; CHECK-NEXT: negl %edi
+; CHECK-NEXT: sbbl %eax, %eax
+; CHECK-NEXT: retq
+ %cmp = icmp ne i32 %x, 0
+ %sel = select i1 %cmp, i32 -1, i32 0
+ ret i32 %sel
+}
+
+; (X != 0) ? -1 : 0 --> 0 - (X != 0)
+
+define i64 @i64_select_0_or_neg1_commuted_as_math(i64 %x) {
+; CHECK-LABEL: i64_select_0_or_neg1_commuted_as_math:
+; CHECK: # BB#0:
+; CHECK-NEXT: negq %rdi
+; CHECK-NEXT: sbbq %rax, %rax
+; CHECK-NEXT: retq
+ %cmp = icmp ne i64 %x, 0
+ %ext = zext i1 %cmp to i64
+ %sub = sub i64 0, %ext
+ ret i64 %sub
+}
+
+; (X == 0) ? -1 : 0 --> 0 - (X == 0)
+
+define i64 @i64_select_neg1_or_0(i64 %x) {
+; CHECK-LABEL: i64_select_neg1_or_0:
+; CHECK: # BB#0:
+; CHECK-NEXT: cmpq $1, %rdi
+; CHECK-NEXT: sbbq %rax, %rax
+; CHECK-NEXT: retq
+ %cmp = icmp eq i64 %x, 0
+ %sel = select i1 %cmp, i64 -1, i64 0
+ ret i64 %sel
+}
+
+; (X == 0) ? -1 : 0 --> 0 - (X == 0)
+
+define i32 @i32_select_neg1_or_0_as_math(i32 %x) {
+; CHECK-LABEL: i32_select_neg1_or_0_as_math:
+; CHECK: # BB#0:
+; CHECK-NEXT: cmpl $1, %edi
+; CHECK-NEXT: sbbl %eax, %eax
+; CHECK-NEXT: retq
+ %cmp = icmp eq i32 %x, 0
+ %ext = zext i1 %cmp to i32
+ %sub = sub i32 0, %ext
+ ret i32 %sub
+}
+
+; (X != 0) ? 0 : -1 --> (X != 0) - 1
+
+define i16 @i16_select_neg1_or_0_commuted(i16 %x) {
+; CHECK-LABEL: i16_select_neg1_or_0_commuted:
+; CHECK: # BB#0:
+; CHECK-NEXT: cmpw $1, %di
+; CHECK-NEXT: sbbw %ax, %ax
+; CHECK-NEXT: retq
+ %cmp = icmp ne i16 %x, 0
+ %sel = select i1 %cmp, i16 0, i16 -1
+ ret i16 %sel
+}
+
+; (X != 0) ? 0 : -1 --> (X != 0) - 1
+
+define i8 @i8_select_neg1_or_0_commuted_as_math(i8 %x) {
+; CHECK-LABEL: i8_select_neg1_or_0_commuted_as_math:
+; CHECK: # BB#0:
+; CHECK-NEXT: cmpb $1, %dil
+; CHECK-NEXT: sbbb %al, %al
+; CHECK-NEXT: retq
+ %cmp = icmp ne i8 %x, 0
+ %ext = zext i1 %cmp to i8
+ %add = add i8 %ext, -1
+ ret i8 %add
+}
+
+; Make sure we're creating nodes with the right value types. This would crash.
+; https://bugs.llvm.org/show_bug.cgi?id=33560
+
+define void @PR33560(i8 %x, i64 %y) {
+; CHECK-LABEL: PR33560:
+; CHECK: # BB#0: # %entry
+; CHECK-NEXT: negb %dil
+; CHECK-NEXT: sbbq %rax, %rax
+; CHECK-NEXT: cmpq %rsi, %rax
+; CHECK-NEXT: retq
+entry:
+ %cmp1 = icmp eq i8 %x, 0
+ %ext = zext i1 %cmp1 to i64
+ %add = add i64 %ext, -1
+ %cmp2 = icmp eq i64 %add, %y
+ br i1 %cmp2, label %end, label %else
+
+else:
+ %tmp7 = zext i1 %cmp1 to i8
+ br label %end
+
+end:
+ ret void
+}
+