diff --git a/llvm/test/CodeGen/X86/64-bit-shift-by-32-minus-y.ll b/llvm/test/CodeGen/X86/64-bit-shift-by-32-minus-y.ll new file mode 100644 index 000000000000..87dc69bea030 --- /dev/null +++ b/llvm/test/CodeGen/X86/64-bit-shift-by-32-minus-y.ll @@ -0,0 +1,367 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefixes=X64-NOBMI2 +; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi2 | FileCheck %s --check-prefixes=X64-BMI2 +; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefixes=X32-NOBMI2 +; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+bmi2 | FileCheck %s --check-prefixes=X32-BMI2 + +define i64 @t0(i64 %val, i64 %shamt) nounwind { +; X64-NOBMI2-LABEL: t0: +; X64-NOBMI2: # %bb.0: +; X64-NOBMI2-NEXT: movq %rdi, %rax +; X64-NOBMI2-NEXT: movb $32, %cl +; X64-NOBMI2-NEXT: subb %sil, %cl +; X64-NOBMI2-NEXT: shlq %cl, %rax +; X64-NOBMI2-NEXT: retq +; +; X64-BMI2-LABEL: t0: +; X64-BMI2: # %bb.0: +; X64-BMI2-NEXT: movb $32, %al +; X64-BMI2-NEXT: subb %sil, %al +; X64-BMI2-NEXT: shlxq %rax, %rdi, %rax +; X64-BMI2-NEXT: retq +; +; X32-NOBMI2-LABEL: t0: +; X32-NOBMI2: # %bb.0: +; X32-NOBMI2-NEXT: pushl %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-NOBMI2-NEXT: movb $32, %cl +; X32-NOBMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-NOBMI2-NEXT: movl %esi, %eax +; X32-NOBMI2-NEXT: shll %cl, %eax +; X32-NOBMI2-NEXT: shldl %cl, %esi, %edx +; X32-NOBMI2-NEXT: testb $32, %cl +; X32-NOBMI2-NEXT: je .LBB0_2 +; X32-NOBMI2-NEXT: # %bb.1: +; X32-NOBMI2-NEXT: movl %eax, %edx +; X32-NOBMI2-NEXT: xorl %eax, %eax +; X32-NOBMI2-NEXT: .LBB0_2: +; X32-NOBMI2-NEXT: popl %esi +; X32-NOBMI2-NEXT: retl +; +; X32-BMI2-LABEL: t0: +; X32-BMI2: # %bb.0: +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-BMI2-NEXT: movb $32, %cl +; X32-BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-BMI2-NEXT: shldl %cl, %eax, %edx +; X32-BMI2-NEXT: shlxl %ecx, %eax, %eax +; X32-BMI2-NEXT: testb $32, %cl +; X32-BMI2-NEXT: je .LBB0_2 +; X32-BMI2-NEXT: # %bb.1: +; X32-BMI2-NEXT: movl %eax, %edx +; X32-BMI2-NEXT: xorl %eax, %eax +; X32-BMI2-NEXT: .LBB0_2: +; X32-BMI2-NEXT: retl + %negshamt = sub i64 32, %shamt + %shifted = shl i64 %val, %negshamt + ret i64 %shifted +} + +; The constant we are subtracting from should be a multiple of 32. +define i64 @n1(i64 %val, i64 %shamt) nounwind { +; X64-NOBMI2-LABEL: n1: +; X64-NOBMI2: # %bb.0: +; X64-NOBMI2-NEXT: movq %rdi, %rax +; X64-NOBMI2-NEXT: movb $33, %cl +; X64-NOBMI2-NEXT: subb %sil, %cl +; X64-NOBMI2-NEXT: shlq %cl, %rax +; X64-NOBMI2-NEXT: retq +; +; X64-BMI2-LABEL: n1: +; X64-BMI2: # %bb.0: +; X64-BMI2-NEXT: movb $33, %al +; X64-BMI2-NEXT: subb %sil, %al +; X64-BMI2-NEXT: shlxq %rax, %rdi, %rax +; X64-BMI2-NEXT: retq +; +; X32-NOBMI2-LABEL: n1: +; X32-NOBMI2: # %bb.0: +; X32-NOBMI2-NEXT: pushl %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-NOBMI2-NEXT: movb $33, %cl +; X32-NOBMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-NOBMI2-NEXT: movl %esi, %eax +; X32-NOBMI2-NEXT: shll %cl, %eax +; X32-NOBMI2-NEXT: shldl %cl, %esi, %edx +; X32-NOBMI2-NEXT: testb $32, %cl +; X32-NOBMI2-NEXT: je .LBB1_2 +; X32-NOBMI2-NEXT: # %bb.1: +; X32-NOBMI2-NEXT: movl %eax, %edx +; X32-NOBMI2-NEXT: xorl %eax, %eax +; X32-NOBMI2-NEXT: .LBB1_2: +; X32-NOBMI2-NEXT: popl %esi +; X32-NOBMI2-NEXT: retl +; +; X32-BMI2-LABEL: n1: +; X32-BMI2: # %bb.0: +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-BMI2-NEXT: movb $33, %cl +; X32-BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-BMI2-NEXT: shldl %cl, %eax, %edx +; X32-BMI2-NEXT: shlxl %ecx, %eax, %eax +; X32-BMI2-NEXT: testb $32, %cl +; X32-BMI2-NEXT: je .LBB1_2 +; X32-BMI2-NEXT: # %bb.1: +; X32-BMI2-NEXT: movl %eax, %edx +; X32-BMI2-NEXT: xorl %eax, %eax +; X32-BMI2-NEXT: .LBB1_2: +; X32-BMI2-NEXT: retl + %negshamt = sub i64 33, %shamt + %shifted = shl i64 %val, %negshamt + ret i64 %shifted +} +define i64 @n2(i64 %val, i64 %shamt) nounwind { +; X64-NOBMI2-LABEL: n2: +; X64-NOBMI2: # %bb.0: +; X64-NOBMI2-NEXT: movq %rdi, %rax +; X64-NOBMI2-NEXT: movb $31, %cl +; X64-NOBMI2-NEXT: subb %sil, %cl +; X64-NOBMI2-NEXT: shlq %cl, %rax +; X64-NOBMI2-NEXT: retq +; +; X64-BMI2-LABEL: n2: +; X64-BMI2: # %bb.0: +; X64-BMI2-NEXT: movb $31, %al +; X64-BMI2-NEXT: subb %sil, %al +; X64-BMI2-NEXT: shlxq %rax, %rdi, %rax +; X64-BMI2-NEXT: retq +; +; X32-NOBMI2-LABEL: n2: +; X32-NOBMI2: # %bb.0: +; X32-NOBMI2-NEXT: pushl %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-NOBMI2-NEXT: movb $31, %cl +; X32-NOBMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-NOBMI2-NEXT: movl %esi, %eax +; X32-NOBMI2-NEXT: shll %cl, %eax +; X32-NOBMI2-NEXT: shldl %cl, %esi, %edx +; X32-NOBMI2-NEXT: testb $32, %cl +; X32-NOBMI2-NEXT: je .LBB2_2 +; X32-NOBMI2-NEXT: # %bb.1: +; X32-NOBMI2-NEXT: movl %eax, %edx +; X32-NOBMI2-NEXT: xorl %eax, %eax +; X32-NOBMI2-NEXT: .LBB2_2: +; X32-NOBMI2-NEXT: popl %esi +; X32-NOBMI2-NEXT: retl +; +; X32-BMI2-LABEL: n2: +; X32-BMI2: # %bb.0: +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-BMI2-NEXT: movb $31, %cl +; X32-BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-BMI2-NEXT: shldl %cl, %eax, %edx +; X32-BMI2-NEXT: shlxl %ecx, %eax, %eax +; X32-BMI2-NEXT: testb $32, %cl +; X32-BMI2-NEXT: je .LBB2_2 +; X32-BMI2-NEXT: # %bb.1: +; X32-BMI2-NEXT: movl %eax, %edx +; X32-BMI2-NEXT: xorl %eax, %eax +; X32-BMI2-NEXT: .LBB2_2: +; X32-BMI2-NEXT: retl + %negshamt = sub i64 31, %shamt + %shifted = shl i64 %val, %negshamt + ret i64 %shifted +} + +define i64 @t3(i64 %val, i64 %shamt) nounwind { +; X64-NOBMI2-LABEL: t3: +; X64-NOBMI2: # %bb.0: +; X64-NOBMI2-NEXT: movq %rsi, %rcx +; X64-NOBMI2-NEXT: movq %rdi, %rax +; X64-NOBMI2-NEXT: negb %cl +; X64-NOBMI2-NEXT: # kill: def $cl killed $cl killed $rcx +; X64-NOBMI2-NEXT: shlq %cl, %rax +; X64-NOBMI2-NEXT: retq +; +; X64-BMI2-LABEL: t3: +; X64-BMI2: # %bb.0: +; X64-BMI2-NEXT: negb %sil +; X64-BMI2-NEXT: shlxq %rsi, %rdi, %rax +; X64-BMI2-NEXT: retq +; +; X32-NOBMI2-LABEL: t3: +; X32-NOBMI2: # %bb.0: +; X32-NOBMI2-NEXT: pushl %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-NOBMI2-NEXT: movb $64, %cl +; X32-NOBMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-NOBMI2-NEXT: movl %esi, %eax +; X32-NOBMI2-NEXT: shll %cl, %eax +; X32-NOBMI2-NEXT: shldl %cl, %esi, %edx +; X32-NOBMI2-NEXT: testb $32, %cl +; X32-NOBMI2-NEXT: je .LBB3_2 +; X32-NOBMI2-NEXT: # %bb.1: +; X32-NOBMI2-NEXT: movl %eax, %edx +; X32-NOBMI2-NEXT: xorl %eax, %eax +; X32-NOBMI2-NEXT: .LBB3_2: +; X32-NOBMI2-NEXT: popl %esi +; X32-NOBMI2-NEXT: retl +; +; X32-BMI2-LABEL: t3: +; X32-BMI2: # %bb.0: +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-BMI2-NEXT: movb $64, %cl +; X32-BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-BMI2-NEXT: shldl %cl, %eax, %edx +; X32-BMI2-NEXT: shlxl %ecx, %eax, %eax +; X32-BMI2-NEXT: testb $32, %cl +; X32-BMI2-NEXT: je .LBB3_2 +; X32-BMI2-NEXT: # %bb.1: +; X32-BMI2-NEXT: movl %eax, %edx +; X32-BMI2-NEXT: xorl %eax, %eax +; X32-BMI2-NEXT: .LBB3_2: +; X32-BMI2-NEXT: retl + %negshamt = sub i64 64, %shamt + %shifted = shl i64 %val, %negshamt + ret i64 %shifted +} + +define i64 @t4(i64 %val, i64 %shamt) nounwind { +; X64-NOBMI2-LABEL: t4: +; X64-NOBMI2: # %bb.0: +; X64-NOBMI2-NEXT: movq %rdi, %rax +; X64-NOBMI2-NEXT: movb $96, %cl +; X64-NOBMI2-NEXT: subb %sil, %cl +; X64-NOBMI2-NEXT: shlq %cl, %rax +; X64-NOBMI2-NEXT: retq +; +; X64-BMI2-LABEL: t4: +; X64-BMI2: # %bb.0: +; X64-BMI2-NEXT: movb $96, %al +; X64-BMI2-NEXT: subb %sil, %al +; X64-BMI2-NEXT: shlxq %rax, %rdi, %rax +; X64-BMI2-NEXT: retq +; +; X32-NOBMI2-LABEL: t4: +; X32-NOBMI2: # %bb.0: +; X32-NOBMI2-NEXT: pushl %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-NOBMI2-NEXT: movb $96, %cl +; X32-NOBMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-NOBMI2-NEXT: movl %esi, %eax +; X32-NOBMI2-NEXT: shll %cl, %eax +; X32-NOBMI2-NEXT: shldl %cl, %esi, %edx +; X32-NOBMI2-NEXT: testb $32, %cl +; X32-NOBMI2-NEXT: je .LBB4_2 +; X32-NOBMI2-NEXT: # %bb.1: +; X32-NOBMI2-NEXT: movl %eax, %edx +; X32-NOBMI2-NEXT: xorl %eax, %eax +; X32-NOBMI2-NEXT: .LBB4_2: +; X32-NOBMI2-NEXT: popl %esi +; X32-NOBMI2-NEXT: retl +; +; X32-BMI2-LABEL: t4: +; X32-BMI2: # %bb.0: +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-BMI2-NEXT: movb $96, %cl +; X32-BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl +; X32-BMI2-NEXT: shldl %cl, %eax, %edx +; X32-BMI2-NEXT: shlxl %ecx, %eax, %eax +; X32-BMI2-NEXT: testb $32, %cl +; X32-BMI2-NEXT: je .LBB4_2 +; X32-BMI2-NEXT: # %bb.1: +; X32-BMI2-NEXT: movl %eax, %edx +; X32-BMI2-NEXT: xorl %eax, %eax +; X32-BMI2-NEXT: .LBB4_2: +; X32-BMI2-NEXT: retl + %negshamt = sub i64 96, %shamt + %shifted = shl i64 %val, %negshamt + ret i64 %shifted +} + +define i64 @t5_cse(i64 %val, i64 %shamt, i64*%dst) nounwind { +; X64-NOBMI2-LABEL: t5_cse: +; X64-NOBMI2: # %bb.0: +; X64-NOBMI2-NEXT: movq %rdi, %rax +; X64-NOBMI2-NEXT: leaq 32(%rsi), %rcx +; X64-NOBMI2-NEXT: movq %rcx, (%rdx) +; X64-NOBMI2-NEXT: movb $32, %cl +; X64-NOBMI2-NEXT: subb %sil, %cl +; X64-NOBMI2-NEXT: shlq %cl, %rax +; X64-NOBMI2-NEXT: retq +; +; X64-BMI2-LABEL: t5_cse: +; X64-BMI2: # %bb.0: +; X64-BMI2-NEXT: leaq 32(%rsi), %rax +; X64-BMI2-NEXT: movq %rax, (%rdx) +; X64-BMI2-NEXT: movb $32, %al +; X64-BMI2-NEXT: subb %sil, %al +; X64-BMI2-NEXT: shlxq %rax, %rdi, %rax +; X64-BMI2-NEXT: retq +; +; X32-NOBMI2-LABEL: t5_cse: +; X32-NOBMI2: # %bb.0: +; X32-NOBMI2-NEXT: pushl %ebx +; X32-NOBMI2-NEXT: pushl %edi +; X32-NOBMI2-NEXT: pushl %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-NOBMI2-NEXT: movl {{[0-9]+}}(%esp), %edi +; X32-NOBMI2-NEXT: movl %eax, %ebx +; X32-NOBMI2-NEXT: addl $32, %ebx +; X32-NOBMI2-NEXT: adcl $0, %edi +; X32-NOBMI2-NEXT: movl %ebx, (%ecx) +; X32-NOBMI2-NEXT: movl %edi, 4(%ecx) +; X32-NOBMI2-NEXT: movb $32, %cl +; X32-NOBMI2-NEXT: subb %al, %cl +; X32-NOBMI2-NEXT: movl %esi, %eax +; X32-NOBMI2-NEXT: shll %cl, %eax +; X32-NOBMI2-NEXT: shldl %cl, %esi, %edx +; X32-NOBMI2-NEXT: testb $32, %cl +; X32-NOBMI2-NEXT: je .LBB5_2 +; X32-NOBMI2-NEXT: # %bb.1: +; X32-NOBMI2-NEXT: movl %eax, %edx +; X32-NOBMI2-NEXT: xorl %eax, %eax +; X32-NOBMI2-NEXT: .LBB5_2: +; X32-NOBMI2-NEXT: popl %esi +; X32-NOBMI2-NEXT: popl %edi +; X32-NOBMI2-NEXT: popl %ebx +; X32-NOBMI2-NEXT: retl +; +; X32-BMI2-LABEL: t5_cse: +; X32-BMI2: # %bb.0: +; X32-BMI2-NEXT: pushl %ebx +; X32-BMI2-NEXT: pushl %edi +; X32-BMI2-NEXT: pushl %esi +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax +; X32-BMI2-NEXT: movl {{[0-9]+}}(%esp), %edi +; X32-BMI2-NEXT: movl %eax, %ebx +; X32-BMI2-NEXT: addl $32, %ebx +; X32-BMI2-NEXT: adcl $0, %edi +; X32-BMI2-NEXT: movl %ebx, (%ecx) +; X32-BMI2-NEXT: movl %edi, 4(%ecx) +; X32-BMI2-NEXT: movb $32, %cl +; X32-BMI2-NEXT: subb %al, %cl +; X32-BMI2-NEXT: shldl %cl, %esi, %edx +; X32-BMI2-NEXT: shlxl %ecx, %esi, %eax +; X32-BMI2-NEXT: testb $32, %cl +; X32-BMI2-NEXT: je .LBB5_2 +; X32-BMI2-NEXT: # %bb.1: +; X32-BMI2-NEXT: movl %eax, %edx +; X32-BMI2-NEXT: xorl %eax, %eax +; X32-BMI2-NEXT: .LBB5_2: +; X32-BMI2-NEXT: popl %esi +; X32-BMI2-NEXT: popl %edi +; X32-BMI2-NEXT: popl %ebx +; X32-BMI2-NEXT: retl + %incshamt = add i64 %shamt, 32 + store i64 %incshamt, i64* %dst + %negshamt = sub i64 32, %shamt + %shifted = shl i64 %val, %negshamt + ret i64 %shifted +}