diff --git a/llvm/test/CodeGen/X86/select-constant-xor.ll b/llvm/test/CodeGen/X86/select-constant-xor.ll --- a/llvm/test/CodeGen/X86/select-constant-xor.ll +++ b/llvm/test/CodeGen/X86/select-constant-xor.ll @@ -254,6 +254,115 @@ %x = add i32 %s, %s2 ret i32 %x } + +; we already have a test for the i64 case at `selecti64i32`. +define i32 @selecti16i32_offby1(i16 %a) { +; X86-LABEL: selecti16i32_offby1: +; X86: # %bb.0: +; X86-NEXT: xorl %eax, %eax +; X86-NEXT: cmpw $0, {{[0-9]+}}(%esp) +; X86-NEXT: sets %al +; X86-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X86-NEXT: retl +; +; X64-LABEL: selecti16i32_offby1: +; X64: # %bb.0: +; X64-NEXT: xorl %eax, %eax +; X64-NEXT: testw %di, %di +; X64-NEXT: sets %al +; X64-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; 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 %eax, %eax +; X86-NEXT: cmpb $0, {{[0-9]+}}(%esp) +; X86-NEXT: sets %al +; X86-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X86-NEXT: retl +; +; X64-LABEL: selecti8i32_offby1: +; X64: # %bb.0: +; X64-NEXT: xorl %eax, %eax +; X64-NEXT: testb %dil, %dil +; X64-NEXT: sets %al +; X64-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X64-NEXT: retq + %c = icmp sgt i8 %a, -1 + %s = select i1 %c, i32 2147483647, i32 -2147483648 + ret i32 %s +} + + +define i32 @selecti64i32_offby1_add(i64 %a) { +; X86-LABEL: selecti64i32_offby1_add: +; X86: # %bb.0: +; X86-NEXT: xorl %eax, %eax +; X86-NEXT: cmpl $0, {{[0-9]+}}(%esp) +; X86-NEXT: setns %al +; X86-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X86-NEXT: retl +; +; X64-LABEL: selecti64i32_offby1_add: +; X64: # %bb.0: +; X64-NEXT: xorl %eax, %eax +; X64-NEXT: testq %rdi, %rdi +; X64-NEXT: setns %al +; X64-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X64-NEXT: retq + %c = icmp sgt i64 %a, -1 + %s = select i1 %c, i32 2147483648, i32 2147483647 + ret i32 %s +} + +define i32 @selecti16i32_offby1_add(i16 %a) { +; X86-LABEL: selecti16i32_offby1_add: +; X86: # %bb.0: +; X86-NEXT: xorl %eax, %eax +; X86-NEXT: cmpw $0, {{[0-9]+}}(%esp) +; X86-NEXT: setns %al +; X86-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X86-NEXT: retl +; +; X64-LABEL: selecti16i32_offby1_add: +; X64: # %bb.0: +; X64-NEXT: xorl %eax, %eax +; X64-NEXT: testw %di, %di +; X64-NEXT: setns %al +; X64-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X64-NEXT: retq + %c = icmp sgt i16 %a, -1 + %s = select i1 %c, i32 2147483648, i32 2147483647 + ret i32 %s +} + +define i32 @selecti8i32_offby1_add(i8 %a) { +; X86-LABEL: selecti8i32_offby1_add: +; X86: # %bb.0: +; X86-NEXT: xorl %eax, %eax +; X86-NEXT: cmpb $0, {{[0-9]+}}(%esp) +; X86-NEXT: setns %al +; X86-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X86-NEXT: retl +; +; X64-LABEL: selecti8i32_offby1_add: +; X64: # %bb.0: +; X64-NEXT: xorl %eax, %eax +; X64-NEXT: testb %dil, %dil +; X64-NEXT: setns %al +; X64-NEXT: addl $2147483647, %eax # imm = 0x7FFFFFFF +; X64-NEXT: retq + %c = icmp sgt i8 %a, -1 + %s = select i1 %c, i32 2147483648, i32 2147483647 + ret i32 %s +} + + ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: ; X64-FASTINC: {{.*}} ; X64-SLOWINC: {{.*}}