Index: test/CodeGen/X86/clear-highbits.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/clear-highbits.ll @@ -0,0 +1,673 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOTRANSFORM,X86-NOTRANSFORM,FALLBACK0,X86-FALLBACK0 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOTRANSFORM,X86-NOTRANSFORM,FALLBACK1,X86-FALLBACK1 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOTRANSFORM,X86-NOTRANSFORM,FALLBACK2,X86-FALLBACK2 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,TRANSFORM,X86-TRANSFORM,FALLBACK3,X86-FALLBACK3 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,TRANSFORM,X86-TRANSFORM,FALLBACK4,X86-FALLBACK4 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOTRANSFORM,X64-NOTRANSFORM,FALLBACK0,X64-FALLBACK0 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOTRANSFORM,X64-NOTRANSFORM,FALLBACK1,X64-FALLBACK1 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOTRANSFORM,X64-NOTRANSFORM,FALLBACK2,X64-FALLBACK2 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,TRANSFORM,X64-TRANSFORM,FALLBACK3,X64-FALLBACK3 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,TRANSFORM,X64-TRANSFORM,FALLBACK4,X64-FALLBACK4 + +; Patterns: +; c) x & (-1 >> y) +; d) x << y >> y +; are equivalent, but we prefer the second variant if we have BMI2. + +; We do not test the variant where y = (32 - z), because that is BMI2's BZHI. + +; ---------------------------------------------------------------------------- ; +; Pattern c. 32-bit +; ---------------------------------------------------------------------------- ; + +define i32 @clear_highbits32_c0(i32 %val, i32 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits32_c0: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shrl %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits32_c0: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shrxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits32_c0: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrl %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits32_c0: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shrxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %mask = lshr i32 -1, %numhighbits + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_highbits32_c1_indexzext(i32 %val, i8 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits32_c1_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shrl %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits32_c1_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shrxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits32_c1_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrl %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits32_c1_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shrxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %sh_prom = zext i8 %numhighbits to i32 + %mask = lshr i32 -1, %sh_prom + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_highbits32_c2_load(i32* %w, i32 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits32_c2_load: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shrl %cl, %eax +; X86-NOTRANSFORM-NEXT: andl (%edx), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits32_c2_load: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shrxl %eax, %edx, %eax +; X86-TRANSFORM-NEXT: andl (%ecx), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits32_c2_load: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrl %cl, %eax +; X64-NOTRANSFORM-NEXT: andl (%rdi), %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits32_c2_load: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shrxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl (%rdi), %eax +; X64-TRANSFORM-NEXT: retq + %val = load i32, i32* %w + %mask = lshr i32 -1, %numhighbits + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_highbits32_c3_load_indexzext(i32* %w, i8 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits32_c3_load_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shrl %cl, %eax +; X86-NOTRANSFORM-NEXT: andl (%edx), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits32_c3_load_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shrxl %eax, %edx, %eax +; X86-TRANSFORM-NEXT: andl (%ecx), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits32_c3_load_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrl %cl, %eax +; X64-NOTRANSFORM-NEXT: andl (%rdi), %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits32_c3_load_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shrxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl (%rdi), %eax +; X64-TRANSFORM-NEXT: retq + %val = load i32, i32* %w + %sh_prom = zext i8 %numhighbits to i32 + %mask = lshr i32 -1, %sh_prom + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_highbits32_c4_commutative(i32 %val, i32 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits32_c4_commutative: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shrl %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits32_c4_commutative: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shrxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits32_c4_commutative: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrl %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits32_c4_commutative: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shrxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %mask = lshr i32 -1, %numhighbits + %masked = and i32 %val, %mask ; swapped order + ret i32 %masked +} + +; 64-bit + +define i64 @clear_highbits64_c0(i64 %val, i64 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits64_c0: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: shrl %cl, %edx +; X86-NOTRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB5_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edx, %eax +; X86-NOTRANSFORM-NEXT: xorl %edx, %edx +; X86-NOTRANSFORM-NEXT: .LBB5_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits64_c0: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %eax +; X86-TRANSFORM-NEXT: shrxl %ecx, %eax, %edx +; X86-TRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB5_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edx, %eax +; X86-TRANSFORM-NEXT: xorl %edx, %edx +; X86-TRANSFORM-NEXT: .LBB5_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits64_c0: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits64_c0: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shrxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %mask = lshr i64 -1, %numhighbits + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_highbits64_c1_indexzext(i64 %val, i8 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits64_c1_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: shrl %cl, %edx +; X86-NOTRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB6_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edx, %eax +; X86-NOTRANSFORM-NEXT: xorl %edx, %edx +; X86-NOTRANSFORM-NEXT: .LBB6_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits64_c1_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %eax +; X86-TRANSFORM-NEXT: shrxl %ecx, %eax, %edx +; X86-TRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB6_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edx, %eax +; X86-TRANSFORM-NEXT: xorl %edx, %edx +; X86-TRANSFORM-NEXT: .LBB6_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits64_c1_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits64_c1_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: # kill: def $esi killed $esi def $rsi +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shrxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %sh_prom = zext i8 %numhighbits to i64 + %mask = lshr i64 -1, %sh_prom + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_highbits64_c2_load(i64* %w, i64 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits64_c2_load: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: shrl %cl, %edx +; X86-NOTRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB7_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edx, %eax +; X86-NOTRANSFORM-NEXT: xorl %edx, %edx +; X86-NOTRANSFORM-NEXT: .LBB7_2: +; X86-NOTRANSFORM-NEXT: andl (%esi), %eax +; X86-NOTRANSFORM-NEXT: andl 4(%esi), %edx +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits64_c2_load: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %eax +; X86-TRANSFORM-NEXT: shrxl %ecx, %eax, %edx +; X86-TRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB7_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edx, %eax +; X86-TRANSFORM-NEXT: xorl %edx, %edx +; X86-TRANSFORM-NEXT: .LBB7_2: +; X86-TRANSFORM-NEXT: andl (%esi), %eax +; X86-TRANSFORM-NEXT: andl 4(%esi), %edx +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits64_c2_load: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq (%rdi), %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits64_c2_load: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shrxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq (%rdi), %rax +; X64-TRANSFORM-NEXT: retq + %val = load i64, i64* %w + %mask = lshr i64 -1, %numhighbits + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_highbits64_c3_load_indexzext(i64* %w, i8 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits64_c3_load_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: shrl %cl, %edx +; X86-NOTRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB8_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edx, %eax +; X86-NOTRANSFORM-NEXT: xorl %edx, %edx +; X86-NOTRANSFORM-NEXT: .LBB8_2: +; X86-NOTRANSFORM-NEXT: andl (%esi), %eax +; X86-NOTRANSFORM-NEXT: andl 4(%esi), %edx +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits64_c3_load_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %eax +; X86-TRANSFORM-NEXT: shrxl %ecx, %eax, %edx +; X86-TRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB8_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edx, %eax +; X86-TRANSFORM-NEXT: xorl %edx, %edx +; X86-TRANSFORM-NEXT: .LBB8_2: +; X86-TRANSFORM-NEXT: andl (%esi), %eax +; X86-TRANSFORM-NEXT: andl 4(%esi), %edx +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits64_c3_load_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq (%rdi), %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits64_c3_load_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: # kill: def $esi killed $esi def $rsi +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shrxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq (%rdi), %rax +; X64-TRANSFORM-NEXT: retq + %val = load i64, i64* %w + %sh_prom = zext i8 %numhighbits to i64 + %mask = lshr i64 -1, %sh_prom + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_highbits64_c4_commutative(i64 %val, i64 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_highbits64_c4_commutative: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: shrl %cl, %edx +; X86-NOTRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB9_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edx, %eax +; X86-NOTRANSFORM-NEXT: xorl %edx, %edx +; X86-NOTRANSFORM-NEXT: .LBB9_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_highbits64_c4_commutative: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %eax +; X86-TRANSFORM-NEXT: shrxl %ecx, %eax, %edx +; X86-TRANSFORM-NEXT: shrdl %cl, %eax, %eax +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB9_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edx, %eax +; X86-TRANSFORM-NEXT: xorl %edx, %edx +; X86-TRANSFORM-NEXT: .LBB9_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_highbits64_c4_commutative: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_highbits64_c4_commutative: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shrxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %mask = lshr i64 -1, %numhighbits + %masked = and i64 %val, %mask ; swapped order + ret i64 %masked +} + +; ---------------------------------------------------------------------------- ; +; Multi-use tests +; ---------------------------------------------------------------------------- ; + +declare void @use32(i32) +declare void @use64(i64) + +define i32 @oneuse32(i32 %val, i32 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: oneuse32: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: subl $8, %esp +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %esi +; X86-NOTRANSFORM-NEXT: shrl %cl, %esi +; X86-NOTRANSFORM-NEXT: movl %esi, (%esp) +; X86-NOTRANSFORM-NEXT: calll use32 +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movl %esi, %eax +; X86-NOTRANSFORM-NEXT: addl $8, %esp +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: oneuse32: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: subl $8, %esp +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shrxl %eax, %ecx, %esi +; X86-TRANSFORM-NEXT: movl %esi, (%esp) +; X86-TRANSFORM-NEXT: calll use32 +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movl %esi, %eax +; X86-TRANSFORM-NEXT: addl $8, %esp +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: oneuse32: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: pushq %rbp +; X64-NOTRANSFORM-NEXT: pushq %rbx +; X64-NOTRANSFORM-NEXT: pushq %rax +; X64-NOTRANSFORM-NEXT: movl %edi, %ebx +; X64-NOTRANSFORM-NEXT: movl $-1, %ebp +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrl %cl, %ebp +; X64-NOTRANSFORM-NEXT: movl %ebp, %edi +; X64-NOTRANSFORM-NEXT: callq use32 +; X64-NOTRANSFORM-NEXT: andl %ebx, %ebp +; X64-NOTRANSFORM-NEXT: movl %ebp, %eax +; X64-NOTRANSFORM-NEXT: addq $8, %rsp +; X64-NOTRANSFORM-NEXT: popq %rbx +; X64-NOTRANSFORM-NEXT: popq %rbp +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: oneuse32: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: pushq %rbp +; X64-TRANSFORM-NEXT: pushq %rbx +; X64-TRANSFORM-NEXT: pushq %rax +; X64-TRANSFORM-NEXT: movl %edi, %ebx +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shrxl %esi, %eax, %ebp +; X64-TRANSFORM-NEXT: movl %ebp, %edi +; X64-TRANSFORM-NEXT: callq use32 +; X64-TRANSFORM-NEXT: andl %ebx, %ebp +; X64-TRANSFORM-NEXT: movl %ebp, %eax +; X64-TRANSFORM-NEXT: addq $8, %rsp +; X64-TRANSFORM-NEXT: popq %rbx +; X64-TRANSFORM-NEXT: popq %rbp +; X64-TRANSFORM-NEXT: retq + %mask = lshr i32 -1, %numhighbits + call void @use32(i32 %mask) + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i64 @oneuse64(i64 %val, i64 %numhighbits) nounwind { +; X86-NOTRANSFORM-LABEL: oneuse64: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %edi +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: pushl %eax +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %esi +; X86-NOTRANSFORM-NEXT: movl $-1, %edi +; X86-NOTRANSFORM-NEXT: shrl %cl, %edi +; X86-NOTRANSFORM-NEXT: shrdl %cl, %esi, %esi +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB11_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edi, %esi +; X86-NOTRANSFORM-NEXT: xorl %edi, %edi +; X86-NOTRANSFORM-NEXT: .LBB11_2: +; X86-NOTRANSFORM-NEXT: subl $8, %esp +; X86-NOTRANSFORM-NEXT: pushl %edi +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: calll use64 +; X86-NOTRANSFORM-NEXT: addl $16, %esp +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edi +; X86-NOTRANSFORM-NEXT: movl %esi, %eax +; X86-NOTRANSFORM-NEXT: movl %edi, %edx +; X86-NOTRANSFORM-NEXT: addl $4, %esp +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: popl %edi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: oneuse64: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %edi +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: pushl %eax +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %esi +; X86-TRANSFORM-NEXT: shrxl %ecx, %esi, %edi +; X86-TRANSFORM-NEXT: shrdl %cl, %esi, %esi +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB11_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edi, %esi +; X86-TRANSFORM-NEXT: xorl %edi, %edi +; X86-TRANSFORM-NEXT: .LBB11_2: +; X86-TRANSFORM-NEXT: subl $8, %esp +; X86-TRANSFORM-NEXT: pushl %edi +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: calll use64 +; X86-TRANSFORM-NEXT: addl $16, %esp +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edi +; X86-TRANSFORM-NEXT: movl %esi, %eax +; X86-TRANSFORM-NEXT: movl %edi, %edx +; X86-TRANSFORM-NEXT: addl $4, %esp +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: popl %edi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: oneuse64: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: pushq %r14 +; X64-NOTRANSFORM-NEXT: pushq %rbx +; X64-NOTRANSFORM-NEXT: pushq %rax +; X64-NOTRANSFORM-NEXT: movq %rdi, %r14 +; X64-NOTRANSFORM-NEXT: movq $-1, %rbx +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shrq %cl, %rbx +; X64-NOTRANSFORM-NEXT: movq %rbx, %rdi +; X64-NOTRANSFORM-NEXT: callq use64 +; X64-NOTRANSFORM-NEXT: andq %r14, %rbx +; X64-NOTRANSFORM-NEXT: movq %rbx, %rax +; X64-NOTRANSFORM-NEXT: addq $8, %rsp +; X64-NOTRANSFORM-NEXT: popq %rbx +; X64-NOTRANSFORM-NEXT: popq %r14 +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: oneuse64: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: pushq %r14 +; X64-TRANSFORM-NEXT: pushq %rbx +; X64-TRANSFORM-NEXT: pushq %rax +; X64-TRANSFORM-NEXT: movq %rdi, %r14 +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shrxq %rsi, %rax, %rbx +; X64-TRANSFORM-NEXT: movq %rbx, %rdi +; X64-TRANSFORM-NEXT: callq use64 +; X64-TRANSFORM-NEXT: andq %r14, %rbx +; X64-TRANSFORM-NEXT: movq %rbx, %rax +; X64-TRANSFORM-NEXT: addq $8, %rsp +; X64-TRANSFORM-NEXT: popq %rbx +; X64-TRANSFORM-NEXT: popq %r14 +; X64-TRANSFORM-NEXT: retq + %mask = lshr i64 -1, %numhighbits + call void @use64(i64 %mask) + %masked = and i64 %mask, %val + ret i64 %masked +} Index: test/CodeGen/X86/clear-lowbits.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/clear-lowbits.ll @@ -0,0 +1,1217 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOTRANSFORM,X86-NOTRANSFORM,FALLBACK0,X86-FALLBACK0 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOTRANSFORM,X86-NOTRANSFORM,FALLBACK1,X86-FALLBACK1 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOTRANSFORM,X86-NOTRANSFORM,FALLBACK2,X86-FALLBACK2 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,TRANSFORM,X86-TRANSFORM,FALLBACK3,X86-FALLBACK3 +; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,TRANSFORM,X86-TRANSFORM,FALLBACK4,X86-FALLBACK4 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOTRANSFORM,X64-NOTRANSFORM,FALLBACK0,X64-FALLBACK0 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOTRANSFORM,X64-NOTRANSFORM,FALLBACK1,X64-FALLBACK1 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOTRANSFORM,X64-NOTRANSFORM,FALLBACK2,X64-FALLBACK2 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,TRANSFORM,X64-TRANSFORM,FALLBACK3,X64-FALLBACK3 +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,TRANSFORM,X64-TRANSFORM,FALLBACK4,X64-FALLBACK4 + +; Patterns: +; c) x & (-1 << y) +; ic) x & (-1 << (32 - y)) +; d) x >> y << y +; id) x >> (32 - y) << (32 - y) +; are equivalent, but we prefer the second variant if we have BMI2. + +; ---------------------------------------------------------------------------- ; +; Pattern c. 32-bit +; ---------------------------------------------------------------------------- ; + +define i32 @clear_lowbits32_c0(i32 %val, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_c0: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_c0: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_c0: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_c0: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shlxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %mask = shl i32 -1, %numlowbits + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_c1_indexzext(i32 %val, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_c1_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_c1_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_c1_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_c1_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shlxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %sh_prom = zext i8 %numlowbits to i32 + %mask = shl i32 -1, %sh_prom + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_c2_load(i32* %w, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_c2_load: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl (%edx), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_c2_load: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %eax, %edx, %eax +; X86-TRANSFORM-NEXT: andl (%ecx), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_c2_load: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl (%rdi), %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_c2_load: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shlxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl (%rdi), %eax +; X64-TRANSFORM-NEXT: retq + %val = load i32, i32* %w + %mask = shl i32 -1, %numlowbits + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_c3_load_indexzext(i32* %w, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_c3_load_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl (%edx), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_c3_load_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %eax, %edx, %eax +; X86-TRANSFORM-NEXT: andl (%ecx), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_c3_load_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl (%rdi), %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_c3_load_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shlxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl (%rdi), %eax +; X64-TRANSFORM-NEXT: retq + %val = load i32, i32* %w + %sh_prom = zext i8 %numlowbits to i32 + %mask = shl i32 -1, %sh_prom + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_c4_commutative(i32 %val, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_c4_commutative: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_c4_commutative: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_c4_commutative: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_c4_commutative: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shlxl %esi, %eax, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %mask = shl i32 -1, %numlowbits + %masked = and i32 %val, %mask ; swapped order + ret i32 %masked +} + +; 64-bit + +define i64 @clear_lowbits64_c0(i64 %val, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_c0: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB5_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB5_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_c0: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB5_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB5_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_c0: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_c0: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shlxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %mask = shl i64 -1, %numlowbits + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_c1_indexzext(i64 %val, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_c1_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB6_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB6_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_c1_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB6_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB6_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_c1_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_c1_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: # kill: def $esi killed $esi def $rsi +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shlxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %sh_prom = zext i8 %numlowbits to i64 + %mask = shl i64 -1, %sh_prom + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_c2_load(i64* %w, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_c2_load: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB7_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB7_2: +; X86-NOTRANSFORM-NEXT: andl 4(%esi), %edx +; X86-NOTRANSFORM-NEXT: andl (%esi), %eax +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_c2_load: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB7_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB7_2: +; X86-TRANSFORM-NEXT: andl 4(%esi), %edx +; X86-TRANSFORM-NEXT: andl (%esi), %eax +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_c2_load: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq (%rdi), %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_c2_load: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shlxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq (%rdi), %rax +; X64-TRANSFORM-NEXT: retq + %val = load i64, i64* %w + %mask = shl i64 -1, %numlowbits + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_c3_load_indexzext(i64* %w, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_c3_load_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB8_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB8_2: +; X86-NOTRANSFORM-NEXT: andl 4(%esi), %edx +; X86-NOTRANSFORM-NEXT: andl (%esi), %eax +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_c3_load_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB8_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB8_2: +; X86-TRANSFORM-NEXT: andl 4(%esi), %edx +; X86-TRANSFORM-NEXT: andl (%esi), %eax +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_c3_load_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq (%rdi), %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_c3_load_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: # kill: def $esi killed $esi def $rsi +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shlxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq (%rdi), %rax +; X64-TRANSFORM-NEXT: retq + %val = load i64, i64* %w + %sh_prom = zext i8 %numlowbits to i64 + %mask = shl i64 -1, %sh_prom + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_c4_commutative(i64 %val, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_c4_commutative: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB9_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB9_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_c4_commutative: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB9_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB9_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_c4_commutative: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_c4_commutative: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shlxq %rsi, %rax, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %mask = shl i64 -1, %numlowbits + %masked = and i64 %val, %mask ; swapped order + ret i64 %masked +} + +; ---------------------------------------------------------------------------- ; +; Pattern ic. 32-bit +; ---------------------------------------------------------------------------- ; + +define i32 @clear_lowbits32_ic0(i32 %val, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_ic0: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl $32, %ecx +; X86-NOTRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_ic0: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl $32, %eax +; X86-TRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_ic0: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $32, %ecx +; X64-NOTRANSFORM-NEXT: subl %esi, %ecx +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_ic0: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $32, %eax +; X64-TRANSFORM-NEXT: subl %esi, %eax +; X64-TRANSFORM-NEXT: movl $-1, %ecx +; X64-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %numhighbits = sub i32 32, %numlowbits + %mask = shl i32 -1, %numhighbits + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_ic1_indexzext(i32 %val, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_ic1_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb $32, %cl +; X86-NOTRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_ic1_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb $32, %al +; X86-TRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_ic1_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movb $32, %cl +; X64-NOTRANSFORM-NEXT: subb %sil, %cl +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_ic1_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movb $32, %al +; X64-TRANSFORM-NEXT: subb %sil, %al +; X64-TRANSFORM-NEXT: movl $-1, %ecx +; X64-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %numhighbits = sub i8 32, %numlowbits + %sh_prom = zext i8 %numhighbits to i32 + %mask = shl i32 -1, %sh_prom + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_ic2_load(i32* %w, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_ic2_load: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: movl $32, %ecx +; X86-NOTRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl (%edx), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_ic2_load: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movl $32, %eax +; X86-TRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %eax, %edx, %eax +; X86-TRANSFORM-NEXT: andl (%ecx), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_ic2_load: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $32, %ecx +; X64-NOTRANSFORM-NEXT: subl %esi, %ecx +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl (%rdi), %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_ic2_load: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $32, %eax +; X64-TRANSFORM-NEXT: subl %esi, %eax +; X64-TRANSFORM-NEXT: movl $-1, %ecx +; X64-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X64-TRANSFORM-NEXT: andl (%rdi), %eax +; X64-TRANSFORM-NEXT: retq + %val = load i32, i32* %w + %numhighbits = sub i32 32, %numlowbits + %mask = shl i32 -1, %numhighbits + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_ic3_load_indexzext(i32* %w, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_ic3_load_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: movb $32, %cl +; X86-NOTRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl (%edx), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_ic3_load_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movb $32, %al +; X86-TRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %eax, %edx, %eax +; X86-TRANSFORM-NEXT: andl (%ecx), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_ic3_load_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movb $32, %cl +; X64-NOTRANSFORM-NEXT: subb %sil, %cl +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl (%rdi), %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_ic3_load_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movb $32, %al +; X64-TRANSFORM-NEXT: subb %sil, %al +; X64-TRANSFORM-NEXT: movl $-1, %ecx +; X64-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X64-TRANSFORM-NEXT: andl (%rdi), %eax +; X64-TRANSFORM-NEXT: retq + %val = load i32, i32* %w + %numhighbits = sub i8 32, %numlowbits + %sh_prom = zext i8 %numhighbits to i32 + %mask = shl i32 -1, %sh_prom + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i32 @clear_lowbits32_ic4_commutative(i32 %val, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits32_ic4_commutative: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl $32, %ecx +; X86-NOTRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits32_ic4_commutative: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl $32, %eax +; X86-TRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits32_ic4_commutative: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $32, %ecx +; X64-NOTRANSFORM-NEXT: subl %esi, %ecx +; X64-NOTRANSFORM-NEXT: movl $-1, %eax +; X64-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %eax +; X64-NOTRANSFORM-NEXT: andl %edi, %eax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits32_ic4_commutative: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $32, %eax +; X64-TRANSFORM-NEXT: subl %esi, %eax +; X64-TRANSFORM-NEXT: movl $-1, %ecx +; X64-TRANSFORM-NEXT: shlxl %eax, %ecx, %eax +; X64-TRANSFORM-NEXT: andl %edi, %eax +; X64-TRANSFORM-NEXT: retq + %numhighbits = sub i32 32, %numlowbits + %mask = shl i32 -1, %numhighbits + %masked = and i32 %val, %mask ; swapped order + ret i32 %masked +} + +; 64-bit + +define i64 @clear_lowbits64_ic0(i64 %val, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_ic0: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl $64, %ecx +; X86-NOTRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB15_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB15_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_ic0: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl $64, %ecx +; X86-TRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB15_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB15_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_ic0: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $64, %ecx +; X64-NOTRANSFORM-NEXT: subl %esi, %ecx +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_ic0: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $64, %eax +; X64-TRANSFORM-NEXT: subl %esi, %eax +; X64-TRANSFORM-NEXT: movq $-1, %rcx +; X64-TRANSFORM-NEXT: shlxq %rax, %rcx, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %numhighbits = sub i64 64, %numlowbits + %mask = shl i64 -1, %numhighbits + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_ic1_indexzext(i64 %val, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_ic1_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movb $64, %cl +; X86-NOTRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB16_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB16_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_ic1_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movb $64, %cl +; X86-TRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB16_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB16_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_ic1_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movb $64, %cl +; X64-NOTRANSFORM-NEXT: subb %sil, %cl +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_ic1_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movb $64, %al +; X64-TRANSFORM-NEXT: subb %sil, %al +; X64-TRANSFORM-NEXT: movq $-1, %rcx +; X64-TRANSFORM-NEXT: shlxq %rax, %rcx, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %numhighbits = sub i8 64, %numlowbits + %sh_prom = zext i8 %numhighbits to i64 + %mask = shl i64 -1, %sh_prom + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_ic2_load(i64* %w, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_ic2_load: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movl $64, %ecx +; X86-NOTRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB17_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB17_2: +; X86-NOTRANSFORM-NEXT: andl 4(%esi), %edx +; X86-NOTRANSFORM-NEXT: andl (%esi), %eax +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_ic2_load: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movl $64, %ecx +; X86-TRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB17_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB17_2: +; X86-TRANSFORM-NEXT: andl 4(%esi), %edx +; X86-TRANSFORM-NEXT: andl (%esi), %eax +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_ic2_load: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $64, %ecx +; X64-NOTRANSFORM-NEXT: subl %esi, %ecx +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq (%rdi), %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_ic2_load: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $64, %eax +; X64-TRANSFORM-NEXT: subl %esi, %eax +; X64-TRANSFORM-NEXT: movq $-1, %rcx +; X64-TRANSFORM-NEXT: shlxq %rax, %rcx, %rax +; X64-TRANSFORM-NEXT: andq (%rdi), %rax +; X64-TRANSFORM-NEXT: retq + %val = load i64, i64* %w + %numhighbits = sub i64 64, %numlowbits + %mask = shl i64 -1, %numhighbits + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_ic3_load_indexzext(i64* %w, i8 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_ic3_load_indexzext: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movb $64, %cl +; X86-NOTRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB18_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB18_2: +; X86-NOTRANSFORM-NEXT: andl 4(%esi), %edx +; X86-NOTRANSFORM-NEXT: andl (%esi), %eax +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_ic3_load_indexzext: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: movl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movb $64, %cl +; X86-TRANSFORM-NEXT: subb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB18_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB18_2: +; X86-TRANSFORM-NEXT: andl 4(%esi), %edx +; X86-TRANSFORM-NEXT: andl (%esi), %eax +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_ic3_load_indexzext: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movb $64, %cl +; X64-NOTRANSFORM-NEXT: subb %sil, %cl +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq (%rdi), %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_ic3_load_indexzext: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movb $64, %al +; X64-TRANSFORM-NEXT: subb %sil, %al +; X64-TRANSFORM-NEXT: movq $-1, %rcx +; X64-TRANSFORM-NEXT: shlxq %rax, %rcx, %rax +; X64-TRANSFORM-NEXT: andq (%rdi), %rax +; X64-TRANSFORM-NEXT: retq + %val = load i64, i64* %w + %numhighbits = sub i8 64, %numlowbits + %sh_prom = zext i8 %numhighbits to i64 + %mask = shl i64 -1, %sh_prom + %masked = and i64 %mask, %val + ret i64 %masked +} + +define i64 @clear_lowbits64_ic4_commutative(i64 %val, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: clear_lowbits64_ic4_commutative: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: movl $64, %ecx +; X86-NOTRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-NOTRANSFORM-NEXT: movl $-1, %edx +; X86-NOTRANSFORM-NEXT: movl $-1, %eax +; X86-NOTRANSFORM-NEXT: shll %cl, %eax +; X86-NOTRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB19_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %eax, %edx +; X86-NOTRANSFORM-NEXT: xorl %eax, %eax +; X86-NOTRANSFORM-NEXT: .LBB19_2: +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: clear_lowbits64_ic4_commutative: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: movl $64, %ecx +; X86-TRANSFORM-NEXT: subl {{[0-9]+}}(%esp), %ecx +; X86-TRANSFORM-NEXT: movl $-1, %edx +; X86-TRANSFORM-NEXT: shlxl %ecx, %edx, %eax +; X86-TRANSFORM-NEXT: shldl %cl, %edx, %edx +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB19_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %eax, %edx +; X86-TRANSFORM-NEXT: xorl %eax, %eax +; X86-TRANSFORM-NEXT: .LBB19_2: +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edx +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %eax +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: clear_lowbits64_ic4_commutative: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: movl $64, %ecx +; X64-NOTRANSFORM-NEXT: subl %esi, %ecx +; X64-NOTRANSFORM-NEXT: movq $-1, %rax +; X64-NOTRANSFORM-NEXT: # kill: def $cl killed $cl killed $ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rax +; X64-NOTRANSFORM-NEXT: andq %rdi, %rax +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: clear_lowbits64_ic4_commutative: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: movl $64, %eax +; X64-TRANSFORM-NEXT: subl %esi, %eax +; X64-TRANSFORM-NEXT: movq $-1, %rcx +; X64-TRANSFORM-NEXT: shlxq %rax, %rcx, %rax +; X64-TRANSFORM-NEXT: andq %rdi, %rax +; X64-TRANSFORM-NEXT: retq + %numhighbits = sub i64 64, %numlowbits + %mask = shl i64 -1, %numhighbits + %masked = and i64 %val, %mask ; swapped order + ret i64 %masked +} + +; ---------------------------------------------------------------------------- ; +; Multi-use tests +; ---------------------------------------------------------------------------- ; + +declare void @use32(i32) +declare void @use64(i64) + +define i32 @oneuse32(i32 %val, i32 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: oneuse32: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: subl $8, %esp +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %esi +; X86-NOTRANSFORM-NEXT: shll %cl, %esi +; X86-NOTRANSFORM-NEXT: movl %esi, (%esp) +; X86-NOTRANSFORM-NEXT: calll use32 +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: movl %esi, %eax +; X86-NOTRANSFORM-NEXT: addl $8, %esp +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: oneuse32: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: subl $8, %esp +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %al +; X86-TRANSFORM-NEXT: movl $-1, %ecx +; X86-TRANSFORM-NEXT: shlxl %eax, %ecx, %esi +; X86-TRANSFORM-NEXT: movl %esi, (%esp) +; X86-TRANSFORM-NEXT: calll use32 +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: movl %esi, %eax +; X86-TRANSFORM-NEXT: addl $8, %esp +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: oneuse32: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: pushq %rbp +; X64-NOTRANSFORM-NEXT: pushq %rbx +; X64-NOTRANSFORM-NEXT: pushq %rax +; X64-NOTRANSFORM-NEXT: movl %edi, %ebx +; X64-NOTRANSFORM-NEXT: movl $-1, %ebp +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shll %cl, %ebp +; X64-NOTRANSFORM-NEXT: movl %ebp, %edi +; X64-NOTRANSFORM-NEXT: callq use32 +; X64-NOTRANSFORM-NEXT: andl %ebx, %ebp +; X64-NOTRANSFORM-NEXT: movl %ebp, %eax +; X64-NOTRANSFORM-NEXT: addq $8, %rsp +; X64-NOTRANSFORM-NEXT: popq %rbx +; X64-NOTRANSFORM-NEXT: popq %rbp +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: oneuse32: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: pushq %rbp +; X64-TRANSFORM-NEXT: pushq %rbx +; X64-TRANSFORM-NEXT: pushq %rax +; X64-TRANSFORM-NEXT: movl %edi, %ebx +; X64-TRANSFORM-NEXT: movl $-1, %eax +; X64-TRANSFORM-NEXT: shlxl %esi, %eax, %ebp +; X64-TRANSFORM-NEXT: movl %ebp, %edi +; X64-TRANSFORM-NEXT: callq use32 +; X64-TRANSFORM-NEXT: andl %ebx, %ebp +; X64-TRANSFORM-NEXT: movl %ebp, %eax +; X64-TRANSFORM-NEXT: addq $8, %rsp +; X64-TRANSFORM-NEXT: popq %rbx +; X64-TRANSFORM-NEXT: popq %rbp +; X64-TRANSFORM-NEXT: retq + %mask = shl i32 -1, %numlowbits + call void @use32(i32 %mask) + %masked = and i32 %mask, %val + ret i32 %masked +} + +define i64 @oneuse64(i64 %val, i64 %numlowbits) nounwind { +; X86-NOTRANSFORM-LABEL: oneuse64: +; X86-NOTRANSFORM: # %bb.0: +; X86-NOTRANSFORM-NEXT: pushl %edi +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: pushl %eax +; X86-NOTRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-NOTRANSFORM-NEXT: movl $-1, %esi +; X86-NOTRANSFORM-NEXT: movl $-1, %edi +; X86-NOTRANSFORM-NEXT: shll %cl, %edi +; X86-NOTRANSFORM-NEXT: shldl %cl, %esi, %esi +; X86-NOTRANSFORM-NEXT: testb $32, %cl +; X86-NOTRANSFORM-NEXT: je .LBB21_2 +; X86-NOTRANSFORM-NEXT: # %bb.1: +; X86-NOTRANSFORM-NEXT: movl %edi, %esi +; X86-NOTRANSFORM-NEXT: xorl %edi, %edi +; X86-NOTRANSFORM-NEXT: .LBB21_2: +; X86-NOTRANSFORM-NEXT: subl $8, %esp +; X86-NOTRANSFORM-NEXT: pushl %esi +; X86-NOTRANSFORM-NEXT: pushl %edi +; X86-NOTRANSFORM-NEXT: calll use64 +; X86-NOTRANSFORM-NEXT: addl $16, %esp +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-NOTRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edi +; X86-NOTRANSFORM-NEXT: movl %edi, %eax +; X86-NOTRANSFORM-NEXT: movl %esi, %edx +; X86-NOTRANSFORM-NEXT: addl $4, %esp +; X86-NOTRANSFORM-NEXT: popl %esi +; X86-NOTRANSFORM-NEXT: popl %edi +; X86-NOTRANSFORM-NEXT: retl +; +; X86-TRANSFORM-LABEL: oneuse64: +; X86-TRANSFORM: # %bb.0: +; X86-TRANSFORM-NEXT: pushl %edi +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: pushl %eax +; X86-TRANSFORM-NEXT: movb {{[0-9]+}}(%esp), %cl +; X86-TRANSFORM-NEXT: movl $-1, %esi +; X86-TRANSFORM-NEXT: shlxl %ecx, %esi, %edi +; X86-TRANSFORM-NEXT: shldl %cl, %esi, %esi +; X86-TRANSFORM-NEXT: testb $32, %cl +; X86-TRANSFORM-NEXT: je .LBB21_2 +; X86-TRANSFORM-NEXT: # %bb.1: +; X86-TRANSFORM-NEXT: movl %edi, %esi +; X86-TRANSFORM-NEXT: xorl %edi, %edi +; X86-TRANSFORM-NEXT: .LBB21_2: +; X86-TRANSFORM-NEXT: subl $8, %esp +; X86-TRANSFORM-NEXT: pushl %esi +; X86-TRANSFORM-NEXT: pushl %edi +; X86-TRANSFORM-NEXT: calll use64 +; X86-TRANSFORM-NEXT: addl $16, %esp +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %esi +; X86-TRANSFORM-NEXT: andl {{[0-9]+}}(%esp), %edi +; X86-TRANSFORM-NEXT: movl %edi, %eax +; X86-TRANSFORM-NEXT: movl %esi, %edx +; X86-TRANSFORM-NEXT: addl $4, %esp +; X86-TRANSFORM-NEXT: popl %esi +; X86-TRANSFORM-NEXT: popl %edi +; X86-TRANSFORM-NEXT: retl +; +; X64-NOTRANSFORM-LABEL: oneuse64: +; X64-NOTRANSFORM: # %bb.0: +; X64-NOTRANSFORM-NEXT: pushq %r14 +; X64-NOTRANSFORM-NEXT: pushq %rbx +; X64-NOTRANSFORM-NEXT: pushq %rax +; X64-NOTRANSFORM-NEXT: movq %rdi, %r14 +; X64-NOTRANSFORM-NEXT: movq $-1, %rbx +; X64-NOTRANSFORM-NEXT: movl %esi, %ecx +; X64-NOTRANSFORM-NEXT: shlq %cl, %rbx +; X64-NOTRANSFORM-NEXT: movq %rbx, %rdi +; X64-NOTRANSFORM-NEXT: callq use64 +; X64-NOTRANSFORM-NEXT: andq %r14, %rbx +; X64-NOTRANSFORM-NEXT: movq %rbx, %rax +; X64-NOTRANSFORM-NEXT: addq $8, %rsp +; X64-NOTRANSFORM-NEXT: popq %rbx +; X64-NOTRANSFORM-NEXT: popq %r14 +; X64-NOTRANSFORM-NEXT: retq +; +; X64-TRANSFORM-LABEL: oneuse64: +; X64-TRANSFORM: # %bb.0: +; X64-TRANSFORM-NEXT: pushq %r14 +; X64-TRANSFORM-NEXT: pushq %rbx +; X64-TRANSFORM-NEXT: pushq %rax +; X64-TRANSFORM-NEXT: movq %rdi, %r14 +; X64-TRANSFORM-NEXT: movq $-1, %rax +; X64-TRANSFORM-NEXT: shlxq %rsi, %rax, %rbx +; X64-TRANSFORM-NEXT: movq %rbx, %rdi +; X64-TRANSFORM-NEXT: callq use64 +; X64-TRANSFORM-NEXT: andq %r14, %rbx +; X64-TRANSFORM-NEXT: movq %rbx, %rax +; X64-TRANSFORM-NEXT: addq $8, %rsp +; X64-TRANSFORM-NEXT: popq %rbx +; X64-TRANSFORM-NEXT: popq %r14 +; X64-TRANSFORM-NEXT: retq + %mask = shl i64 -1, %numlowbits + call void @use64(i64 %mask) + %masked = and i64 %mask, %val + ret i64 %masked +}