From 8751bf94c8f2bd39752cde33f3eaab63c7c29ada Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 12 Jul 2017 17:44:50 +0000 Subject: [PATCH] [x86] add tests for improving sbb transforms; NFC We're subtracting X from X the hard way... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307819 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/X86/sbb.ll | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/CodeGen/X86/sbb.ll b/test/CodeGen/X86/sbb.ll index 027ae95c30d..e5025dc13c8 100644 --- a/test/CodeGen/X86/sbb.ll +++ b/test/CodeGen/X86/sbb.ll @@ -185,6 +185,41 @@ define i32 @uge_select_0_or_neg1_sub(i32 %x, i32 %y) nounwind { ret i32 %sub } +; Check more sub-from-zero patterns. +; (X >u Y) ? -1 : 0 --> cmp, sbb + +define i64 @ugt_select_neg1_or_0_sub(i64 %x, i64 %y) nounwind { +; CHECK-LABEL: ugt_select_neg1_or_0_sub: +; CHECK: # BB#0: +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: cmpq %rdi, %rsi +; CHECK-NEXT: sbbq $0, %rax +; CHECK-NEXT: retq + %cmp = icmp ugt i64 %x, %y + %zext = zext i1 %cmp to i64 + %sub = sub i64 0, %zext + ret i64 %sub +} + +; Swap the predicate and compare operands: +; (Y cmp, sbb + +define i16 @ult_select_neg1_or_0_sub(i16 %x, i16 %y) nounwind { +; CHECK-LABEL: ult_select_neg1_or_0_sub: +; CHECK: # BB#0: +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: cmpw %di, %si +; CHECK-NEXT: sbbl $0, %eax +; CHECK-NEXT: # kill: %AX %AX %EAX +; CHECK-NEXT: retq + %cmp = icmp ult i16 %y, %x + %zext = zext i1 %cmp to i16 + %sub = sub i16 0, %zext + ret i16 %sub +} + + + ; Make sure we're creating nodes with the right value types. This would crash. ; https://bugs.llvm.org/show_bug.cgi?id=33560 -- 2.50.1