1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+bmi,+bmi2 | FileCheck %s --check-prefixes=CHECK,X86 3; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi,+bmi2 | FileCheck %s --check-prefixes=CHECK,X64 4 5define i32 @bzhi32(i32 %x, i32 %y) { 6; X86-LABEL: bzhi32: 7; X86: # %bb.0: 8; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 9; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 10; X86-NEXT: addl %ecx, %ecx 11; X86-NEXT: bzhil %eax, %ecx, %eax 12; X86-NEXT: retl 13; 14; X64-LABEL: bzhi32: 15; X64: # %bb.0: 16; X64-NEXT: addl %edi, %edi 17; X64-NEXT: bzhil %esi, %edi, %eax 18; X64-NEXT: retq 19 %x1 = add i32 %x, %x 20 %tmp = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %x1, i32 %y) 21 ret i32 %tmp 22} 23 24define i32 @bzhi32_load(i32* %x, i32 %y) { 25; X86-LABEL: bzhi32_load: 26; X86: # %bb.0: 27; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 28; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 29; X86-NEXT: bzhil %eax, (%ecx), %eax 30; X86-NEXT: retl 31; 32; X64-LABEL: bzhi32_load: 33; X64: # %bb.0: 34; X64-NEXT: bzhil %esi, (%rdi), %eax 35; X64-NEXT: retq 36 %x1 = load i32, i32* %x 37 %tmp = tail call i32 @llvm.x86.bmi.bzhi.32(i32 %x1, i32 %y) 38 ret i32 %tmp 39} 40 41declare i32 @llvm.x86.bmi.bzhi.32(i32, i32) 42 43define i32 @pdep32(i32 %x, i32 %y) { 44; X86-LABEL: pdep32: 45; X86: # %bb.0: 46; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 47; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 48; X86-NEXT: addl %ecx, %ecx 49; X86-NEXT: pdepl %ecx, %eax, %eax 50; X86-NEXT: retl 51; 52; X64-LABEL: pdep32: 53; X64: # %bb.0: 54; X64-NEXT: addl %esi, %esi 55; X64-NEXT: pdepl %esi, %edi, %eax 56; X64-NEXT: retq 57 %y1 = add i32 %y, %y 58 %tmp = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 %y1) 59 ret i32 %tmp 60} 61 62define i32 @pdep32_load(i32 %x, i32* %y) { 63; X86-LABEL: pdep32_load: 64; X86: # %bb.0: 65; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 66; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 67; X86-NEXT: pdepl (%eax), %ecx, %eax 68; X86-NEXT: retl 69; 70; X64-LABEL: pdep32_load: 71; X64: # %bb.0: 72; X64-NEXT: pdepl (%rsi), %edi, %eax 73; X64-NEXT: retq 74 %y1 = load i32, i32* %y 75 %tmp = tail call i32 @llvm.x86.bmi.pdep.32(i32 %x, i32 %y1) 76 ret i32 %tmp 77} 78 79declare i32 @llvm.x86.bmi.pdep.32(i32, i32) 80 81define i32 @pext32(i32 %x, i32 %y) { 82; X86-LABEL: pext32: 83; X86: # %bb.0: 84; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 85; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 86; X86-NEXT: addl %ecx, %ecx 87; X86-NEXT: pextl %ecx, %eax, %eax 88; X86-NEXT: retl 89; 90; X64-LABEL: pext32: 91; X64: # %bb.0: 92; X64-NEXT: addl %esi, %esi 93; X64-NEXT: pextl %esi, %edi, %eax 94; X64-NEXT: retq 95 %y1 = add i32 %y, %y 96 %tmp = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 %y1) 97 ret i32 %tmp 98} 99 100define i32 @pext32_load(i32 %x, i32* %y) { 101; X86-LABEL: pext32_load: 102; X86: # %bb.0: 103; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 104; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 105; X86-NEXT: pextl (%eax), %ecx, %eax 106; X86-NEXT: retl 107; 108; X64-LABEL: pext32_load: 109; X64: # %bb.0: 110; X64-NEXT: pextl (%rsi), %edi, %eax 111; X64-NEXT: retq 112 %y1 = load i32, i32* %y 113 %tmp = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 %y1) 114 ret i32 %tmp 115} 116 117declare i32 @llvm.x86.bmi.pext.32(i32, i32) 118 119define i32 @mulx32(i32 %x, i32 %y, i32* %p) { 120; X86-LABEL: mulx32: 121; X86: # %bb.0: 122; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 123; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 124; X86-NEXT: movl {{[0-9]+}}(%esp), %edx 125; X86-NEXT: addl %edx, %edx 126; X86-NEXT: addl %eax, %eax 127; X86-NEXT: mulxl %eax, %eax, %edx 128; X86-NEXT: movl %edx, (%ecx) 129; X86-NEXT: retl 130; 131; X64-LABEL: mulx32: 132; X64: # %bb.0: 133; X64-NEXT: # kill: def $esi killed $esi def $rsi 134; X64-NEXT: # kill: def $edi killed $edi def $rdi 135; X64-NEXT: addl %edi, %edi 136; X64-NEXT: addl %esi, %esi 137; X64-NEXT: imulq %rdi, %rsi 138; X64-NEXT: movq %rsi, %rax 139; X64-NEXT: shrq $32, %rax 140; X64-NEXT: movl %eax, (%rdx) 141; X64-NEXT: movl %esi, %eax 142; X64-NEXT: retq 143 %x1 = add i32 %x, %x 144 %y1 = add i32 %y, %y 145 %x2 = zext i32 %x1 to i64 146 %y2 = zext i32 %y1 to i64 147 %r1 = mul i64 %x2, %y2 148 %h1 = lshr i64 %r1, 32 149 %h = trunc i64 %h1 to i32 150 %l = trunc i64 %r1 to i32 151 store i32 %h, i32* %p 152 ret i32 %l 153} 154 155define i32 @mulx32_load(i32 %x, i32* %y, i32* %p) { 156; X86-LABEL: mulx32_load: 157; X86: # %bb.0: 158; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 159; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 160; X86-NEXT: movl {{[0-9]+}}(%esp), %edx 161; X86-NEXT: addl %edx, %edx 162; X86-NEXT: mulxl (%eax), %eax, %edx 163; X86-NEXT: movl %edx, (%ecx) 164; X86-NEXT: retl 165; 166; X64-LABEL: mulx32_load: 167; X64: # %bb.0: 168; X64-NEXT: # kill: def $edi killed $edi def $rdi 169; X64-NEXT: addl %edi, %edi 170; X64-NEXT: movl (%rsi), %eax 171; X64-NEXT: imulq %rax, %rdi 172; X64-NEXT: movq %rdi, %rax 173; X64-NEXT: shrq $32, %rax 174; X64-NEXT: movl %eax, (%rdx) 175; X64-NEXT: movl %edi, %eax 176; X64-NEXT: retq 177 %x1 = add i32 %x, %x 178 %y1 = load i32, i32* %y 179 %x2 = zext i32 %x1 to i64 180 %y2 = zext i32 %y1 to i64 181 %r1 = mul i64 %x2, %y2 182 %h1 = lshr i64 %r1, 32 183 %h = trunc i64 %h1 to i32 184 %l = trunc i64 %r1 to i32 185 store i32 %h, i32* %p 186 ret i32 %l 187} 188