[PATCH] D145001: [X86] Add additional tests for folding `(select (setgt X, -1), C, C+1)`; NFC

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 13:20:09 PST 2023


goldstein.w.n created this revision.
Herald added a subscriber: pengfei.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The goal of these tests is to hit more cases where typeof(X) != typeof(C).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145001

Files:
  llvm/test/CodeGen/X86/select-constant-xor.ll


Index: llvm/test/CodeGen/X86/select-constant-xor.ll
===================================================================
--- llvm/test/CodeGen/X86/select-constant-xor.ll
+++ llvm/test/CodeGen/X86/select-constant-xor.ll
@@ -256,6 +256,53 @@
   %x = add i32 %s, %s2
   ret i32 %x
 }
+
+define i32 @selecti16i32_offby1(i16 %a) {
+; X86-LABEL: selecti16i32_offby1:
+; X86:       # %bb.0:
+; X86-NEXT:    xorl %ecx, %ecx
+; X86-NEXT:    cmpw $0, {{[0-9]+}}(%esp)
+; X86-NEXT:    setns %cl
+; X86-NEXT:    movl $-2147483648, %eax # imm = 0x80000000
+; X86-NEXT:    subl %ecx, %eax
+; X86-NEXT:    retl
+;
+; X64-LABEL: selecti16i32_offby1:
+; X64:       # %bb.0:
+; X64-NEXT:    xorl %ecx, %ecx
+; X64-NEXT:    testw %di, %di
+; X64-NEXT:    setns %cl
+; X64-NEXT:    movl $-2147483648, %eax # imm = 0x80000000
+; X64-NEXT:    subl %ecx, %eax
+; X64-NEXT:    retq
+  %c = icmp sgt i16 %a, -1
+  %s = select i1 %c, i32 2147483647, i32 -2147483648
+  ret i32 %s
+}
+
+define i32 @selecti8i32_offby1(i8 %a) {
+; X86-LABEL: selecti8i32_offby1:
+; X86:       # %bb.0:
+; X86-NEXT:    xorl %ecx, %ecx
+; X86-NEXT:    cmpb $0, {{[0-9]+}}(%esp)
+; X86-NEXT:    setns %cl
+; X86-NEXT:    movl $-2147483648, %eax # imm = 0x80000000
+; X86-NEXT:    subl %ecx, %eax
+; X86-NEXT:    retl
+;
+; X64-LABEL: selecti8i32_offby1:
+; X64:       # %bb.0:
+; X64-NEXT:    xorl %ecx, %ecx
+; X64-NEXT:    testb %dil, %dil
+; X64-NEXT:    setns %cl
+; X64-NEXT:    movl $-2147483648, %eax # imm = 0x80000000
+; X64-NEXT:    subl %ecx, %eax
+; X64-NEXT:    retq
+  %c = icmp sgt i8 %a, -1
+  %s = select i1 %c, i32 2147483647, i32 -2147483648
+  ret i32 %s
+}
+
 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
 ; X64-FASTINC: {{.*}}
 ; X64-SLOWINC: {{.*}}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145001.501279.patch
Type: text/x-patch
Size: 1778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230228/d44e9b80/attachment.bin>


More information about the llvm-commits mailing list