1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X86,NOBMI,X86-NOBMI 3; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1NOTBM,X86-BMI1NOTBM 4; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1TBM,X86-BMI1TBM 5; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1BMI2,X86-BMI1BMI2,BMI1TBM,X86-BMI1TBM,BMI1TBMBMI2,X86-BMI1TBMBMI2 6; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1BMI2,X86-BMI1BMI2,BMI1NOTBMBMI2,X86-BMI1NOTBMBMI2 7; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X64,NOBMI,X64-NOBMI 8; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1NOTBM,X64-BMI1NOTBM 9; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1TBM,X64-BMI1TBM 10; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1BMI2,X64-BMI1BMI2,BMI1TBM,X64-BMI1TBM,BMI1TBMBMI2,X64-BMI1TBMBMI2 11; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2,+fast-bextr < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1BMI2,X64-BMI1BMI2,BMI1NOTBMBMI2,X64-BMI1NOTBMBMI2 12 13; *Please* keep in sync with test/CodeGen/AArch64/extract-bits.ll 14 15; https://bugs.llvm.org/show_bug.cgi?id=36419 16; https://bugs.llvm.org/show_bug.cgi?id=37603 17; https://bugs.llvm.org/show_bug.cgi?id=37610 18 19; Patterns: 20; a) (x >> start) & (1 << nbits) - 1 21; b) (x >> start) & ~(-1 << nbits) 22; c) (x >> start) & (-1 >> (32 - y)) 23; d) (x >> start) << (32 - y) >> (32 - y) 24; are equivalent. 25 26declare void @use32(i32) 27declare void @use64(i64) 28 29; ---------------------------------------------------------------------------- ; 30; Pattern a. 32-bit 31; ---------------------------------------------------------------------------- ; 32 33define i32 @bextr32_a0(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 34; X86-NOBMI-LABEL: bextr32_a0: 35; X86-NOBMI: # %bb.0: 36; X86-NOBMI-NEXT: pushl %esi 37; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 38; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 39; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 40; X86-NOBMI-NEXT: shrl %cl, %esi 41; X86-NOBMI-NEXT: movl $1, %eax 42; X86-NOBMI-NEXT: movl %edx, %ecx 43; X86-NOBMI-NEXT: shll %cl, %eax 44; X86-NOBMI-NEXT: decl %eax 45; X86-NOBMI-NEXT: andl %esi, %eax 46; X86-NOBMI-NEXT: popl %esi 47; X86-NOBMI-NEXT: retl 48; 49; X86-BMI1NOTBM-LABEL: bextr32_a0: 50; X86-BMI1NOTBM: # %bb.0: 51; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 52; X86-BMI1NOTBM-NEXT: shll $8, %eax 53; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 54; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 55; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 56; X86-BMI1NOTBM-NEXT: retl 57; 58; X86-BMI1BMI2-LABEL: bextr32_a0: 59; X86-BMI1BMI2: # %bb.0: 60; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 61; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 62; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 63; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 64; X86-BMI1BMI2-NEXT: retl 65; 66; X64-NOBMI-LABEL: bextr32_a0: 67; X64-NOBMI: # %bb.0: 68; X64-NOBMI-NEXT: movl %esi, %ecx 69; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 70; X64-NOBMI-NEXT: shrl %cl, %edi 71; X64-NOBMI-NEXT: movl $1, %eax 72; X64-NOBMI-NEXT: movl %edx, %ecx 73; X64-NOBMI-NEXT: shll %cl, %eax 74; X64-NOBMI-NEXT: decl %eax 75; X64-NOBMI-NEXT: andl %edi, %eax 76; X64-NOBMI-NEXT: retq 77; 78; X64-BMI1NOTBM-LABEL: bextr32_a0: 79; X64-BMI1NOTBM: # %bb.0: 80; X64-BMI1NOTBM-NEXT: shll $8, %edx 81; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 82; X64-BMI1NOTBM-NEXT: orl %edx, %eax 83; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 84; X64-BMI1NOTBM-NEXT: retq 85; 86; X64-BMI1BMI2-LABEL: bextr32_a0: 87; X64-BMI1BMI2: # %bb.0: 88; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 89; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 90; X64-BMI1BMI2-NEXT: retq 91 %shifted = lshr i32 %val, %numskipbits 92 %onebit = shl i32 1, %numlowbits 93 %mask = add nsw i32 %onebit, -1 94 %masked = and i32 %mask, %shifted 95 ret i32 %masked 96} 97 98define i32 @bextr32_a0_arithmetic(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 99; X86-NOBMI-LABEL: bextr32_a0_arithmetic: 100; X86-NOBMI: # %bb.0: 101; X86-NOBMI-NEXT: pushl %esi 102; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 103; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 104; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 105; X86-NOBMI-NEXT: sarl %cl, %esi 106; X86-NOBMI-NEXT: movl $1, %eax 107; X86-NOBMI-NEXT: movl %edx, %ecx 108; X86-NOBMI-NEXT: shll %cl, %eax 109; X86-NOBMI-NEXT: decl %eax 110; X86-NOBMI-NEXT: andl %esi, %eax 111; X86-NOBMI-NEXT: popl %esi 112; X86-NOBMI-NEXT: retl 113; 114; X86-BMI1NOTBM-LABEL: bextr32_a0_arithmetic: 115; X86-BMI1NOTBM: # %bb.0: 116; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 117; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 118; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 119; X86-BMI1NOTBM-NEXT: sarl %cl, %edx 120; X86-BMI1NOTBM-NEXT: shll $8, %eax 121; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 122; X86-BMI1NOTBM-NEXT: retl 123; 124; X86-BMI1BMI2-LABEL: bextr32_a0_arithmetic: 125; X86-BMI1BMI2: # %bb.0: 126; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 127; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 128; X86-BMI1BMI2-NEXT: sarxl %ecx, {{[0-9]+}}(%esp), %ecx 129; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 130; X86-BMI1BMI2-NEXT: retl 131; 132; X64-NOBMI-LABEL: bextr32_a0_arithmetic: 133; X64-NOBMI: # %bb.0: 134; X64-NOBMI-NEXT: movl %esi, %ecx 135; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 136; X64-NOBMI-NEXT: sarl %cl, %edi 137; X64-NOBMI-NEXT: movl $1, %eax 138; X64-NOBMI-NEXT: movl %edx, %ecx 139; X64-NOBMI-NEXT: shll %cl, %eax 140; X64-NOBMI-NEXT: decl %eax 141; X64-NOBMI-NEXT: andl %edi, %eax 142; X64-NOBMI-NEXT: retq 143; 144; X64-BMI1NOTBM-LABEL: bextr32_a0_arithmetic: 145; X64-BMI1NOTBM: # %bb.0: 146; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 147; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 148; X64-BMI1NOTBM-NEXT: sarl %cl, %edi 149; X64-BMI1NOTBM-NEXT: shll $8, %edx 150; X64-BMI1NOTBM-NEXT: bextrl %edx, %edi, %eax 151; X64-BMI1NOTBM-NEXT: retq 152; 153; X64-BMI1BMI2-LABEL: bextr32_a0_arithmetic: 154; X64-BMI1BMI2: # %bb.0: 155; X64-BMI1BMI2-NEXT: sarxl %esi, %edi, %eax 156; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 157; X64-BMI1BMI2-NEXT: retq 158 %shifted = ashr i32 %val, %numskipbits 159 %onebit = shl i32 1, %numlowbits 160 %mask = add nsw i32 %onebit, -1 161 %masked = and i32 %mask, %shifted 162 ret i32 %masked 163} 164 165define i32 @bextr32_a1_indexzext(i32 %val, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 166; X86-NOBMI-LABEL: bextr32_a1_indexzext: 167; X86-NOBMI: # %bb.0: 168; X86-NOBMI-NEXT: pushl %esi 169; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 170; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 171; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 172; X86-NOBMI-NEXT: shrl %cl, %esi 173; X86-NOBMI-NEXT: movl $1, %eax 174; X86-NOBMI-NEXT: movl %edx, %ecx 175; X86-NOBMI-NEXT: shll %cl, %eax 176; X86-NOBMI-NEXT: decl %eax 177; X86-NOBMI-NEXT: andl %esi, %eax 178; X86-NOBMI-NEXT: popl %esi 179; X86-NOBMI-NEXT: retl 180; 181; X86-BMI1NOTBM-LABEL: bextr32_a1_indexzext: 182; X86-BMI1NOTBM: # %bb.0: 183; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 184; X86-BMI1NOTBM-NEXT: shll $8, %eax 185; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 186; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 187; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 188; X86-BMI1NOTBM-NEXT: retl 189; 190; X86-BMI1BMI2-LABEL: bextr32_a1_indexzext: 191; X86-BMI1BMI2: # %bb.0: 192; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 193; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 194; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 195; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 196; X86-BMI1BMI2-NEXT: retl 197; 198; X64-NOBMI-LABEL: bextr32_a1_indexzext: 199; X64-NOBMI: # %bb.0: 200; X64-NOBMI-NEXT: movl %esi, %ecx 201; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 202; X64-NOBMI-NEXT: shrl %cl, %edi 203; X64-NOBMI-NEXT: movl $1, %eax 204; X64-NOBMI-NEXT: movl %edx, %ecx 205; X64-NOBMI-NEXT: shll %cl, %eax 206; X64-NOBMI-NEXT: decl %eax 207; X64-NOBMI-NEXT: andl %edi, %eax 208; X64-NOBMI-NEXT: retq 209; 210; X64-BMI1NOTBM-LABEL: bextr32_a1_indexzext: 211; X64-BMI1NOTBM: # %bb.0: 212; X64-BMI1NOTBM-NEXT: shll $8, %edx 213; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 214; X64-BMI1NOTBM-NEXT: orl %edx, %eax 215; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 216; X64-BMI1NOTBM-NEXT: retq 217; 218; X64-BMI1BMI2-LABEL: bextr32_a1_indexzext: 219; X64-BMI1BMI2: # %bb.0: 220; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 221; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 222; X64-BMI1BMI2-NEXT: retq 223 %skip = zext i8 %numskipbits to i32 224 %shifted = lshr i32 %val, %skip 225 %conv = zext i8 %numlowbits to i32 226 %onebit = shl i32 1, %conv 227 %mask = add nsw i32 %onebit, -1 228 %masked = and i32 %mask, %shifted 229 ret i32 %masked 230} 231 232define i32 @bextr32_a2_load(i32* %w, i32 %numskipbits, i32 %numlowbits) nounwind { 233; X86-NOBMI-LABEL: bextr32_a2_load: 234; X86-NOBMI: # %bb.0: 235; X86-NOBMI-NEXT: pushl %esi 236; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 237; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 238; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 239; X86-NOBMI-NEXT: movl (%eax), %esi 240; X86-NOBMI-NEXT: shrl %cl, %esi 241; X86-NOBMI-NEXT: movl $1, %eax 242; X86-NOBMI-NEXT: movl %edx, %ecx 243; X86-NOBMI-NEXT: shll %cl, %eax 244; X86-NOBMI-NEXT: decl %eax 245; X86-NOBMI-NEXT: andl %esi, %eax 246; X86-NOBMI-NEXT: popl %esi 247; X86-NOBMI-NEXT: retl 248; 249; X86-BMI1NOTBM-LABEL: bextr32_a2_load: 250; X86-BMI1NOTBM: # %bb.0: 251; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 252; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 253; X86-BMI1NOTBM-NEXT: shll $8, %ecx 254; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %edx 255; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 256; X86-BMI1NOTBM-NEXT: bextrl %edx, (%eax), %eax 257; X86-BMI1NOTBM-NEXT: retl 258; 259; X86-BMI1BMI2-LABEL: bextr32_a2_load: 260; X86-BMI1BMI2: # %bb.0: 261; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 262; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 263; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 264; X86-BMI1BMI2-NEXT: shrxl %edx, (%ecx), %ecx 265; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 266; X86-BMI1BMI2-NEXT: retl 267; 268; X64-NOBMI-LABEL: bextr32_a2_load: 269; X64-NOBMI: # %bb.0: 270; X64-NOBMI-NEXT: movl %esi, %ecx 271; X64-NOBMI-NEXT: movl (%rdi), %esi 272; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 273; X64-NOBMI-NEXT: shrl %cl, %esi 274; X64-NOBMI-NEXT: movl $1, %eax 275; X64-NOBMI-NEXT: movl %edx, %ecx 276; X64-NOBMI-NEXT: shll %cl, %eax 277; X64-NOBMI-NEXT: decl %eax 278; X64-NOBMI-NEXT: andl %esi, %eax 279; X64-NOBMI-NEXT: retq 280; 281; X64-BMI1NOTBM-LABEL: bextr32_a2_load: 282; X64-BMI1NOTBM: # %bb.0: 283; X64-BMI1NOTBM-NEXT: shll $8, %edx 284; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 285; X64-BMI1NOTBM-NEXT: orl %edx, %eax 286; X64-BMI1NOTBM-NEXT: bextrl %eax, (%rdi), %eax 287; X64-BMI1NOTBM-NEXT: retq 288; 289; X64-BMI1BMI2-LABEL: bextr32_a2_load: 290; X64-BMI1BMI2: # %bb.0: 291; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %eax 292; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 293; X64-BMI1BMI2-NEXT: retq 294 %val = load i32, i32* %w 295 %shifted = lshr i32 %val, %numskipbits 296 %onebit = shl i32 1, %numlowbits 297 %mask = add nsw i32 %onebit, -1 298 %masked = and i32 %mask, %shifted 299 ret i32 %masked 300} 301 302define i32 @bextr32_a3_load_indexzext(i32* %w, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 303; X86-NOBMI-LABEL: bextr32_a3_load_indexzext: 304; X86-NOBMI: # %bb.0: 305; X86-NOBMI-NEXT: pushl %esi 306; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 307; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 308; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 309; X86-NOBMI-NEXT: movl (%eax), %esi 310; X86-NOBMI-NEXT: shrl %cl, %esi 311; X86-NOBMI-NEXT: movl $1, %eax 312; X86-NOBMI-NEXT: movl %edx, %ecx 313; X86-NOBMI-NEXT: shll %cl, %eax 314; X86-NOBMI-NEXT: decl %eax 315; X86-NOBMI-NEXT: andl %esi, %eax 316; X86-NOBMI-NEXT: popl %esi 317; X86-NOBMI-NEXT: retl 318; 319; X86-BMI1NOTBM-LABEL: bextr32_a3_load_indexzext: 320; X86-BMI1NOTBM: # %bb.0: 321; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 322; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 323; X86-BMI1NOTBM-NEXT: shll $8, %ecx 324; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %edx 325; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 326; X86-BMI1NOTBM-NEXT: bextrl %edx, (%eax), %eax 327; X86-BMI1NOTBM-NEXT: retl 328; 329; X86-BMI1BMI2-LABEL: bextr32_a3_load_indexzext: 330; X86-BMI1BMI2: # %bb.0: 331; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 332; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 333; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 334; X86-BMI1BMI2-NEXT: shrxl %edx, (%ecx), %ecx 335; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 336; X86-BMI1BMI2-NEXT: retl 337; 338; X64-NOBMI-LABEL: bextr32_a3_load_indexzext: 339; X64-NOBMI: # %bb.0: 340; X64-NOBMI-NEXT: movl %esi, %ecx 341; X64-NOBMI-NEXT: movl (%rdi), %esi 342; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 343; X64-NOBMI-NEXT: shrl %cl, %esi 344; X64-NOBMI-NEXT: movl $1, %eax 345; X64-NOBMI-NEXT: movl %edx, %ecx 346; X64-NOBMI-NEXT: shll %cl, %eax 347; X64-NOBMI-NEXT: decl %eax 348; X64-NOBMI-NEXT: andl %esi, %eax 349; X64-NOBMI-NEXT: retq 350; 351; X64-BMI1NOTBM-LABEL: bextr32_a3_load_indexzext: 352; X64-BMI1NOTBM: # %bb.0: 353; X64-BMI1NOTBM-NEXT: shll $8, %edx 354; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 355; X64-BMI1NOTBM-NEXT: orl %edx, %eax 356; X64-BMI1NOTBM-NEXT: bextrl %eax, (%rdi), %eax 357; X64-BMI1NOTBM-NEXT: retq 358; 359; X64-BMI1BMI2-LABEL: bextr32_a3_load_indexzext: 360; X64-BMI1BMI2: # %bb.0: 361; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %eax 362; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 363; X64-BMI1BMI2-NEXT: retq 364 %val = load i32, i32* %w 365 %skip = zext i8 %numskipbits to i32 366 %shifted = lshr i32 %val, %skip 367 %conv = zext i8 %numlowbits to i32 368 %onebit = shl i32 1, %conv 369 %mask = add nsw i32 %onebit, -1 370 %masked = and i32 %mask, %shifted 371 ret i32 %masked 372} 373 374define i32 @bextr32_a4_commutative(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 375; X86-NOBMI-LABEL: bextr32_a4_commutative: 376; X86-NOBMI: # %bb.0: 377; X86-NOBMI-NEXT: pushl %esi 378; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 379; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 380; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 381; X86-NOBMI-NEXT: shrl %cl, %esi 382; X86-NOBMI-NEXT: movl $1, %eax 383; X86-NOBMI-NEXT: movl %edx, %ecx 384; X86-NOBMI-NEXT: shll %cl, %eax 385; X86-NOBMI-NEXT: decl %eax 386; X86-NOBMI-NEXT: andl %esi, %eax 387; X86-NOBMI-NEXT: popl %esi 388; X86-NOBMI-NEXT: retl 389; 390; X86-BMI1NOTBM-LABEL: bextr32_a4_commutative: 391; X86-BMI1NOTBM: # %bb.0: 392; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 393; X86-BMI1NOTBM-NEXT: shll $8, %eax 394; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 395; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 396; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 397; X86-BMI1NOTBM-NEXT: retl 398; 399; X86-BMI1BMI2-LABEL: bextr32_a4_commutative: 400; X86-BMI1BMI2: # %bb.0: 401; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 402; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 403; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 404; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 405; X86-BMI1BMI2-NEXT: retl 406; 407; X64-NOBMI-LABEL: bextr32_a4_commutative: 408; X64-NOBMI: # %bb.0: 409; X64-NOBMI-NEXT: movl %esi, %ecx 410; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 411; X64-NOBMI-NEXT: shrl %cl, %edi 412; X64-NOBMI-NEXT: movl $1, %eax 413; X64-NOBMI-NEXT: movl %edx, %ecx 414; X64-NOBMI-NEXT: shll %cl, %eax 415; X64-NOBMI-NEXT: decl %eax 416; X64-NOBMI-NEXT: andl %edi, %eax 417; X64-NOBMI-NEXT: retq 418; 419; X64-BMI1NOTBM-LABEL: bextr32_a4_commutative: 420; X64-BMI1NOTBM: # %bb.0: 421; X64-BMI1NOTBM-NEXT: shll $8, %edx 422; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 423; X64-BMI1NOTBM-NEXT: orl %edx, %eax 424; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 425; X64-BMI1NOTBM-NEXT: retq 426; 427; X64-BMI1BMI2-LABEL: bextr32_a4_commutative: 428; X64-BMI1BMI2: # %bb.0: 429; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 430; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 431; X64-BMI1BMI2-NEXT: retq 432 %shifted = lshr i32 %val, %numskipbits 433 %onebit = shl i32 1, %numlowbits 434 %mask = add nsw i32 %onebit, -1 435 %masked = and i32 %shifted, %mask ; swapped order 436 ret i32 %masked 437} 438 439define i32 @bextr32_a5_skipextrauses(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 440; X86-NOBMI-LABEL: bextr32_a5_skipextrauses: 441; X86-NOBMI: # %bb.0: 442; X86-NOBMI-NEXT: pushl %edi 443; X86-NOBMI-NEXT: pushl %esi 444; X86-NOBMI-NEXT: pushl %eax 445; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 446; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 447; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 448; X86-NOBMI-NEXT: movl %eax, %ecx 449; X86-NOBMI-NEXT: shrl %cl, %edi 450; X86-NOBMI-NEXT: movl $1, %esi 451; X86-NOBMI-NEXT: movl %edx, %ecx 452; X86-NOBMI-NEXT: shll %cl, %esi 453; X86-NOBMI-NEXT: decl %esi 454; X86-NOBMI-NEXT: andl %edi, %esi 455; X86-NOBMI-NEXT: movl %eax, (%esp) 456; X86-NOBMI-NEXT: calll use32 457; X86-NOBMI-NEXT: movl %esi, %eax 458; X86-NOBMI-NEXT: addl $4, %esp 459; X86-NOBMI-NEXT: popl %esi 460; X86-NOBMI-NEXT: popl %edi 461; X86-NOBMI-NEXT: retl 462; 463; X86-BMI1NOTBM-LABEL: bextr32_a5_skipextrauses: 464; X86-BMI1NOTBM: # %bb.0: 465; X86-BMI1NOTBM-NEXT: pushl %esi 466; X86-BMI1NOTBM-NEXT: subl $8, %esp 467; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 468; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 469; X86-BMI1NOTBM-NEXT: shll $8, %ecx 470; X86-BMI1NOTBM-NEXT: movzbl %al, %edx 471; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 472; X86-BMI1NOTBM-NEXT: bextrl %edx, {{[0-9]+}}(%esp), %esi 473; X86-BMI1NOTBM-NEXT: movl %eax, (%esp) 474; X86-BMI1NOTBM-NEXT: calll use32 475; X86-BMI1NOTBM-NEXT: movl %esi, %eax 476; X86-BMI1NOTBM-NEXT: addl $8, %esp 477; X86-BMI1NOTBM-NEXT: popl %esi 478; X86-BMI1NOTBM-NEXT: retl 479; 480; X86-BMI1BMI2-LABEL: bextr32_a5_skipextrauses: 481; X86-BMI1BMI2: # %bb.0: 482; X86-BMI1BMI2-NEXT: pushl %esi 483; X86-BMI1BMI2-NEXT: subl $8, %esp 484; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 485; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 486; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %edx 487; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %esi 488; X86-BMI1BMI2-NEXT: movl %ecx, (%esp) 489; X86-BMI1BMI2-NEXT: calll use32 490; X86-BMI1BMI2-NEXT: movl %esi, %eax 491; X86-BMI1BMI2-NEXT: addl $8, %esp 492; X86-BMI1BMI2-NEXT: popl %esi 493; X86-BMI1BMI2-NEXT: retl 494; 495; X64-NOBMI-LABEL: bextr32_a5_skipextrauses: 496; X64-NOBMI: # %bb.0: 497; X64-NOBMI-NEXT: pushq %rbx 498; X64-NOBMI-NEXT: movl %esi, %ecx 499; X64-NOBMI-NEXT: shrl %cl, %edi 500; X64-NOBMI-NEXT: movl $1, %ebx 501; X64-NOBMI-NEXT: movl %edx, %ecx 502; X64-NOBMI-NEXT: shll %cl, %ebx 503; X64-NOBMI-NEXT: decl %ebx 504; X64-NOBMI-NEXT: andl %edi, %ebx 505; X64-NOBMI-NEXT: movl %esi, %edi 506; X64-NOBMI-NEXT: callq use32 507; X64-NOBMI-NEXT: movl %ebx, %eax 508; X64-NOBMI-NEXT: popq %rbx 509; X64-NOBMI-NEXT: retq 510; 511; X64-BMI1NOTBM-LABEL: bextr32_a5_skipextrauses: 512; X64-BMI1NOTBM: # %bb.0: 513; X64-BMI1NOTBM-NEXT: pushq %rbx 514; X64-BMI1NOTBM-NEXT: shll $8, %edx 515; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 516; X64-BMI1NOTBM-NEXT: orl %edx, %eax 517; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %ebx 518; X64-BMI1NOTBM-NEXT: movl %esi, %edi 519; X64-BMI1NOTBM-NEXT: callq use32 520; X64-BMI1NOTBM-NEXT: movl %ebx, %eax 521; X64-BMI1NOTBM-NEXT: popq %rbx 522; X64-BMI1NOTBM-NEXT: retq 523; 524; X64-BMI1BMI2-LABEL: bextr32_a5_skipextrauses: 525; X64-BMI1BMI2: # %bb.0: 526; X64-BMI1BMI2-NEXT: pushq %rbx 527; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 528; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %ebx 529; X64-BMI1BMI2-NEXT: movl %esi, %edi 530; X64-BMI1BMI2-NEXT: callq use32 531; X64-BMI1BMI2-NEXT: movl %ebx, %eax 532; X64-BMI1BMI2-NEXT: popq %rbx 533; X64-BMI1BMI2-NEXT: retq 534 %shifted = lshr i32 %val, %numskipbits 535 %onebit = shl i32 1, %numlowbits 536 %mask = add nsw i32 %onebit, -1 537 %masked = and i32 %mask, %shifted 538 call void @use32(i32 %numskipbits) 539 ret i32 %masked 540} 541 542; 64-bit 543 544define i64 @bextr64_a0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 545; X86-NOBMI-LABEL: bextr64_a0: 546; X86-NOBMI: # %bb.0: 547; X86-NOBMI-NEXT: pushl %edi 548; X86-NOBMI-NEXT: pushl %esi 549; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 550; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 551; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 552; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 553; X86-NOBMI-NEXT: movl %eax, %edi 554; X86-NOBMI-NEXT: shrl %cl, %edi 555; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 556; X86-NOBMI-NEXT: testb $32, %cl 557; X86-NOBMI-NEXT: je .LBB7_2 558; X86-NOBMI-NEXT: # %bb.1: 559; X86-NOBMI-NEXT: movl %edi, %esi 560; X86-NOBMI-NEXT: xorl %edi, %edi 561; X86-NOBMI-NEXT: .LBB7_2: 562; X86-NOBMI-NEXT: movl $1, %eax 563; X86-NOBMI-NEXT: xorl %edx, %edx 564; X86-NOBMI-NEXT: movb %ch, %cl 565; X86-NOBMI-NEXT: shldl %cl, %eax, %edx 566; X86-NOBMI-NEXT: shll %cl, %eax 567; X86-NOBMI-NEXT: testb $32, %ch 568; X86-NOBMI-NEXT: je .LBB7_4 569; X86-NOBMI-NEXT: # %bb.3: 570; X86-NOBMI-NEXT: movl %eax, %edx 571; X86-NOBMI-NEXT: xorl %eax, %eax 572; X86-NOBMI-NEXT: .LBB7_4: 573; X86-NOBMI-NEXT: addl $-1, %eax 574; X86-NOBMI-NEXT: adcl $-1, %edx 575; X86-NOBMI-NEXT: andl %esi, %eax 576; X86-NOBMI-NEXT: andl %edi, %edx 577; X86-NOBMI-NEXT: popl %esi 578; X86-NOBMI-NEXT: popl %edi 579; X86-NOBMI-NEXT: retl 580; 581; X86-BMI1NOTBM-LABEL: bextr64_a0: 582; X86-BMI1NOTBM: # %bb.0: 583; X86-BMI1NOTBM-NEXT: pushl %edi 584; X86-BMI1NOTBM-NEXT: pushl %esi 585; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %ch 586; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 587; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 588; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 589; X86-BMI1NOTBM-NEXT: movl %eax, %edi 590; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 591; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 592; X86-BMI1NOTBM-NEXT: testb $32, %cl 593; X86-BMI1NOTBM-NEXT: je .LBB7_2 594; X86-BMI1NOTBM-NEXT: # %bb.1: 595; X86-BMI1NOTBM-NEXT: movl %edi, %esi 596; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 597; X86-BMI1NOTBM-NEXT: .LBB7_2: 598; X86-BMI1NOTBM-NEXT: movl $1, %eax 599; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 600; X86-BMI1NOTBM-NEXT: movb %ch, %cl 601; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx 602; X86-BMI1NOTBM-NEXT: shll %cl, %eax 603; X86-BMI1NOTBM-NEXT: testb $32, %ch 604; X86-BMI1NOTBM-NEXT: je .LBB7_4 605; X86-BMI1NOTBM-NEXT: # %bb.3: 606; X86-BMI1NOTBM-NEXT: movl %eax, %edx 607; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 608; X86-BMI1NOTBM-NEXT: .LBB7_4: 609; X86-BMI1NOTBM-NEXT: addl $-1, %eax 610; X86-BMI1NOTBM-NEXT: adcl $-1, %edx 611; X86-BMI1NOTBM-NEXT: andl %esi, %eax 612; X86-BMI1NOTBM-NEXT: andl %edi, %edx 613; X86-BMI1NOTBM-NEXT: popl %esi 614; X86-BMI1NOTBM-NEXT: popl %edi 615; X86-BMI1NOTBM-NEXT: retl 616; 617; X86-BMI1BMI2-LABEL: bextr64_a0: 618; X86-BMI1BMI2: # %bb.0: 619; X86-BMI1BMI2-NEXT: pushl %ebx 620; X86-BMI1BMI2-NEXT: pushl %edi 621; X86-BMI1BMI2-NEXT: pushl %esi 622; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 623; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 624; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 625; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 626; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 627; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 628; X86-BMI1BMI2-NEXT: testb $32, %cl 629; X86-BMI1BMI2-NEXT: je .LBB7_2 630; X86-BMI1BMI2-NEXT: # %bb.1: 631; X86-BMI1BMI2-NEXT: movl %edi, %esi 632; X86-BMI1BMI2-NEXT: xorl %edi, %edi 633; X86-BMI1BMI2-NEXT: .LBB7_2: 634; X86-BMI1BMI2-NEXT: movl $1, %eax 635; X86-BMI1BMI2-NEXT: xorl %edx, %edx 636; X86-BMI1BMI2-NEXT: movl %ebx, %ecx 637; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx 638; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 639; X86-BMI1BMI2-NEXT: testb $32, %bl 640; X86-BMI1BMI2-NEXT: je .LBB7_4 641; X86-BMI1BMI2-NEXT: # %bb.3: 642; X86-BMI1BMI2-NEXT: movl %eax, %edx 643; X86-BMI1BMI2-NEXT: xorl %eax, %eax 644; X86-BMI1BMI2-NEXT: .LBB7_4: 645; X86-BMI1BMI2-NEXT: addl $-1, %eax 646; X86-BMI1BMI2-NEXT: adcl $-1, %edx 647; X86-BMI1BMI2-NEXT: andl %esi, %eax 648; X86-BMI1BMI2-NEXT: andl %edi, %edx 649; X86-BMI1BMI2-NEXT: popl %esi 650; X86-BMI1BMI2-NEXT: popl %edi 651; X86-BMI1BMI2-NEXT: popl %ebx 652; X86-BMI1BMI2-NEXT: retl 653; 654; X64-NOBMI-LABEL: bextr64_a0: 655; X64-NOBMI: # %bb.0: 656; X64-NOBMI-NEXT: movq %rsi, %rcx 657; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 658; X64-NOBMI-NEXT: shrq %cl, %rdi 659; X64-NOBMI-NEXT: movl $1, %eax 660; X64-NOBMI-NEXT: movl %edx, %ecx 661; X64-NOBMI-NEXT: shlq %cl, %rax 662; X64-NOBMI-NEXT: decq %rax 663; X64-NOBMI-NEXT: andq %rdi, %rax 664; X64-NOBMI-NEXT: retq 665; 666; X64-BMI1NOTBM-LABEL: bextr64_a0: 667; X64-BMI1NOTBM: # %bb.0: 668; X64-BMI1NOTBM-NEXT: shll $8, %edx 669; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 670; X64-BMI1NOTBM-NEXT: orl %edx, %eax 671; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 672; X64-BMI1NOTBM-NEXT: retq 673; 674; X64-BMI1BMI2-LABEL: bextr64_a0: 675; X64-BMI1BMI2: # %bb.0: 676; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 677; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 678; X64-BMI1BMI2-NEXT: retq 679 %shifted = lshr i64 %val, %numskipbits 680 %onebit = shl i64 1, %numlowbits 681 %mask = add nsw i64 %onebit, -1 682 %masked = and i64 %mask, %shifted 683 ret i64 %masked 684} 685 686define i64 @bextr64_a0_arithmetic(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 687; X86-NOBMI-LABEL: bextr64_a0_arithmetic: 688; X86-NOBMI: # %bb.0: 689; X86-NOBMI-NEXT: pushl %edi 690; X86-NOBMI-NEXT: pushl %esi 691; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 692; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 693; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 694; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 695; X86-NOBMI-NEXT: movl %eax, %esi 696; X86-NOBMI-NEXT: sarl %cl, %esi 697; X86-NOBMI-NEXT: shrdl %cl, %eax, %edi 698; X86-NOBMI-NEXT: testb $32, %cl 699; X86-NOBMI-NEXT: je .LBB8_2 700; X86-NOBMI-NEXT: # %bb.1: 701; X86-NOBMI-NEXT: sarl $31, %eax 702; X86-NOBMI-NEXT: movl %esi, %edi 703; X86-NOBMI-NEXT: movl %eax, %esi 704; X86-NOBMI-NEXT: .LBB8_2: 705; X86-NOBMI-NEXT: movl $1, %eax 706; X86-NOBMI-NEXT: xorl %edx, %edx 707; X86-NOBMI-NEXT: movb %ch, %cl 708; X86-NOBMI-NEXT: shldl %cl, %eax, %edx 709; X86-NOBMI-NEXT: shll %cl, %eax 710; X86-NOBMI-NEXT: testb $32, %ch 711; X86-NOBMI-NEXT: je .LBB8_4 712; X86-NOBMI-NEXT: # %bb.3: 713; X86-NOBMI-NEXT: movl %eax, %edx 714; X86-NOBMI-NEXT: xorl %eax, %eax 715; X86-NOBMI-NEXT: .LBB8_4: 716; X86-NOBMI-NEXT: addl $-1, %eax 717; X86-NOBMI-NEXT: adcl $-1, %edx 718; X86-NOBMI-NEXT: andl %edi, %eax 719; X86-NOBMI-NEXT: andl %esi, %edx 720; X86-NOBMI-NEXT: popl %esi 721; X86-NOBMI-NEXT: popl %edi 722; X86-NOBMI-NEXT: retl 723; 724; X86-BMI1NOTBM-LABEL: bextr64_a0_arithmetic: 725; X86-BMI1NOTBM: # %bb.0: 726; X86-BMI1NOTBM-NEXT: pushl %edi 727; X86-BMI1NOTBM-NEXT: pushl %esi 728; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %ch 729; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 730; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 731; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 732; X86-BMI1NOTBM-NEXT: movl %eax, %esi 733; X86-BMI1NOTBM-NEXT: sarl %cl, %esi 734; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %edi 735; X86-BMI1NOTBM-NEXT: testb $32, %cl 736; X86-BMI1NOTBM-NEXT: je .LBB8_2 737; X86-BMI1NOTBM-NEXT: # %bb.1: 738; X86-BMI1NOTBM-NEXT: sarl $31, %eax 739; X86-BMI1NOTBM-NEXT: movl %esi, %edi 740; X86-BMI1NOTBM-NEXT: movl %eax, %esi 741; X86-BMI1NOTBM-NEXT: .LBB8_2: 742; X86-BMI1NOTBM-NEXT: movl $1, %eax 743; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 744; X86-BMI1NOTBM-NEXT: movb %ch, %cl 745; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx 746; X86-BMI1NOTBM-NEXT: shll %cl, %eax 747; X86-BMI1NOTBM-NEXT: testb $32, %ch 748; X86-BMI1NOTBM-NEXT: je .LBB8_4 749; X86-BMI1NOTBM-NEXT: # %bb.3: 750; X86-BMI1NOTBM-NEXT: movl %eax, %edx 751; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 752; X86-BMI1NOTBM-NEXT: .LBB8_4: 753; X86-BMI1NOTBM-NEXT: addl $-1, %eax 754; X86-BMI1NOTBM-NEXT: adcl $-1, %edx 755; X86-BMI1NOTBM-NEXT: andl %edi, %eax 756; X86-BMI1NOTBM-NEXT: andl %esi, %edx 757; X86-BMI1NOTBM-NEXT: popl %esi 758; X86-BMI1NOTBM-NEXT: popl %edi 759; X86-BMI1NOTBM-NEXT: retl 760; 761; X86-BMI1BMI2-LABEL: bextr64_a0_arithmetic: 762; X86-BMI1BMI2: # %bb.0: 763; X86-BMI1BMI2-NEXT: pushl %ebx 764; X86-BMI1BMI2-NEXT: pushl %edi 765; X86-BMI1BMI2-NEXT: pushl %esi 766; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 767; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 768; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 769; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 770; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 771; X86-BMI1BMI2-NEXT: sarxl %ecx, %eax, %edi 772; X86-BMI1BMI2-NEXT: testb $32, %cl 773; X86-BMI1BMI2-NEXT: je .LBB8_2 774; X86-BMI1BMI2-NEXT: # %bb.1: 775; X86-BMI1BMI2-NEXT: sarl $31, %eax 776; X86-BMI1BMI2-NEXT: movl %edi, %esi 777; X86-BMI1BMI2-NEXT: movl %eax, %edi 778; X86-BMI1BMI2-NEXT: .LBB8_2: 779; X86-BMI1BMI2-NEXT: movl $1, %eax 780; X86-BMI1BMI2-NEXT: xorl %edx, %edx 781; X86-BMI1BMI2-NEXT: movl %ebx, %ecx 782; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx 783; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 784; X86-BMI1BMI2-NEXT: testb $32, %bl 785; X86-BMI1BMI2-NEXT: je .LBB8_4 786; X86-BMI1BMI2-NEXT: # %bb.3: 787; X86-BMI1BMI2-NEXT: movl %eax, %edx 788; X86-BMI1BMI2-NEXT: xorl %eax, %eax 789; X86-BMI1BMI2-NEXT: .LBB8_4: 790; X86-BMI1BMI2-NEXT: addl $-1, %eax 791; X86-BMI1BMI2-NEXT: adcl $-1, %edx 792; X86-BMI1BMI2-NEXT: andl %esi, %eax 793; X86-BMI1BMI2-NEXT: andl %edi, %edx 794; X86-BMI1BMI2-NEXT: popl %esi 795; X86-BMI1BMI2-NEXT: popl %edi 796; X86-BMI1BMI2-NEXT: popl %ebx 797; X86-BMI1BMI2-NEXT: retl 798; 799; X64-NOBMI-LABEL: bextr64_a0_arithmetic: 800; X64-NOBMI: # %bb.0: 801; X64-NOBMI-NEXT: movq %rsi, %rcx 802; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 803; X64-NOBMI-NEXT: sarq %cl, %rdi 804; X64-NOBMI-NEXT: movl $1, %eax 805; X64-NOBMI-NEXT: movl %edx, %ecx 806; X64-NOBMI-NEXT: shlq %cl, %rax 807; X64-NOBMI-NEXT: decq %rax 808; X64-NOBMI-NEXT: andq %rdi, %rax 809; X64-NOBMI-NEXT: retq 810; 811; X64-BMI1NOTBM-LABEL: bextr64_a0_arithmetic: 812; X64-BMI1NOTBM: # %bb.0: 813; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx 814; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx 815; X64-BMI1NOTBM-NEXT: sarq %cl, %rdi 816; X64-BMI1NOTBM-NEXT: shll $8, %edx 817; X64-BMI1NOTBM-NEXT: bextrq %rdx, %rdi, %rax 818; X64-BMI1NOTBM-NEXT: retq 819; 820; X64-BMI1BMI2-LABEL: bextr64_a0_arithmetic: 821; X64-BMI1BMI2: # %bb.0: 822; X64-BMI1BMI2-NEXT: sarxq %rsi, %rdi, %rax 823; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 824; X64-BMI1BMI2-NEXT: retq 825 %shifted = ashr i64 %val, %numskipbits 826 %onebit = shl i64 1, %numlowbits 827 %mask = add nsw i64 %onebit, -1 828 %masked = and i64 %mask, %shifted 829 ret i64 %masked 830} 831 832define i64 @bextr64_a1_indexzext(i64 %val, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 833; X86-NOBMI-LABEL: bextr64_a1_indexzext: 834; X86-NOBMI: # %bb.0: 835; X86-NOBMI-NEXT: pushl %edi 836; X86-NOBMI-NEXT: pushl %esi 837; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 838; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 839; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 840; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 841; X86-NOBMI-NEXT: movl %eax, %edi 842; X86-NOBMI-NEXT: shrl %cl, %edi 843; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 844; X86-NOBMI-NEXT: testb $32, %cl 845; X86-NOBMI-NEXT: je .LBB9_2 846; X86-NOBMI-NEXT: # %bb.1: 847; X86-NOBMI-NEXT: movl %edi, %esi 848; X86-NOBMI-NEXT: xorl %edi, %edi 849; X86-NOBMI-NEXT: .LBB9_2: 850; X86-NOBMI-NEXT: movl $1, %eax 851; X86-NOBMI-NEXT: xorl %edx, %edx 852; X86-NOBMI-NEXT: movb %ch, %cl 853; X86-NOBMI-NEXT: shldl %cl, %eax, %edx 854; X86-NOBMI-NEXT: shll %cl, %eax 855; X86-NOBMI-NEXT: testb $32, %ch 856; X86-NOBMI-NEXT: je .LBB9_4 857; X86-NOBMI-NEXT: # %bb.3: 858; X86-NOBMI-NEXT: movl %eax, %edx 859; X86-NOBMI-NEXT: xorl %eax, %eax 860; X86-NOBMI-NEXT: .LBB9_4: 861; X86-NOBMI-NEXT: addl $-1, %eax 862; X86-NOBMI-NEXT: adcl $-1, %edx 863; X86-NOBMI-NEXT: andl %esi, %eax 864; X86-NOBMI-NEXT: andl %edi, %edx 865; X86-NOBMI-NEXT: popl %esi 866; X86-NOBMI-NEXT: popl %edi 867; X86-NOBMI-NEXT: retl 868; 869; X86-BMI1NOTBM-LABEL: bextr64_a1_indexzext: 870; X86-BMI1NOTBM: # %bb.0: 871; X86-BMI1NOTBM-NEXT: pushl %edi 872; X86-BMI1NOTBM-NEXT: pushl %esi 873; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %ch 874; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 875; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 876; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 877; X86-BMI1NOTBM-NEXT: movl %eax, %edi 878; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 879; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 880; X86-BMI1NOTBM-NEXT: testb $32, %cl 881; X86-BMI1NOTBM-NEXT: je .LBB9_2 882; X86-BMI1NOTBM-NEXT: # %bb.1: 883; X86-BMI1NOTBM-NEXT: movl %edi, %esi 884; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 885; X86-BMI1NOTBM-NEXT: .LBB9_2: 886; X86-BMI1NOTBM-NEXT: movl $1, %eax 887; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 888; X86-BMI1NOTBM-NEXT: movb %ch, %cl 889; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx 890; X86-BMI1NOTBM-NEXT: shll %cl, %eax 891; X86-BMI1NOTBM-NEXT: testb $32, %ch 892; X86-BMI1NOTBM-NEXT: je .LBB9_4 893; X86-BMI1NOTBM-NEXT: # %bb.3: 894; X86-BMI1NOTBM-NEXT: movl %eax, %edx 895; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 896; X86-BMI1NOTBM-NEXT: .LBB9_4: 897; X86-BMI1NOTBM-NEXT: addl $-1, %eax 898; X86-BMI1NOTBM-NEXT: adcl $-1, %edx 899; X86-BMI1NOTBM-NEXT: andl %esi, %eax 900; X86-BMI1NOTBM-NEXT: andl %edi, %edx 901; X86-BMI1NOTBM-NEXT: popl %esi 902; X86-BMI1NOTBM-NEXT: popl %edi 903; X86-BMI1NOTBM-NEXT: retl 904; 905; X86-BMI1BMI2-LABEL: bextr64_a1_indexzext: 906; X86-BMI1BMI2: # %bb.0: 907; X86-BMI1BMI2-NEXT: pushl %ebx 908; X86-BMI1BMI2-NEXT: pushl %edi 909; X86-BMI1BMI2-NEXT: pushl %esi 910; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 911; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 912; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 913; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 914; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 915; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 916; X86-BMI1BMI2-NEXT: testb $32, %cl 917; X86-BMI1BMI2-NEXT: je .LBB9_2 918; X86-BMI1BMI2-NEXT: # %bb.1: 919; X86-BMI1BMI2-NEXT: movl %edi, %esi 920; X86-BMI1BMI2-NEXT: xorl %edi, %edi 921; X86-BMI1BMI2-NEXT: .LBB9_2: 922; X86-BMI1BMI2-NEXT: movl $1, %eax 923; X86-BMI1BMI2-NEXT: xorl %edx, %edx 924; X86-BMI1BMI2-NEXT: movl %ebx, %ecx 925; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx 926; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 927; X86-BMI1BMI2-NEXT: testb $32, %bl 928; X86-BMI1BMI2-NEXT: je .LBB9_4 929; X86-BMI1BMI2-NEXT: # %bb.3: 930; X86-BMI1BMI2-NEXT: movl %eax, %edx 931; X86-BMI1BMI2-NEXT: xorl %eax, %eax 932; X86-BMI1BMI2-NEXT: .LBB9_4: 933; X86-BMI1BMI2-NEXT: addl $-1, %eax 934; X86-BMI1BMI2-NEXT: adcl $-1, %edx 935; X86-BMI1BMI2-NEXT: andl %esi, %eax 936; X86-BMI1BMI2-NEXT: andl %edi, %edx 937; X86-BMI1BMI2-NEXT: popl %esi 938; X86-BMI1BMI2-NEXT: popl %edi 939; X86-BMI1BMI2-NEXT: popl %ebx 940; X86-BMI1BMI2-NEXT: retl 941; 942; X64-NOBMI-LABEL: bextr64_a1_indexzext: 943; X64-NOBMI: # %bb.0: 944; X64-NOBMI-NEXT: movl %esi, %ecx 945; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 946; X64-NOBMI-NEXT: shrq %cl, %rdi 947; X64-NOBMI-NEXT: movl $1, %eax 948; X64-NOBMI-NEXT: movl %edx, %ecx 949; X64-NOBMI-NEXT: shlq %cl, %rax 950; X64-NOBMI-NEXT: decq %rax 951; X64-NOBMI-NEXT: andq %rdi, %rax 952; X64-NOBMI-NEXT: retq 953; 954; X64-BMI1NOTBM-LABEL: bextr64_a1_indexzext: 955; X64-BMI1NOTBM: # %bb.0: 956; X64-BMI1NOTBM-NEXT: shll $8, %edx 957; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 958; X64-BMI1NOTBM-NEXT: orl %edx, %eax 959; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 960; X64-BMI1NOTBM-NEXT: retq 961; 962; X64-BMI1BMI2-LABEL: bextr64_a1_indexzext: 963; X64-BMI1BMI2: # %bb.0: 964; X64-BMI1BMI2-NEXT: # kill: def $edx killed $edx def $rdx 965; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 966; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 967; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 968; X64-BMI1BMI2-NEXT: retq 969 %skip = zext i8 %numskipbits to i64 970 %shifted = lshr i64 %val, %skip 971 %conv = zext i8 %numlowbits to i64 972 %onebit = shl i64 1, %conv 973 %mask = add nsw i64 %onebit, -1 974 %masked = and i64 %mask, %shifted 975 ret i64 %masked 976} 977 978define i64 @bextr64_a2_load(i64* %w, i64 %numskipbits, i64 %numlowbits) nounwind { 979; X86-NOBMI-LABEL: bextr64_a2_load: 980; X86-NOBMI: # %bb.0: 981; X86-NOBMI-NEXT: pushl %edi 982; X86-NOBMI-NEXT: pushl %esi 983; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 984; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 985; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 986; X86-NOBMI-NEXT: movl (%eax), %esi 987; X86-NOBMI-NEXT: movl 4(%eax), %eax 988; X86-NOBMI-NEXT: movl %eax, %edi 989; X86-NOBMI-NEXT: shrl %cl, %edi 990; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 991; X86-NOBMI-NEXT: testb $32, %cl 992; X86-NOBMI-NEXT: je .LBB10_2 993; X86-NOBMI-NEXT: # %bb.1: 994; X86-NOBMI-NEXT: movl %edi, %esi 995; X86-NOBMI-NEXT: xorl %edi, %edi 996; X86-NOBMI-NEXT: .LBB10_2: 997; X86-NOBMI-NEXT: movl $1, %eax 998; X86-NOBMI-NEXT: xorl %edx, %edx 999; X86-NOBMI-NEXT: movb %ch, %cl 1000; X86-NOBMI-NEXT: shldl %cl, %eax, %edx 1001; X86-NOBMI-NEXT: shll %cl, %eax 1002; X86-NOBMI-NEXT: testb $32, %ch 1003; X86-NOBMI-NEXT: je .LBB10_4 1004; X86-NOBMI-NEXT: # %bb.3: 1005; X86-NOBMI-NEXT: movl %eax, %edx 1006; X86-NOBMI-NEXT: xorl %eax, %eax 1007; X86-NOBMI-NEXT: .LBB10_4: 1008; X86-NOBMI-NEXT: addl $-1, %eax 1009; X86-NOBMI-NEXT: adcl $-1, %edx 1010; X86-NOBMI-NEXT: andl %esi, %eax 1011; X86-NOBMI-NEXT: andl %edi, %edx 1012; X86-NOBMI-NEXT: popl %esi 1013; X86-NOBMI-NEXT: popl %edi 1014; X86-NOBMI-NEXT: retl 1015; 1016; X86-BMI1NOTBM-LABEL: bextr64_a2_load: 1017; X86-BMI1NOTBM: # %bb.0: 1018; X86-BMI1NOTBM-NEXT: pushl %edi 1019; X86-BMI1NOTBM-NEXT: pushl %esi 1020; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %ch 1021; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 1022; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 1023; X86-BMI1NOTBM-NEXT: movl (%eax), %esi 1024; X86-BMI1NOTBM-NEXT: movl 4(%eax), %eax 1025; X86-BMI1NOTBM-NEXT: movl %eax, %edi 1026; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 1027; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 1028; X86-BMI1NOTBM-NEXT: testb $32, %cl 1029; X86-BMI1NOTBM-NEXT: je .LBB10_2 1030; X86-BMI1NOTBM-NEXT: # %bb.1: 1031; X86-BMI1NOTBM-NEXT: movl %edi, %esi 1032; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 1033; X86-BMI1NOTBM-NEXT: .LBB10_2: 1034; X86-BMI1NOTBM-NEXT: movl $1, %eax 1035; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 1036; X86-BMI1NOTBM-NEXT: movb %ch, %cl 1037; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx 1038; X86-BMI1NOTBM-NEXT: shll %cl, %eax 1039; X86-BMI1NOTBM-NEXT: testb $32, %ch 1040; X86-BMI1NOTBM-NEXT: je .LBB10_4 1041; X86-BMI1NOTBM-NEXT: # %bb.3: 1042; X86-BMI1NOTBM-NEXT: movl %eax, %edx 1043; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 1044; X86-BMI1NOTBM-NEXT: .LBB10_4: 1045; X86-BMI1NOTBM-NEXT: addl $-1, %eax 1046; X86-BMI1NOTBM-NEXT: adcl $-1, %edx 1047; X86-BMI1NOTBM-NEXT: andl %esi, %eax 1048; X86-BMI1NOTBM-NEXT: andl %edi, %edx 1049; X86-BMI1NOTBM-NEXT: popl %esi 1050; X86-BMI1NOTBM-NEXT: popl %edi 1051; X86-BMI1NOTBM-NEXT: retl 1052; 1053; X86-BMI1BMI2-LABEL: bextr64_a2_load: 1054; X86-BMI1BMI2: # %bb.0: 1055; X86-BMI1BMI2-NEXT: pushl %ebx 1056; X86-BMI1BMI2-NEXT: pushl %edi 1057; X86-BMI1BMI2-NEXT: pushl %esi 1058; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 1059; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 1060; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 1061; X86-BMI1BMI2-NEXT: movl (%eax), %esi 1062; X86-BMI1BMI2-NEXT: movl 4(%eax), %eax 1063; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 1064; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 1065; X86-BMI1BMI2-NEXT: testb $32, %cl 1066; X86-BMI1BMI2-NEXT: je .LBB10_2 1067; X86-BMI1BMI2-NEXT: # %bb.1: 1068; X86-BMI1BMI2-NEXT: movl %edi, %esi 1069; X86-BMI1BMI2-NEXT: xorl %edi, %edi 1070; X86-BMI1BMI2-NEXT: .LBB10_2: 1071; X86-BMI1BMI2-NEXT: movl $1, %eax 1072; X86-BMI1BMI2-NEXT: xorl %edx, %edx 1073; X86-BMI1BMI2-NEXT: movl %ebx, %ecx 1074; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx 1075; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 1076; X86-BMI1BMI2-NEXT: testb $32, %bl 1077; X86-BMI1BMI2-NEXT: je .LBB10_4 1078; X86-BMI1BMI2-NEXT: # %bb.3: 1079; X86-BMI1BMI2-NEXT: movl %eax, %edx 1080; X86-BMI1BMI2-NEXT: xorl %eax, %eax 1081; X86-BMI1BMI2-NEXT: .LBB10_4: 1082; X86-BMI1BMI2-NEXT: addl $-1, %eax 1083; X86-BMI1BMI2-NEXT: adcl $-1, %edx 1084; X86-BMI1BMI2-NEXT: andl %esi, %eax 1085; X86-BMI1BMI2-NEXT: andl %edi, %edx 1086; X86-BMI1BMI2-NEXT: popl %esi 1087; X86-BMI1BMI2-NEXT: popl %edi 1088; X86-BMI1BMI2-NEXT: popl %ebx 1089; X86-BMI1BMI2-NEXT: retl 1090; 1091; X64-NOBMI-LABEL: bextr64_a2_load: 1092; X64-NOBMI: # %bb.0: 1093; X64-NOBMI-NEXT: movq %rsi, %rcx 1094; X64-NOBMI-NEXT: movq (%rdi), %rsi 1095; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 1096; X64-NOBMI-NEXT: shrq %cl, %rsi 1097; X64-NOBMI-NEXT: movl $1, %eax 1098; X64-NOBMI-NEXT: movl %edx, %ecx 1099; X64-NOBMI-NEXT: shlq %cl, %rax 1100; X64-NOBMI-NEXT: decq %rax 1101; X64-NOBMI-NEXT: andq %rsi, %rax 1102; X64-NOBMI-NEXT: retq 1103; 1104; X64-BMI1NOTBM-LABEL: bextr64_a2_load: 1105; X64-BMI1NOTBM: # %bb.0: 1106; X64-BMI1NOTBM-NEXT: shll $8, %edx 1107; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 1108; X64-BMI1NOTBM-NEXT: orl %edx, %eax 1109; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax 1110; X64-BMI1NOTBM-NEXT: retq 1111; 1112; X64-BMI1BMI2-LABEL: bextr64_a2_load: 1113; X64-BMI1BMI2: # %bb.0: 1114; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %rax 1115; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 1116; X64-BMI1BMI2-NEXT: retq 1117 %val = load i64, i64* %w 1118 %shifted = lshr i64 %val, %numskipbits 1119 %onebit = shl i64 1, %numlowbits 1120 %mask = add nsw i64 %onebit, -1 1121 %masked = and i64 %mask, %shifted 1122 ret i64 %masked 1123} 1124 1125define i64 @bextr64_a3_load_indexzext(i64* %w, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 1126; X86-NOBMI-LABEL: bextr64_a3_load_indexzext: 1127; X86-NOBMI: # %bb.0: 1128; X86-NOBMI-NEXT: pushl %edi 1129; X86-NOBMI-NEXT: pushl %esi 1130; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 1131; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 1132; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1133; X86-NOBMI-NEXT: movl (%eax), %esi 1134; X86-NOBMI-NEXT: movl 4(%eax), %eax 1135; X86-NOBMI-NEXT: movl %eax, %edi 1136; X86-NOBMI-NEXT: shrl %cl, %edi 1137; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 1138; X86-NOBMI-NEXT: testb $32, %cl 1139; X86-NOBMI-NEXT: je .LBB11_2 1140; X86-NOBMI-NEXT: # %bb.1: 1141; X86-NOBMI-NEXT: movl %edi, %esi 1142; X86-NOBMI-NEXT: xorl %edi, %edi 1143; X86-NOBMI-NEXT: .LBB11_2: 1144; X86-NOBMI-NEXT: movl $1, %eax 1145; X86-NOBMI-NEXT: xorl %edx, %edx 1146; X86-NOBMI-NEXT: movb %ch, %cl 1147; X86-NOBMI-NEXT: shldl %cl, %eax, %edx 1148; X86-NOBMI-NEXT: shll %cl, %eax 1149; X86-NOBMI-NEXT: testb $32, %ch 1150; X86-NOBMI-NEXT: je .LBB11_4 1151; X86-NOBMI-NEXT: # %bb.3: 1152; X86-NOBMI-NEXT: movl %eax, %edx 1153; X86-NOBMI-NEXT: xorl %eax, %eax 1154; X86-NOBMI-NEXT: .LBB11_4: 1155; X86-NOBMI-NEXT: addl $-1, %eax 1156; X86-NOBMI-NEXT: adcl $-1, %edx 1157; X86-NOBMI-NEXT: andl %esi, %eax 1158; X86-NOBMI-NEXT: andl %edi, %edx 1159; X86-NOBMI-NEXT: popl %esi 1160; X86-NOBMI-NEXT: popl %edi 1161; X86-NOBMI-NEXT: retl 1162; 1163; X86-BMI1NOTBM-LABEL: bextr64_a3_load_indexzext: 1164; X86-BMI1NOTBM: # %bb.0: 1165; X86-BMI1NOTBM-NEXT: pushl %edi 1166; X86-BMI1NOTBM-NEXT: pushl %esi 1167; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %ch 1168; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 1169; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 1170; X86-BMI1NOTBM-NEXT: movl (%eax), %esi 1171; X86-BMI1NOTBM-NEXT: movl 4(%eax), %eax 1172; X86-BMI1NOTBM-NEXT: movl %eax, %edi 1173; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 1174; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 1175; X86-BMI1NOTBM-NEXT: testb $32, %cl 1176; X86-BMI1NOTBM-NEXT: je .LBB11_2 1177; X86-BMI1NOTBM-NEXT: # %bb.1: 1178; X86-BMI1NOTBM-NEXT: movl %edi, %esi 1179; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 1180; X86-BMI1NOTBM-NEXT: .LBB11_2: 1181; X86-BMI1NOTBM-NEXT: movl $1, %eax 1182; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 1183; X86-BMI1NOTBM-NEXT: movb %ch, %cl 1184; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx 1185; X86-BMI1NOTBM-NEXT: shll %cl, %eax 1186; X86-BMI1NOTBM-NEXT: testb $32, %ch 1187; X86-BMI1NOTBM-NEXT: je .LBB11_4 1188; X86-BMI1NOTBM-NEXT: # %bb.3: 1189; X86-BMI1NOTBM-NEXT: movl %eax, %edx 1190; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 1191; X86-BMI1NOTBM-NEXT: .LBB11_4: 1192; X86-BMI1NOTBM-NEXT: addl $-1, %eax 1193; X86-BMI1NOTBM-NEXT: adcl $-1, %edx 1194; X86-BMI1NOTBM-NEXT: andl %esi, %eax 1195; X86-BMI1NOTBM-NEXT: andl %edi, %edx 1196; X86-BMI1NOTBM-NEXT: popl %esi 1197; X86-BMI1NOTBM-NEXT: popl %edi 1198; X86-BMI1NOTBM-NEXT: retl 1199; 1200; X86-BMI1BMI2-LABEL: bextr64_a3_load_indexzext: 1201; X86-BMI1BMI2: # %bb.0: 1202; X86-BMI1BMI2-NEXT: pushl %ebx 1203; X86-BMI1BMI2-NEXT: pushl %edi 1204; X86-BMI1BMI2-NEXT: pushl %esi 1205; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 1206; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 1207; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 1208; X86-BMI1BMI2-NEXT: movl (%eax), %esi 1209; X86-BMI1BMI2-NEXT: movl 4(%eax), %eax 1210; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 1211; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 1212; X86-BMI1BMI2-NEXT: testb $32, %cl 1213; X86-BMI1BMI2-NEXT: je .LBB11_2 1214; X86-BMI1BMI2-NEXT: # %bb.1: 1215; X86-BMI1BMI2-NEXT: movl %edi, %esi 1216; X86-BMI1BMI2-NEXT: xorl %edi, %edi 1217; X86-BMI1BMI2-NEXT: .LBB11_2: 1218; X86-BMI1BMI2-NEXT: movl $1, %eax 1219; X86-BMI1BMI2-NEXT: xorl %edx, %edx 1220; X86-BMI1BMI2-NEXT: movl %ebx, %ecx 1221; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx 1222; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 1223; X86-BMI1BMI2-NEXT: testb $32, %bl 1224; X86-BMI1BMI2-NEXT: je .LBB11_4 1225; X86-BMI1BMI2-NEXT: # %bb.3: 1226; X86-BMI1BMI2-NEXT: movl %eax, %edx 1227; X86-BMI1BMI2-NEXT: xorl %eax, %eax 1228; X86-BMI1BMI2-NEXT: .LBB11_4: 1229; X86-BMI1BMI2-NEXT: addl $-1, %eax 1230; X86-BMI1BMI2-NEXT: adcl $-1, %edx 1231; X86-BMI1BMI2-NEXT: andl %esi, %eax 1232; X86-BMI1BMI2-NEXT: andl %edi, %edx 1233; X86-BMI1BMI2-NEXT: popl %esi 1234; X86-BMI1BMI2-NEXT: popl %edi 1235; X86-BMI1BMI2-NEXT: popl %ebx 1236; X86-BMI1BMI2-NEXT: retl 1237; 1238; X64-NOBMI-LABEL: bextr64_a3_load_indexzext: 1239; X64-NOBMI: # %bb.0: 1240; X64-NOBMI-NEXT: movl %esi, %ecx 1241; X64-NOBMI-NEXT: movq (%rdi), %rsi 1242; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 1243; X64-NOBMI-NEXT: shrq %cl, %rsi 1244; X64-NOBMI-NEXT: movl $1, %eax 1245; X64-NOBMI-NEXT: movl %edx, %ecx 1246; X64-NOBMI-NEXT: shlq %cl, %rax 1247; X64-NOBMI-NEXT: decq %rax 1248; X64-NOBMI-NEXT: andq %rsi, %rax 1249; X64-NOBMI-NEXT: retq 1250; 1251; X64-BMI1NOTBM-LABEL: bextr64_a3_load_indexzext: 1252; X64-BMI1NOTBM: # %bb.0: 1253; X64-BMI1NOTBM-NEXT: shll $8, %edx 1254; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 1255; X64-BMI1NOTBM-NEXT: orl %edx, %eax 1256; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax 1257; X64-BMI1NOTBM-NEXT: retq 1258; 1259; X64-BMI1BMI2-LABEL: bextr64_a3_load_indexzext: 1260; X64-BMI1BMI2: # %bb.0: 1261; X64-BMI1BMI2-NEXT: # kill: def $edx killed $edx def $rdx 1262; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 1263; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %rax 1264; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 1265; X64-BMI1BMI2-NEXT: retq 1266 %val = load i64, i64* %w 1267 %skip = zext i8 %numskipbits to i64 1268 %shifted = lshr i64 %val, %skip 1269 %conv = zext i8 %numlowbits to i64 1270 %onebit = shl i64 1, %conv 1271 %mask = add nsw i64 %onebit, -1 1272 %masked = and i64 %mask, %shifted 1273 ret i64 %masked 1274} 1275 1276define i64 @bextr64_a4_commutative(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 1277; X86-NOBMI-LABEL: bextr64_a4_commutative: 1278; X86-NOBMI: # %bb.0: 1279; X86-NOBMI-NEXT: pushl %edi 1280; X86-NOBMI-NEXT: pushl %esi 1281; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 1282; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 1283; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1284; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 1285; X86-NOBMI-NEXT: movl %esi, %edx 1286; X86-NOBMI-NEXT: shrl %cl, %edx 1287; X86-NOBMI-NEXT: shrdl %cl, %esi, %eax 1288; X86-NOBMI-NEXT: testb $32, %cl 1289; X86-NOBMI-NEXT: je .LBB12_2 1290; X86-NOBMI-NEXT: # %bb.1: 1291; X86-NOBMI-NEXT: movl %edx, %eax 1292; X86-NOBMI-NEXT: xorl %edx, %edx 1293; X86-NOBMI-NEXT: .LBB12_2: 1294; X86-NOBMI-NEXT: movl $1, %esi 1295; X86-NOBMI-NEXT: xorl %edi, %edi 1296; X86-NOBMI-NEXT: movb %ch, %cl 1297; X86-NOBMI-NEXT: shldl %cl, %esi, %edi 1298; X86-NOBMI-NEXT: shll %cl, %esi 1299; X86-NOBMI-NEXT: testb $32, %ch 1300; X86-NOBMI-NEXT: je .LBB12_4 1301; X86-NOBMI-NEXT: # %bb.3: 1302; X86-NOBMI-NEXT: movl %esi, %edi 1303; X86-NOBMI-NEXT: xorl %esi, %esi 1304; X86-NOBMI-NEXT: .LBB12_4: 1305; X86-NOBMI-NEXT: addl $-1, %esi 1306; X86-NOBMI-NEXT: adcl $-1, %edi 1307; X86-NOBMI-NEXT: andl %esi, %eax 1308; X86-NOBMI-NEXT: andl %edi, %edx 1309; X86-NOBMI-NEXT: popl %esi 1310; X86-NOBMI-NEXT: popl %edi 1311; X86-NOBMI-NEXT: retl 1312; 1313; X86-BMI1NOTBM-LABEL: bextr64_a4_commutative: 1314; X86-BMI1NOTBM: # %bb.0: 1315; X86-BMI1NOTBM-NEXT: pushl %edi 1316; X86-BMI1NOTBM-NEXT: pushl %esi 1317; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %ch 1318; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 1319; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 1320; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 1321; X86-BMI1NOTBM-NEXT: movl %esi, %edx 1322; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 1323; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %eax 1324; X86-BMI1NOTBM-NEXT: testb $32, %cl 1325; X86-BMI1NOTBM-NEXT: je .LBB12_2 1326; X86-BMI1NOTBM-NEXT: # %bb.1: 1327; X86-BMI1NOTBM-NEXT: movl %edx, %eax 1328; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 1329; X86-BMI1NOTBM-NEXT: .LBB12_2: 1330; X86-BMI1NOTBM-NEXT: movl $1, %esi 1331; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 1332; X86-BMI1NOTBM-NEXT: movb %ch, %cl 1333; X86-BMI1NOTBM-NEXT: shldl %cl, %esi, %edi 1334; X86-BMI1NOTBM-NEXT: shll %cl, %esi 1335; X86-BMI1NOTBM-NEXT: testb $32, %ch 1336; X86-BMI1NOTBM-NEXT: je .LBB12_4 1337; X86-BMI1NOTBM-NEXT: # %bb.3: 1338; X86-BMI1NOTBM-NEXT: movl %esi, %edi 1339; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 1340; X86-BMI1NOTBM-NEXT: .LBB12_4: 1341; X86-BMI1NOTBM-NEXT: addl $-1, %esi 1342; X86-BMI1NOTBM-NEXT: adcl $-1, %edi 1343; X86-BMI1NOTBM-NEXT: andl %esi, %eax 1344; X86-BMI1NOTBM-NEXT: andl %edi, %edx 1345; X86-BMI1NOTBM-NEXT: popl %esi 1346; X86-BMI1NOTBM-NEXT: popl %edi 1347; X86-BMI1NOTBM-NEXT: retl 1348; 1349; X86-BMI1BMI2-LABEL: bextr64_a4_commutative: 1350; X86-BMI1BMI2: # %bb.0: 1351; X86-BMI1BMI2-NEXT: pushl %ebx 1352; X86-BMI1BMI2-NEXT: pushl %edi 1353; X86-BMI1BMI2-NEXT: pushl %esi 1354; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 1355; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 1356; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 1357; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 1358; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 1359; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edx 1360; X86-BMI1BMI2-NEXT: testb $32, %cl 1361; X86-BMI1BMI2-NEXT: je .LBB12_2 1362; X86-BMI1BMI2-NEXT: # %bb.1: 1363; X86-BMI1BMI2-NEXT: movl %edx, %eax 1364; X86-BMI1BMI2-NEXT: xorl %edx, %edx 1365; X86-BMI1BMI2-NEXT: .LBB12_2: 1366; X86-BMI1BMI2-NEXT: movl $1, %edi 1367; X86-BMI1BMI2-NEXT: xorl %esi, %esi 1368; X86-BMI1BMI2-NEXT: movl %ebx, %ecx 1369; X86-BMI1BMI2-NEXT: shldl %cl, %edi, %esi 1370; X86-BMI1BMI2-NEXT: shlxl %ebx, %edi, %ecx 1371; X86-BMI1BMI2-NEXT: testb $32, %bl 1372; X86-BMI1BMI2-NEXT: je .LBB12_4 1373; X86-BMI1BMI2-NEXT: # %bb.3: 1374; X86-BMI1BMI2-NEXT: movl %ecx, %esi 1375; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 1376; X86-BMI1BMI2-NEXT: .LBB12_4: 1377; X86-BMI1BMI2-NEXT: addl $-1, %ecx 1378; X86-BMI1BMI2-NEXT: adcl $-1, %esi 1379; X86-BMI1BMI2-NEXT: andl %ecx, %eax 1380; X86-BMI1BMI2-NEXT: andl %esi, %edx 1381; X86-BMI1BMI2-NEXT: popl %esi 1382; X86-BMI1BMI2-NEXT: popl %edi 1383; X86-BMI1BMI2-NEXT: popl %ebx 1384; X86-BMI1BMI2-NEXT: retl 1385; 1386; X64-NOBMI-LABEL: bextr64_a4_commutative: 1387; X64-NOBMI: # %bb.0: 1388; X64-NOBMI-NEXT: movq %rsi, %rcx 1389; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 1390; X64-NOBMI-NEXT: shrq %cl, %rdi 1391; X64-NOBMI-NEXT: movl $1, %eax 1392; X64-NOBMI-NEXT: movl %edx, %ecx 1393; X64-NOBMI-NEXT: shlq %cl, %rax 1394; X64-NOBMI-NEXT: decq %rax 1395; X64-NOBMI-NEXT: andq %rdi, %rax 1396; X64-NOBMI-NEXT: retq 1397; 1398; X64-BMI1NOTBM-LABEL: bextr64_a4_commutative: 1399; X64-BMI1NOTBM: # %bb.0: 1400; X64-BMI1NOTBM-NEXT: shll $8, %edx 1401; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 1402; X64-BMI1NOTBM-NEXT: orl %edx, %eax 1403; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 1404; X64-BMI1NOTBM-NEXT: retq 1405; 1406; X64-BMI1BMI2-LABEL: bextr64_a4_commutative: 1407; X64-BMI1BMI2: # %bb.0: 1408; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 1409; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 1410; X64-BMI1BMI2-NEXT: retq 1411 %shifted = lshr i64 %val, %numskipbits 1412 %onebit = shl i64 1, %numlowbits 1413 %mask = add nsw i64 %onebit, -1 1414 %masked = and i64 %shifted, %mask ; swapped order 1415 ret i64 %masked 1416} 1417 1418define i64 @bextr64_a5_skipextrauses(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 1419; X86-NOBMI-LABEL: bextr64_a5_skipextrauses: 1420; X86-NOBMI: # %bb.0: 1421; X86-NOBMI-NEXT: pushl %ebp 1422; X86-NOBMI-NEXT: pushl %ebx 1423; X86-NOBMI-NEXT: pushl %edi 1424; X86-NOBMI-NEXT: pushl %esi 1425; X86-NOBMI-NEXT: subl $12, %esp 1426; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 1427; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ebx 1428; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 1429; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1430; X86-NOBMI-NEXT: movl %esi, %ebp 1431; X86-NOBMI-NEXT: movl %eax, %ecx 1432; X86-NOBMI-NEXT: shrl %cl, %ebp 1433; X86-NOBMI-NEXT: shrdl %cl, %esi, %ebx 1434; X86-NOBMI-NEXT: testb $32, %al 1435; X86-NOBMI-NEXT: je .LBB13_2 1436; X86-NOBMI-NEXT: # %bb.1: 1437; X86-NOBMI-NEXT: movl %ebp, %ebx 1438; X86-NOBMI-NEXT: xorl %ebp, %ebp 1439; X86-NOBMI-NEXT: .LBB13_2: 1440; X86-NOBMI-NEXT: movl $1, %esi 1441; X86-NOBMI-NEXT: xorl %edi, %edi 1442; X86-NOBMI-NEXT: movl %edx, %ecx 1443; X86-NOBMI-NEXT: shldl %cl, %esi, %edi 1444; X86-NOBMI-NEXT: shll %cl, %esi 1445; X86-NOBMI-NEXT: testb $32, %dl 1446; X86-NOBMI-NEXT: je .LBB13_4 1447; X86-NOBMI-NEXT: # %bb.3: 1448; X86-NOBMI-NEXT: movl %esi, %edi 1449; X86-NOBMI-NEXT: xorl %esi, %esi 1450; X86-NOBMI-NEXT: .LBB13_4: 1451; X86-NOBMI-NEXT: addl $-1, %esi 1452; X86-NOBMI-NEXT: adcl $-1, %edi 1453; X86-NOBMI-NEXT: andl %ebx, %esi 1454; X86-NOBMI-NEXT: andl %ebp, %edi 1455; X86-NOBMI-NEXT: subl $8, %esp 1456; X86-NOBMI-NEXT: pushl {{[0-9]+}}(%esp) 1457; X86-NOBMI-NEXT: pushl %eax 1458; X86-NOBMI-NEXT: calll use64 1459; X86-NOBMI-NEXT: addl $16, %esp 1460; X86-NOBMI-NEXT: movl %esi, %eax 1461; X86-NOBMI-NEXT: movl %edi, %edx 1462; X86-NOBMI-NEXT: addl $12, %esp 1463; X86-NOBMI-NEXT: popl %esi 1464; X86-NOBMI-NEXT: popl %edi 1465; X86-NOBMI-NEXT: popl %ebx 1466; X86-NOBMI-NEXT: popl %ebp 1467; X86-NOBMI-NEXT: retl 1468; 1469; X86-BMI1NOTBM-LABEL: bextr64_a5_skipextrauses: 1470; X86-BMI1NOTBM: # %bb.0: 1471; X86-BMI1NOTBM-NEXT: pushl %ebp 1472; X86-BMI1NOTBM-NEXT: pushl %ebx 1473; X86-BMI1NOTBM-NEXT: pushl %edi 1474; X86-BMI1NOTBM-NEXT: pushl %esi 1475; X86-BMI1NOTBM-NEXT: subl $12, %esp 1476; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %dl 1477; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ebx 1478; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 1479; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 1480; X86-BMI1NOTBM-NEXT: movl %esi, %ebp 1481; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 1482; X86-BMI1NOTBM-NEXT: shrl %cl, %ebp 1483; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %ebx 1484; X86-BMI1NOTBM-NEXT: testb $32, %al 1485; X86-BMI1NOTBM-NEXT: je .LBB13_2 1486; X86-BMI1NOTBM-NEXT: # %bb.1: 1487; X86-BMI1NOTBM-NEXT: movl %ebp, %ebx 1488; X86-BMI1NOTBM-NEXT: xorl %ebp, %ebp 1489; X86-BMI1NOTBM-NEXT: .LBB13_2: 1490; X86-BMI1NOTBM-NEXT: movl $1, %esi 1491; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 1492; X86-BMI1NOTBM-NEXT: movl %edx, %ecx 1493; X86-BMI1NOTBM-NEXT: shldl %cl, %esi, %edi 1494; X86-BMI1NOTBM-NEXT: shll %cl, %esi 1495; X86-BMI1NOTBM-NEXT: testb $32, %dl 1496; X86-BMI1NOTBM-NEXT: je .LBB13_4 1497; X86-BMI1NOTBM-NEXT: # %bb.3: 1498; X86-BMI1NOTBM-NEXT: movl %esi, %edi 1499; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 1500; X86-BMI1NOTBM-NEXT: .LBB13_4: 1501; X86-BMI1NOTBM-NEXT: addl $-1, %esi 1502; X86-BMI1NOTBM-NEXT: adcl $-1, %edi 1503; X86-BMI1NOTBM-NEXT: andl %ebx, %esi 1504; X86-BMI1NOTBM-NEXT: andl %ebp, %edi 1505; X86-BMI1NOTBM-NEXT: subl $8, %esp 1506; X86-BMI1NOTBM-NEXT: pushl {{[0-9]+}}(%esp) 1507; X86-BMI1NOTBM-NEXT: pushl %eax 1508; X86-BMI1NOTBM-NEXT: calll use64 1509; X86-BMI1NOTBM-NEXT: addl $16, %esp 1510; X86-BMI1NOTBM-NEXT: movl %esi, %eax 1511; X86-BMI1NOTBM-NEXT: movl %edi, %edx 1512; X86-BMI1NOTBM-NEXT: addl $12, %esp 1513; X86-BMI1NOTBM-NEXT: popl %esi 1514; X86-BMI1NOTBM-NEXT: popl %edi 1515; X86-BMI1NOTBM-NEXT: popl %ebx 1516; X86-BMI1NOTBM-NEXT: popl %ebp 1517; X86-BMI1NOTBM-NEXT: retl 1518; 1519; X86-BMI1BMI2-LABEL: bextr64_a5_skipextrauses: 1520; X86-BMI1BMI2: # %bb.0: 1521; X86-BMI1BMI2-NEXT: pushl %ebp 1522; X86-BMI1BMI2-NEXT: pushl %ebx 1523; X86-BMI1BMI2-NEXT: pushl %edi 1524; X86-BMI1BMI2-NEXT: pushl %esi 1525; X86-BMI1BMI2-NEXT: subl $12, %esp 1526; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 1527; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ebx 1528; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 1529; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 1530; X86-BMI1BMI2-NEXT: movl %eax, %ecx 1531; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %ebx 1532; X86-BMI1BMI2-NEXT: shrxl %eax, %esi, %ebp 1533; X86-BMI1BMI2-NEXT: testb $32, %al 1534; X86-BMI1BMI2-NEXT: je .LBB13_2 1535; X86-BMI1BMI2-NEXT: # %bb.1: 1536; X86-BMI1BMI2-NEXT: movl %ebp, %ebx 1537; X86-BMI1BMI2-NEXT: xorl %ebp, %ebp 1538; X86-BMI1BMI2-NEXT: .LBB13_2: 1539; X86-BMI1BMI2-NEXT: movl $1, %edi 1540; X86-BMI1BMI2-NEXT: xorl %esi, %esi 1541; X86-BMI1BMI2-NEXT: movl %edx, %ecx 1542; X86-BMI1BMI2-NEXT: shldl %cl, %edi, %esi 1543; X86-BMI1BMI2-NEXT: shlxl %edx, %edi, %edi 1544; X86-BMI1BMI2-NEXT: testb $32, %dl 1545; X86-BMI1BMI2-NEXT: je .LBB13_4 1546; X86-BMI1BMI2-NEXT: # %bb.3: 1547; X86-BMI1BMI2-NEXT: movl %edi, %esi 1548; X86-BMI1BMI2-NEXT: xorl %edi, %edi 1549; X86-BMI1BMI2-NEXT: .LBB13_4: 1550; X86-BMI1BMI2-NEXT: addl $-1, %edi 1551; X86-BMI1BMI2-NEXT: adcl $-1, %esi 1552; X86-BMI1BMI2-NEXT: andl %ebx, %edi 1553; X86-BMI1BMI2-NEXT: andl %ebp, %esi 1554; X86-BMI1BMI2-NEXT: subl $8, %esp 1555; X86-BMI1BMI2-NEXT: pushl {{[0-9]+}}(%esp) 1556; X86-BMI1BMI2-NEXT: pushl %eax 1557; X86-BMI1BMI2-NEXT: calll use64 1558; X86-BMI1BMI2-NEXT: addl $16, %esp 1559; X86-BMI1BMI2-NEXT: movl %edi, %eax 1560; X86-BMI1BMI2-NEXT: movl %esi, %edx 1561; X86-BMI1BMI2-NEXT: addl $12, %esp 1562; X86-BMI1BMI2-NEXT: popl %esi 1563; X86-BMI1BMI2-NEXT: popl %edi 1564; X86-BMI1BMI2-NEXT: popl %ebx 1565; X86-BMI1BMI2-NEXT: popl %ebp 1566; X86-BMI1BMI2-NEXT: retl 1567; 1568; X64-NOBMI-LABEL: bextr64_a5_skipextrauses: 1569; X64-NOBMI: # %bb.0: 1570; X64-NOBMI-NEXT: pushq %rbx 1571; X64-NOBMI-NEXT: movl %esi, %ecx 1572; X64-NOBMI-NEXT: shrq %cl, %rdi 1573; X64-NOBMI-NEXT: movl $1, %ebx 1574; X64-NOBMI-NEXT: movl %edx, %ecx 1575; X64-NOBMI-NEXT: shlq %cl, %rbx 1576; X64-NOBMI-NEXT: decq %rbx 1577; X64-NOBMI-NEXT: andq %rdi, %rbx 1578; X64-NOBMI-NEXT: movq %rsi, %rdi 1579; X64-NOBMI-NEXT: callq use64 1580; X64-NOBMI-NEXT: movq %rbx, %rax 1581; X64-NOBMI-NEXT: popq %rbx 1582; X64-NOBMI-NEXT: retq 1583; 1584; X64-BMI1NOTBM-LABEL: bextr64_a5_skipextrauses: 1585; X64-BMI1NOTBM: # %bb.0: 1586; X64-BMI1NOTBM-NEXT: pushq %rbx 1587; X64-BMI1NOTBM-NEXT: shll $8, %edx 1588; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 1589; X64-BMI1NOTBM-NEXT: orl %edx, %eax 1590; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rbx 1591; X64-BMI1NOTBM-NEXT: movq %rsi, %rdi 1592; X64-BMI1NOTBM-NEXT: callq use64 1593; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 1594; X64-BMI1NOTBM-NEXT: popq %rbx 1595; X64-BMI1NOTBM-NEXT: retq 1596; 1597; X64-BMI1BMI2-LABEL: bextr64_a5_skipextrauses: 1598; X64-BMI1BMI2: # %bb.0: 1599; X64-BMI1BMI2-NEXT: pushq %rbx 1600; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 1601; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rbx 1602; X64-BMI1BMI2-NEXT: movq %rsi, %rdi 1603; X64-BMI1BMI2-NEXT: callq use64 1604; X64-BMI1BMI2-NEXT: movq %rbx, %rax 1605; X64-BMI1BMI2-NEXT: popq %rbx 1606; X64-BMI1BMI2-NEXT: retq 1607 %shifted = lshr i64 %val, %numskipbits 1608 %onebit = shl i64 1, %numlowbits 1609 %mask = add nsw i64 %onebit, -1 1610 %masked = and i64 %mask, %shifted 1611 call void @use64(i64 %numskipbits) 1612 ret i64 %masked 1613} 1614 1615; 64-bit, but with 32-bit output 1616 1617; Everything done in 64-bit, truncation happens last. 1618define i32 @bextr64_32_a0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 1619; X86-NOBMI-LABEL: bextr64_32_a0: 1620; X86-NOBMI: # %bb.0: 1621; X86-NOBMI-NEXT: pushl %edi 1622; X86-NOBMI-NEXT: pushl %esi 1623; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 1624; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 1625; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1626; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 1627; X86-NOBMI-NEXT: movl %edi, %esi 1628; X86-NOBMI-NEXT: shrl %cl, %esi 1629; X86-NOBMI-NEXT: shrdl %cl, %edi, %eax 1630; X86-NOBMI-NEXT: testb $32, %cl 1631; X86-NOBMI-NEXT: jne .LBB14_2 1632; X86-NOBMI-NEXT: # %bb.1: 1633; X86-NOBMI-NEXT: movl %eax, %esi 1634; X86-NOBMI-NEXT: .LBB14_2: 1635; X86-NOBMI-NEXT: movl $1, %edi 1636; X86-NOBMI-NEXT: movl %edx, %ecx 1637; X86-NOBMI-NEXT: shll %cl, %edi 1638; X86-NOBMI-NEXT: xorl %eax, %eax 1639; X86-NOBMI-NEXT: testb $32, %dl 1640; X86-NOBMI-NEXT: jne .LBB14_4 1641; X86-NOBMI-NEXT: # %bb.3: 1642; X86-NOBMI-NEXT: movl %edi, %eax 1643; X86-NOBMI-NEXT: .LBB14_4: 1644; X86-NOBMI-NEXT: decl %eax 1645; X86-NOBMI-NEXT: andl %esi, %eax 1646; X86-NOBMI-NEXT: popl %esi 1647; X86-NOBMI-NEXT: popl %edi 1648; X86-NOBMI-NEXT: retl 1649; 1650; X86-BMI1NOTBM-LABEL: bextr64_32_a0: 1651; X86-BMI1NOTBM: # %bb.0: 1652; X86-BMI1NOTBM-NEXT: pushl %edi 1653; X86-BMI1NOTBM-NEXT: pushl %esi 1654; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %dl 1655; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 1656; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 1657; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 1658; X86-BMI1NOTBM-NEXT: movl %edi, %esi 1659; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 1660; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %eax 1661; X86-BMI1NOTBM-NEXT: testb $32, %cl 1662; X86-BMI1NOTBM-NEXT: jne .LBB14_2 1663; X86-BMI1NOTBM-NEXT: # %bb.1: 1664; X86-BMI1NOTBM-NEXT: movl %eax, %esi 1665; X86-BMI1NOTBM-NEXT: .LBB14_2: 1666; X86-BMI1NOTBM-NEXT: movl $1, %edi 1667; X86-BMI1NOTBM-NEXT: movl %edx, %ecx 1668; X86-BMI1NOTBM-NEXT: shll %cl, %edi 1669; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 1670; X86-BMI1NOTBM-NEXT: testb $32, %dl 1671; X86-BMI1NOTBM-NEXT: jne .LBB14_4 1672; X86-BMI1NOTBM-NEXT: # %bb.3: 1673; X86-BMI1NOTBM-NEXT: movl %edi, %eax 1674; X86-BMI1NOTBM-NEXT: .LBB14_4: 1675; X86-BMI1NOTBM-NEXT: decl %eax 1676; X86-BMI1NOTBM-NEXT: andl %esi, %eax 1677; X86-BMI1NOTBM-NEXT: popl %esi 1678; X86-BMI1NOTBM-NEXT: popl %edi 1679; X86-BMI1NOTBM-NEXT: retl 1680; 1681; X86-BMI1BMI2-LABEL: bextr64_32_a0: 1682; X86-BMI1BMI2: # %bb.0: 1683; X86-BMI1BMI2-NEXT: pushl %ebx 1684; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 1685; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 1686; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 1687; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 1688; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %edx 1689; X86-BMI1BMI2-NEXT: testb $32, %cl 1690; X86-BMI1BMI2-NEXT: je .LBB14_2 1691; X86-BMI1BMI2-NEXT: # %bb.1: 1692; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edx 1693; X86-BMI1BMI2-NEXT: .LBB14_2: 1694; X86-BMI1BMI2-NEXT: xorl %eax, %eax 1695; X86-BMI1BMI2-NEXT: testb $32, %bl 1696; X86-BMI1BMI2-NEXT: jne .LBB14_4 1697; X86-BMI1BMI2-NEXT: # %bb.3: 1698; X86-BMI1BMI2-NEXT: movl $1, %eax 1699; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 1700; X86-BMI1BMI2-NEXT: .LBB14_4: 1701; X86-BMI1BMI2-NEXT: decl %eax 1702; X86-BMI1BMI2-NEXT: andl %edx, %eax 1703; X86-BMI1BMI2-NEXT: popl %ebx 1704; X86-BMI1BMI2-NEXT: retl 1705; 1706; X64-NOBMI-LABEL: bextr64_32_a0: 1707; X64-NOBMI: # %bb.0: 1708; X64-NOBMI-NEXT: movq %rsi, %rcx 1709; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 1710; X64-NOBMI-NEXT: shrq %cl, %rdi 1711; X64-NOBMI-NEXT: movl $1, %eax 1712; X64-NOBMI-NEXT: movl %edx, %ecx 1713; X64-NOBMI-NEXT: shlq %cl, %rax 1714; X64-NOBMI-NEXT: decl %eax 1715; X64-NOBMI-NEXT: andl %edi, %eax 1716; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 1717; X64-NOBMI-NEXT: retq 1718; 1719; X64-BMI1NOTBM-LABEL: bextr64_32_a0: 1720; X64-BMI1NOTBM: # %bb.0: 1721; X64-BMI1NOTBM-NEXT: shll $8, %edx 1722; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 1723; X64-BMI1NOTBM-NEXT: orl %edx, %eax 1724; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 1725; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 1726; X64-BMI1NOTBM-NEXT: retq 1727; 1728; X64-BMI1BMI2-LABEL: bextr64_32_a0: 1729; X64-BMI1BMI2: # %bb.0: 1730; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 1731; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 1732; X64-BMI1BMI2-NEXT: retq 1733 %shifted = lshr i64 %val, %numskipbits 1734 %onebit = shl i64 1, %numlowbits 1735 %mask = add nsw i64 %onebit, -1 1736 %masked = and i64 %mask, %shifted 1737 %res = trunc i64 %masked to i32 1738 ret i32 %res 1739} 1740 1741; Shifting happens in 64-bit, then truncation. Masking is 32-bit. 1742define i32 @bextr64_32_a1(i64 %val, i64 %numskipbits, i32 %numlowbits) nounwind { 1743; X86-NOBMI-LABEL: bextr64_32_a1: 1744; X86-NOBMI: # %bb.0: 1745; X86-NOBMI-NEXT: pushl %edi 1746; X86-NOBMI-NEXT: pushl %esi 1747; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 1748; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 1749; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1750; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 1751; X86-NOBMI-NEXT: movl %edi, %esi 1752; X86-NOBMI-NEXT: shrl %cl, %esi 1753; X86-NOBMI-NEXT: shrdl %cl, %edi, %eax 1754; X86-NOBMI-NEXT: testb $32, %cl 1755; X86-NOBMI-NEXT: jne .LBB15_2 1756; X86-NOBMI-NEXT: # %bb.1: 1757; X86-NOBMI-NEXT: movl %eax, %esi 1758; X86-NOBMI-NEXT: .LBB15_2: 1759; X86-NOBMI-NEXT: movl $1, %eax 1760; X86-NOBMI-NEXT: movl %edx, %ecx 1761; X86-NOBMI-NEXT: shll %cl, %eax 1762; X86-NOBMI-NEXT: decl %eax 1763; X86-NOBMI-NEXT: andl %esi, %eax 1764; X86-NOBMI-NEXT: popl %esi 1765; X86-NOBMI-NEXT: popl %edi 1766; X86-NOBMI-NEXT: retl 1767; 1768; X86-BMI1NOTBM-LABEL: bextr64_32_a1: 1769; X86-BMI1NOTBM: # %bb.0: 1770; X86-BMI1NOTBM-NEXT: pushl %edi 1771; X86-BMI1NOTBM-NEXT: pushl %esi 1772; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 1773; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 1774; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 1775; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 1776; X86-BMI1NOTBM-NEXT: movl %edi, %edx 1777; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 1778; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 1779; X86-BMI1NOTBM-NEXT: testb $32, %cl 1780; X86-BMI1NOTBM-NEXT: jne .LBB15_2 1781; X86-BMI1NOTBM-NEXT: # %bb.1: 1782; X86-BMI1NOTBM-NEXT: movl %esi, %edx 1783; X86-BMI1NOTBM-NEXT: .LBB15_2: 1784; X86-BMI1NOTBM-NEXT: shll $8, %eax 1785; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 1786; X86-BMI1NOTBM-NEXT: popl %esi 1787; X86-BMI1NOTBM-NEXT: popl %edi 1788; X86-BMI1NOTBM-NEXT: retl 1789; 1790; X86-BMI1BMI2-LABEL: bextr64_32_a1: 1791; X86-BMI1BMI2: # %bb.0: 1792; X86-BMI1BMI2-NEXT: pushl %esi 1793; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 1794; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 1795; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 1796; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 1797; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 1798; X86-BMI1BMI2-NEXT: testb $32, %cl 1799; X86-BMI1BMI2-NEXT: je .LBB15_2 1800; X86-BMI1BMI2-NEXT: # %bb.1: 1801; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 1802; X86-BMI1BMI2-NEXT: .LBB15_2: 1803; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 1804; X86-BMI1BMI2-NEXT: popl %esi 1805; X86-BMI1BMI2-NEXT: retl 1806; 1807; X64-NOBMI-LABEL: bextr64_32_a1: 1808; X64-NOBMI: # %bb.0: 1809; X64-NOBMI-NEXT: movq %rsi, %rcx 1810; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 1811; X64-NOBMI-NEXT: shrq %cl, %rdi 1812; X64-NOBMI-NEXT: movl $1, %eax 1813; X64-NOBMI-NEXT: movl %edx, %ecx 1814; X64-NOBMI-NEXT: shll %cl, %eax 1815; X64-NOBMI-NEXT: decl %eax 1816; X64-NOBMI-NEXT: andl %edi, %eax 1817; X64-NOBMI-NEXT: retq 1818; 1819; X64-BMI1NOTBM-LABEL: bextr64_32_a1: 1820; X64-BMI1NOTBM: # %bb.0: 1821; X64-BMI1NOTBM-NEXT: shll $8, %edx 1822; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 1823; X64-BMI1NOTBM-NEXT: orl %edx, %eax 1824; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 1825; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 1826; X64-BMI1NOTBM-NEXT: retq 1827; 1828; X64-BMI1BMI2-LABEL: bextr64_32_a1: 1829; X64-BMI1BMI2: # %bb.0: 1830; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 1831; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 1832; X64-BMI1BMI2-NEXT: retq 1833 %shifted = lshr i64 %val, %numskipbits 1834 %truncshifted = trunc i64 %shifted to i32 1835 %onebit = shl i32 1, %numlowbits 1836 %mask = add nsw i32 %onebit, -1 1837 %masked = and i32 %mask, %truncshifted 1838 ret i32 %masked 1839} 1840 1841; Shifting happens in 64-bit, then truncation (with extra use). 1842; Masking is 32-bit. 1843define i32 @bextr64_32_a1_trunc_extrause(i64 %val, i64 %numskipbits, i32 %numlowbits) nounwind { 1844; X86-NOBMI-LABEL: bextr64_32_a1_trunc_extrause: 1845; X86-NOBMI: # %bb.0: 1846; X86-NOBMI-NEXT: pushl %ebx 1847; X86-NOBMI-NEXT: pushl %esi 1848; X86-NOBMI-NEXT: pushl %eax 1849; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %bl 1850; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 1851; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1852; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 1853; X86-NOBMI-NEXT: movl %edx, %esi 1854; X86-NOBMI-NEXT: shrl %cl, %esi 1855; X86-NOBMI-NEXT: shrdl %cl, %edx, %eax 1856; X86-NOBMI-NEXT: testb $32, %cl 1857; X86-NOBMI-NEXT: jne .LBB16_2 1858; X86-NOBMI-NEXT: # %bb.1: 1859; X86-NOBMI-NEXT: movl %eax, %esi 1860; X86-NOBMI-NEXT: .LBB16_2: 1861; X86-NOBMI-NEXT: movl %esi, (%esp) 1862; X86-NOBMI-NEXT: calll use32 1863; X86-NOBMI-NEXT: movl $1, %eax 1864; X86-NOBMI-NEXT: movl %ebx, %ecx 1865; X86-NOBMI-NEXT: shll %cl, %eax 1866; X86-NOBMI-NEXT: decl %eax 1867; X86-NOBMI-NEXT: andl %esi, %eax 1868; X86-NOBMI-NEXT: addl $4, %esp 1869; X86-NOBMI-NEXT: popl %esi 1870; X86-NOBMI-NEXT: popl %ebx 1871; X86-NOBMI-NEXT: retl 1872; 1873; X86-BMI1NOTBM-LABEL: bextr64_32_a1_trunc_extrause: 1874; X86-BMI1NOTBM: # %bb.0: 1875; X86-BMI1NOTBM-NEXT: pushl %ebx 1876; X86-BMI1NOTBM-NEXT: pushl %esi 1877; X86-BMI1NOTBM-NEXT: pushl %eax 1878; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %bl 1879; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 1880; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 1881; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 1882; X86-BMI1NOTBM-NEXT: movl %edx, %esi 1883; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 1884; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %eax 1885; X86-BMI1NOTBM-NEXT: testb $32, %cl 1886; X86-BMI1NOTBM-NEXT: jne .LBB16_2 1887; X86-BMI1NOTBM-NEXT: # %bb.1: 1888; X86-BMI1NOTBM-NEXT: movl %eax, %esi 1889; X86-BMI1NOTBM-NEXT: .LBB16_2: 1890; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 1891; X86-BMI1NOTBM-NEXT: calll use32 1892; X86-BMI1NOTBM-NEXT: shll $8, %ebx 1893; X86-BMI1NOTBM-NEXT: bextrl %ebx, %esi, %eax 1894; X86-BMI1NOTBM-NEXT: addl $4, %esp 1895; X86-BMI1NOTBM-NEXT: popl %esi 1896; X86-BMI1NOTBM-NEXT: popl %ebx 1897; X86-BMI1NOTBM-NEXT: retl 1898; 1899; X86-BMI1BMI2-LABEL: bextr64_32_a1_trunc_extrause: 1900; X86-BMI1BMI2: # %bb.0: 1901; X86-BMI1BMI2-NEXT: pushl %ebx 1902; X86-BMI1BMI2-NEXT: pushl %esi 1903; X86-BMI1BMI2-NEXT: pushl %eax 1904; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 1905; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 1906; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 1907; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 1908; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 1909; X86-BMI1BMI2-NEXT: testb $32, %cl 1910; X86-BMI1BMI2-NEXT: je .LBB16_2 1911; X86-BMI1BMI2-NEXT: # %bb.1: 1912; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %esi 1913; X86-BMI1BMI2-NEXT: .LBB16_2: 1914; X86-BMI1BMI2-NEXT: movl %esi, (%esp) 1915; X86-BMI1BMI2-NEXT: calll use32 1916; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax 1917; X86-BMI1BMI2-NEXT: addl $4, %esp 1918; X86-BMI1BMI2-NEXT: popl %esi 1919; X86-BMI1BMI2-NEXT: popl %ebx 1920; X86-BMI1BMI2-NEXT: retl 1921; 1922; X64-NOBMI-LABEL: bextr64_32_a1_trunc_extrause: 1923; X64-NOBMI: # %bb.0: 1924; X64-NOBMI-NEXT: pushq %rbp 1925; X64-NOBMI-NEXT: pushq %rbx 1926; X64-NOBMI-NEXT: pushq %rax 1927; X64-NOBMI-NEXT: movl %edx, %ebp 1928; X64-NOBMI-NEXT: movq %rsi, %rcx 1929; X64-NOBMI-NEXT: movq %rdi, %rbx 1930; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 1931; X64-NOBMI-NEXT: shrq %cl, %rbx 1932; X64-NOBMI-NEXT: movl %ebx, %edi 1933; X64-NOBMI-NEXT: callq use32 1934; X64-NOBMI-NEXT: movl $1, %eax 1935; X64-NOBMI-NEXT: movl %ebp, %ecx 1936; X64-NOBMI-NEXT: shll %cl, %eax 1937; X64-NOBMI-NEXT: decl %eax 1938; X64-NOBMI-NEXT: andl %ebx, %eax 1939; X64-NOBMI-NEXT: addq $8, %rsp 1940; X64-NOBMI-NEXT: popq %rbx 1941; X64-NOBMI-NEXT: popq %rbp 1942; X64-NOBMI-NEXT: retq 1943; 1944; X64-BMI1NOTBM-LABEL: bextr64_32_a1_trunc_extrause: 1945; X64-BMI1NOTBM: # %bb.0: 1946; X64-BMI1NOTBM-NEXT: pushq %rbp 1947; X64-BMI1NOTBM-NEXT: pushq %rbx 1948; X64-BMI1NOTBM-NEXT: pushq %rax 1949; X64-BMI1NOTBM-NEXT: movl %edx, %ebp 1950; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx 1951; X64-BMI1NOTBM-NEXT: movq %rdi, %rbx 1952; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx 1953; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 1954; X64-BMI1NOTBM-NEXT: movl %ebx, %edi 1955; X64-BMI1NOTBM-NEXT: callq use32 1956; X64-BMI1NOTBM-NEXT: shll $8, %ebp 1957; X64-BMI1NOTBM-NEXT: bextrl %ebp, %ebx, %eax 1958; X64-BMI1NOTBM-NEXT: addq $8, %rsp 1959; X64-BMI1NOTBM-NEXT: popq %rbx 1960; X64-BMI1NOTBM-NEXT: popq %rbp 1961; X64-BMI1NOTBM-NEXT: retq 1962; 1963; X64-BMI1BMI2-LABEL: bextr64_32_a1_trunc_extrause: 1964; X64-BMI1BMI2: # %bb.0: 1965; X64-BMI1BMI2-NEXT: pushq %rbp 1966; X64-BMI1BMI2-NEXT: pushq %rbx 1967; X64-BMI1BMI2-NEXT: pushq %rax 1968; X64-BMI1BMI2-NEXT: movl %edx, %ebp 1969; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rbx 1970; X64-BMI1BMI2-NEXT: movl %ebx, %edi 1971; X64-BMI1BMI2-NEXT: callq use32 1972; X64-BMI1BMI2-NEXT: bzhil %ebp, %ebx, %eax 1973; X64-BMI1BMI2-NEXT: addq $8, %rsp 1974; X64-BMI1BMI2-NEXT: popq %rbx 1975; X64-BMI1BMI2-NEXT: popq %rbp 1976; X64-BMI1BMI2-NEXT: retq 1977 %shifted = lshr i64 %val, %numskipbits 1978 %truncshifted = trunc i64 %shifted to i32 1979 call void @use32(i32 %truncshifted) 1980 %onebit = shl i32 1, %numlowbits 1981 %mask = add nsw i32 %onebit, -1 1982 %masked = and i32 %mask, %truncshifted 1983 ret i32 %masked 1984} 1985 1986; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit. 1987; Masking is 64-bit. Then truncation. 1988define i32 @bextr64_32_a2(i64 %val, i64 %numskipbits, i32 %numlowbits) nounwind { 1989; X86-NOBMI-LABEL: bextr64_32_a2: 1990; X86-NOBMI: # %bb.0: 1991; X86-NOBMI-NEXT: pushl %edi 1992; X86-NOBMI-NEXT: pushl %esi 1993; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 1994; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 1995; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 1996; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 1997; X86-NOBMI-NEXT: movl %edi, %esi 1998; X86-NOBMI-NEXT: shrl %cl, %esi 1999; X86-NOBMI-NEXT: shrdl %cl, %edi, %eax 2000; X86-NOBMI-NEXT: testb $32, %cl 2001; X86-NOBMI-NEXT: jne .LBB17_2 2002; X86-NOBMI-NEXT: # %bb.1: 2003; X86-NOBMI-NEXT: movl %eax, %esi 2004; X86-NOBMI-NEXT: .LBB17_2: 2005; X86-NOBMI-NEXT: movl $1, %eax 2006; X86-NOBMI-NEXT: movl %edx, %ecx 2007; X86-NOBMI-NEXT: shll %cl, %eax 2008; X86-NOBMI-NEXT: decl %eax 2009; X86-NOBMI-NEXT: andl %esi, %eax 2010; X86-NOBMI-NEXT: popl %esi 2011; X86-NOBMI-NEXT: popl %edi 2012; X86-NOBMI-NEXT: retl 2013; 2014; X86-BMI1NOTBM-LABEL: bextr64_32_a2: 2015; X86-BMI1NOTBM: # %bb.0: 2016; X86-BMI1NOTBM-NEXT: pushl %edi 2017; X86-BMI1NOTBM-NEXT: pushl %esi 2018; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2019; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2020; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 2021; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 2022; X86-BMI1NOTBM-NEXT: movl %edi, %edx 2023; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 2024; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 2025; X86-BMI1NOTBM-NEXT: testb $32, %cl 2026; X86-BMI1NOTBM-NEXT: jne .LBB17_2 2027; X86-BMI1NOTBM-NEXT: # %bb.1: 2028; X86-BMI1NOTBM-NEXT: movl %esi, %edx 2029; X86-BMI1NOTBM-NEXT: .LBB17_2: 2030; X86-BMI1NOTBM-NEXT: shll $8, %eax 2031; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 2032; X86-BMI1NOTBM-NEXT: popl %esi 2033; X86-BMI1NOTBM-NEXT: popl %edi 2034; X86-BMI1NOTBM-NEXT: retl 2035; 2036; X86-BMI1BMI2-LABEL: bextr64_32_a2: 2037; X86-BMI1BMI2: # %bb.0: 2038; X86-BMI1BMI2-NEXT: pushl %esi 2039; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2040; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2041; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 2042; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 2043; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 2044; X86-BMI1BMI2-NEXT: testb $32, %cl 2045; X86-BMI1BMI2-NEXT: je .LBB17_2 2046; X86-BMI1BMI2-NEXT: # %bb.1: 2047; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 2048; X86-BMI1BMI2-NEXT: .LBB17_2: 2049; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 2050; X86-BMI1BMI2-NEXT: popl %esi 2051; X86-BMI1BMI2-NEXT: retl 2052; 2053; X64-NOBMI-LABEL: bextr64_32_a2: 2054; X64-NOBMI: # %bb.0: 2055; X64-NOBMI-NEXT: movq %rsi, %rcx 2056; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 2057; X64-NOBMI-NEXT: shrq %cl, %rdi 2058; X64-NOBMI-NEXT: movl $1, %eax 2059; X64-NOBMI-NEXT: movl %edx, %ecx 2060; X64-NOBMI-NEXT: shll %cl, %eax 2061; X64-NOBMI-NEXT: decl %eax 2062; X64-NOBMI-NEXT: andl %edi, %eax 2063; X64-NOBMI-NEXT: retq 2064; 2065; X64-BMI1NOTBM-LABEL: bextr64_32_a2: 2066; X64-BMI1NOTBM: # %bb.0: 2067; X64-BMI1NOTBM-NEXT: shll $8, %edx 2068; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2069; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2070; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 2071; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 2072; X64-BMI1NOTBM-NEXT: retq 2073; 2074; X64-BMI1BMI2-LABEL: bextr64_32_a2: 2075; X64-BMI1BMI2: # %bb.0: 2076; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 2077; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2078; X64-BMI1BMI2-NEXT: retq 2079 %shifted = lshr i64 %val, %numskipbits 2080 %onebit = shl i32 1, %numlowbits 2081 %mask = add nsw i32 %onebit, -1 2082 %zextmask = zext i32 %mask to i64 2083 %masked = and i64 %zextmask, %shifted 2084 %truncmasked = trunc i64 %masked to i32 2085 ret i32 %truncmasked 2086} 2087 2088; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit. 2089; Masking is 64-bit. Then truncation. 2090define i32 @bextr64_32_a3(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 2091; X86-NOBMI-LABEL: bextr64_32_a3: 2092; X86-NOBMI: # %bb.0: 2093; X86-NOBMI-NEXT: pushl %edi 2094; X86-NOBMI-NEXT: pushl %esi 2095; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2096; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2097; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2098; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 2099; X86-NOBMI-NEXT: movl %edi, %esi 2100; X86-NOBMI-NEXT: shrl %cl, %esi 2101; X86-NOBMI-NEXT: shrdl %cl, %edi, %eax 2102; X86-NOBMI-NEXT: testb $32, %cl 2103; X86-NOBMI-NEXT: jne .LBB18_2 2104; X86-NOBMI-NEXT: # %bb.1: 2105; X86-NOBMI-NEXT: movl %eax, %esi 2106; X86-NOBMI-NEXT: .LBB18_2: 2107; X86-NOBMI-NEXT: movl $1, %edi 2108; X86-NOBMI-NEXT: movl %edx, %ecx 2109; X86-NOBMI-NEXT: shll %cl, %edi 2110; X86-NOBMI-NEXT: xorl %eax, %eax 2111; X86-NOBMI-NEXT: testb $32, %dl 2112; X86-NOBMI-NEXT: jne .LBB18_4 2113; X86-NOBMI-NEXT: # %bb.3: 2114; X86-NOBMI-NEXT: movl %edi, %eax 2115; X86-NOBMI-NEXT: .LBB18_4: 2116; X86-NOBMI-NEXT: decl %eax 2117; X86-NOBMI-NEXT: andl %esi, %eax 2118; X86-NOBMI-NEXT: popl %esi 2119; X86-NOBMI-NEXT: popl %edi 2120; X86-NOBMI-NEXT: retl 2121; 2122; X86-BMI1NOTBM-LABEL: bextr64_32_a3: 2123; X86-BMI1NOTBM: # %bb.0: 2124; X86-BMI1NOTBM-NEXT: pushl %edi 2125; X86-BMI1NOTBM-NEXT: pushl %esi 2126; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %dl 2127; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2128; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 2129; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 2130; X86-BMI1NOTBM-NEXT: movl %edi, %esi 2131; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 2132; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %eax 2133; X86-BMI1NOTBM-NEXT: testb $32, %cl 2134; X86-BMI1NOTBM-NEXT: jne .LBB18_2 2135; X86-BMI1NOTBM-NEXT: # %bb.1: 2136; X86-BMI1NOTBM-NEXT: movl %eax, %esi 2137; X86-BMI1NOTBM-NEXT: .LBB18_2: 2138; X86-BMI1NOTBM-NEXT: movl $1, %edi 2139; X86-BMI1NOTBM-NEXT: movl %edx, %ecx 2140; X86-BMI1NOTBM-NEXT: shll %cl, %edi 2141; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 2142; X86-BMI1NOTBM-NEXT: testb $32, %dl 2143; X86-BMI1NOTBM-NEXT: jne .LBB18_4 2144; X86-BMI1NOTBM-NEXT: # %bb.3: 2145; X86-BMI1NOTBM-NEXT: movl %edi, %eax 2146; X86-BMI1NOTBM-NEXT: .LBB18_4: 2147; X86-BMI1NOTBM-NEXT: decl %eax 2148; X86-BMI1NOTBM-NEXT: andl %esi, %eax 2149; X86-BMI1NOTBM-NEXT: popl %esi 2150; X86-BMI1NOTBM-NEXT: popl %edi 2151; X86-BMI1NOTBM-NEXT: retl 2152; 2153; X86-BMI1BMI2-LABEL: bextr64_32_a3: 2154; X86-BMI1BMI2: # %bb.0: 2155; X86-BMI1BMI2-NEXT: pushl %ebx 2156; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 2157; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2158; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 2159; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 2160; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %edx 2161; X86-BMI1BMI2-NEXT: testb $32, %cl 2162; X86-BMI1BMI2-NEXT: je .LBB18_2 2163; X86-BMI1BMI2-NEXT: # %bb.1: 2164; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edx 2165; X86-BMI1BMI2-NEXT: .LBB18_2: 2166; X86-BMI1BMI2-NEXT: xorl %eax, %eax 2167; X86-BMI1BMI2-NEXT: testb $32, %bl 2168; X86-BMI1BMI2-NEXT: jne .LBB18_4 2169; X86-BMI1BMI2-NEXT: # %bb.3: 2170; X86-BMI1BMI2-NEXT: movl $1, %eax 2171; X86-BMI1BMI2-NEXT: shlxl %ebx, %eax, %eax 2172; X86-BMI1BMI2-NEXT: .LBB18_4: 2173; X86-BMI1BMI2-NEXT: decl %eax 2174; X86-BMI1BMI2-NEXT: andl %edx, %eax 2175; X86-BMI1BMI2-NEXT: popl %ebx 2176; X86-BMI1BMI2-NEXT: retl 2177; 2178; X64-NOBMI-LABEL: bextr64_32_a3: 2179; X64-NOBMI: # %bb.0: 2180; X64-NOBMI-NEXT: movq %rsi, %rcx 2181; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 2182; X64-NOBMI-NEXT: shrq %cl, %rdi 2183; X64-NOBMI-NEXT: movl $1, %eax 2184; X64-NOBMI-NEXT: movl %edx, %ecx 2185; X64-NOBMI-NEXT: shlq %cl, %rax 2186; X64-NOBMI-NEXT: decl %eax 2187; X64-NOBMI-NEXT: andl %edi, %eax 2188; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 2189; X64-NOBMI-NEXT: retq 2190; 2191; X64-BMI1NOTBM-LABEL: bextr64_32_a3: 2192; X64-BMI1NOTBM: # %bb.0: 2193; X64-BMI1NOTBM-NEXT: shll $8, %edx 2194; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2195; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2196; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 2197; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 2198; X64-BMI1NOTBM-NEXT: retq 2199; 2200; X64-BMI1BMI2-LABEL: bextr64_32_a3: 2201; X64-BMI1BMI2: # %bb.0: 2202; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 2203; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2204; X64-BMI1BMI2-NEXT: retq 2205 %shifted = lshr i64 %val, %numskipbits 2206 %onebit = shl i64 1, %numlowbits 2207 %mask = add nsw i64 %onebit, 4294967295 2208 %masked = and i64 %mask, %shifted 2209 %truncmasked = trunc i64 %masked to i32 2210 ret i32 %truncmasked 2211} 2212 2213; ---------------------------------------------------------------------------- ; 2214; Pattern b. 32-bit 2215; ---------------------------------------------------------------------------- ; 2216 2217define i32 @bextr32_b0(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 2218; X86-NOBMI-LABEL: bextr32_b0: 2219; X86-NOBMI: # %bb.0: 2220; X86-NOBMI-NEXT: pushl %esi 2221; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2222; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2223; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 2224; X86-NOBMI-NEXT: shrl %cl, %esi 2225; X86-NOBMI-NEXT: movl $-1, %eax 2226; X86-NOBMI-NEXT: movl %edx, %ecx 2227; X86-NOBMI-NEXT: shll %cl, %eax 2228; X86-NOBMI-NEXT: notl %eax 2229; X86-NOBMI-NEXT: andl %esi, %eax 2230; X86-NOBMI-NEXT: popl %esi 2231; X86-NOBMI-NEXT: retl 2232; 2233; X86-BMI1NOTBM-LABEL: bextr32_b0: 2234; X86-BMI1NOTBM: # %bb.0: 2235; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2236; X86-BMI1NOTBM-NEXT: shll $8, %eax 2237; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 2238; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 2239; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 2240; X86-BMI1NOTBM-NEXT: retl 2241; 2242; X86-BMI1BMI2-LABEL: bextr32_b0: 2243; X86-BMI1BMI2: # %bb.0: 2244; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2245; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2246; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 2247; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 2248; X86-BMI1BMI2-NEXT: retl 2249; 2250; X64-NOBMI-LABEL: bextr32_b0: 2251; X64-NOBMI: # %bb.0: 2252; X64-NOBMI-NEXT: movl %esi, %ecx 2253; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 2254; X64-NOBMI-NEXT: shrl %cl, %edi 2255; X64-NOBMI-NEXT: movl $-1, %eax 2256; X64-NOBMI-NEXT: movl %edx, %ecx 2257; X64-NOBMI-NEXT: shll %cl, %eax 2258; X64-NOBMI-NEXT: notl %eax 2259; X64-NOBMI-NEXT: andl %edi, %eax 2260; X64-NOBMI-NEXT: retq 2261; 2262; X64-BMI1NOTBM-LABEL: bextr32_b0: 2263; X64-BMI1NOTBM: # %bb.0: 2264; X64-BMI1NOTBM-NEXT: shll $8, %edx 2265; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2266; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2267; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 2268; X64-BMI1NOTBM-NEXT: retq 2269; 2270; X64-BMI1BMI2-LABEL: bextr32_b0: 2271; X64-BMI1BMI2: # %bb.0: 2272; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 2273; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2274; X64-BMI1BMI2-NEXT: retq 2275 %shifted = lshr i32 %val, %numskipbits 2276 %notmask = shl i32 -1, %numlowbits 2277 %mask = xor i32 %notmask, -1 2278 %masked = and i32 %mask, %shifted 2279 ret i32 %masked 2280} 2281 2282define i32 @bextr32_b1_indexzext(i32 %val, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 2283; X86-NOBMI-LABEL: bextr32_b1_indexzext: 2284; X86-NOBMI: # %bb.0: 2285; X86-NOBMI-NEXT: pushl %esi 2286; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2287; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2288; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 2289; X86-NOBMI-NEXT: shrl %cl, %esi 2290; X86-NOBMI-NEXT: movl $-1, %eax 2291; X86-NOBMI-NEXT: movl %edx, %ecx 2292; X86-NOBMI-NEXT: shll %cl, %eax 2293; X86-NOBMI-NEXT: notl %eax 2294; X86-NOBMI-NEXT: andl %esi, %eax 2295; X86-NOBMI-NEXT: popl %esi 2296; X86-NOBMI-NEXT: retl 2297; 2298; X86-BMI1NOTBM-LABEL: bextr32_b1_indexzext: 2299; X86-BMI1NOTBM: # %bb.0: 2300; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2301; X86-BMI1NOTBM-NEXT: shll $8, %eax 2302; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 2303; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 2304; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 2305; X86-BMI1NOTBM-NEXT: retl 2306; 2307; X86-BMI1BMI2-LABEL: bextr32_b1_indexzext: 2308; X86-BMI1BMI2: # %bb.0: 2309; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2310; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2311; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 2312; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 2313; X86-BMI1BMI2-NEXT: retl 2314; 2315; X64-NOBMI-LABEL: bextr32_b1_indexzext: 2316; X64-NOBMI: # %bb.0: 2317; X64-NOBMI-NEXT: movl %esi, %ecx 2318; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 2319; X64-NOBMI-NEXT: shrl %cl, %edi 2320; X64-NOBMI-NEXT: movl $-1, %eax 2321; X64-NOBMI-NEXT: movl %edx, %ecx 2322; X64-NOBMI-NEXT: shll %cl, %eax 2323; X64-NOBMI-NEXT: notl %eax 2324; X64-NOBMI-NEXT: andl %edi, %eax 2325; X64-NOBMI-NEXT: retq 2326; 2327; X64-BMI1NOTBM-LABEL: bextr32_b1_indexzext: 2328; X64-BMI1NOTBM: # %bb.0: 2329; X64-BMI1NOTBM-NEXT: shll $8, %edx 2330; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2331; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2332; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 2333; X64-BMI1NOTBM-NEXT: retq 2334; 2335; X64-BMI1BMI2-LABEL: bextr32_b1_indexzext: 2336; X64-BMI1BMI2: # %bb.0: 2337; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 2338; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2339; X64-BMI1BMI2-NEXT: retq 2340 %skip = zext i8 %numskipbits to i32 2341 %shifted = lshr i32 %val, %skip 2342 %conv = zext i8 %numlowbits to i32 2343 %notmask = shl i32 -1, %conv 2344 %mask = xor i32 %notmask, -1 2345 %masked = and i32 %mask, %shifted 2346 ret i32 %masked 2347} 2348 2349define i32 @bextr32_b2_load(i32* %w, i32 %numskipbits, i32 %numlowbits) nounwind { 2350; X86-NOBMI-LABEL: bextr32_b2_load: 2351; X86-NOBMI: # %bb.0: 2352; X86-NOBMI-NEXT: pushl %esi 2353; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2354; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2355; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2356; X86-NOBMI-NEXT: movl (%eax), %esi 2357; X86-NOBMI-NEXT: shrl %cl, %esi 2358; X86-NOBMI-NEXT: movl $-1, %eax 2359; X86-NOBMI-NEXT: movl %edx, %ecx 2360; X86-NOBMI-NEXT: shll %cl, %eax 2361; X86-NOBMI-NEXT: notl %eax 2362; X86-NOBMI-NEXT: andl %esi, %eax 2363; X86-NOBMI-NEXT: popl %esi 2364; X86-NOBMI-NEXT: retl 2365; 2366; X86-BMI1NOTBM-LABEL: bextr32_b2_load: 2367; X86-BMI1NOTBM: # %bb.0: 2368; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 2369; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2370; X86-BMI1NOTBM-NEXT: shll $8, %ecx 2371; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %edx 2372; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 2373; X86-BMI1NOTBM-NEXT: bextrl %edx, (%eax), %eax 2374; X86-BMI1NOTBM-NEXT: retl 2375; 2376; X86-BMI1BMI2-LABEL: bextr32_b2_load: 2377; X86-BMI1BMI2: # %bb.0: 2378; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2379; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 2380; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 2381; X86-BMI1BMI2-NEXT: shrxl %edx, (%ecx), %ecx 2382; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 2383; X86-BMI1BMI2-NEXT: retl 2384; 2385; X64-NOBMI-LABEL: bextr32_b2_load: 2386; X64-NOBMI: # %bb.0: 2387; X64-NOBMI-NEXT: movl %esi, %ecx 2388; X64-NOBMI-NEXT: movl (%rdi), %esi 2389; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 2390; X64-NOBMI-NEXT: shrl %cl, %esi 2391; X64-NOBMI-NEXT: movl $-1, %eax 2392; X64-NOBMI-NEXT: movl %edx, %ecx 2393; X64-NOBMI-NEXT: shll %cl, %eax 2394; X64-NOBMI-NEXT: notl %eax 2395; X64-NOBMI-NEXT: andl %esi, %eax 2396; X64-NOBMI-NEXT: retq 2397; 2398; X64-BMI1NOTBM-LABEL: bextr32_b2_load: 2399; X64-BMI1NOTBM: # %bb.0: 2400; X64-BMI1NOTBM-NEXT: shll $8, %edx 2401; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2402; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2403; X64-BMI1NOTBM-NEXT: bextrl %eax, (%rdi), %eax 2404; X64-BMI1NOTBM-NEXT: retq 2405; 2406; X64-BMI1BMI2-LABEL: bextr32_b2_load: 2407; X64-BMI1BMI2: # %bb.0: 2408; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %eax 2409; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2410; X64-BMI1BMI2-NEXT: retq 2411 %val = load i32, i32* %w 2412 %shifted = lshr i32 %val, %numskipbits 2413 %notmask = shl i32 -1, %numlowbits 2414 %mask = xor i32 %notmask, -1 2415 %masked = and i32 %mask, %shifted 2416 ret i32 %masked 2417} 2418 2419define i32 @bextr32_b3_load_indexzext(i32* %w, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 2420; X86-NOBMI-LABEL: bextr32_b3_load_indexzext: 2421; X86-NOBMI: # %bb.0: 2422; X86-NOBMI-NEXT: pushl %esi 2423; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2424; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2425; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2426; X86-NOBMI-NEXT: movl (%eax), %esi 2427; X86-NOBMI-NEXT: shrl %cl, %esi 2428; X86-NOBMI-NEXT: movl $-1, %eax 2429; X86-NOBMI-NEXT: movl %edx, %ecx 2430; X86-NOBMI-NEXT: shll %cl, %eax 2431; X86-NOBMI-NEXT: notl %eax 2432; X86-NOBMI-NEXT: andl %esi, %eax 2433; X86-NOBMI-NEXT: popl %esi 2434; X86-NOBMI-NEXT: retl 2435; 2436; X86-BMI1NOTBM-LABEL: bextr32_b3_load_indexzext: 2437; X86-BMI1NOTBM: # %bb.0: 2438; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 2439; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2440; X86-BMI1NOTBM-NEXT: shll $8, %ecx 2441; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %edx 2442; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 2443; X86-BMI1NOTBM-NEXT: bextrl %edx, (%eax), %eax 2444; X86-BMI1NOTBM-NEXT: retl 2445; 2446; X86-BMI1BMI2-LABEL: bextr32_b3_load_indexzext: 2447; X86-BMI1BMI2: # %bb.0: 2448; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2449; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 2450; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 2451; X86-BMI1BMI2-NEXT: shrxl %edx, (%ecx), %ecx 2452; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 2453; X86-BMI1BMI2-NEXT: retl 2454; 2455; X64-NOBMI-LABEL: bextr32_b3_load_indexzext: 2456; X64-NOBMI: # %bb.0: 2457; X64-NOBMI-NEXT: movl %esi, %ecx 2458; X64-NOBMI-NEXT: movl (%rdi), %esi 2459; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 2460; X64-NOBMI-NEXT: shrl %cl, %esi 2461; X64-NOBMI-NEXT: movl $-1, %eax 2462; X64-NOBMI-NEXT: movl %edx, %ecx 2463; X64-NOBMI-NEXT: shll %cl, %eax 2464; X64-NOBMI-NEXT: notl %eax 2465; X64-NOBMI-NEXT: andl %esi, %eax 2466; X64-NOBMI-NEXT: retq 2467; 2468; X64-BMI1NOTBM-LABEL: bextr32_b3_load_indexzext: 2469; X64-BMI1NOTBM: # %bb.0: 2470; X64-BMI1NOTBM-NEXT: shll $8, %edx 2471; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2472; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2473; X64-BMI1NOTBM-NEXT: bextrl %eax, (%rdi), %eax 2474; X64-BMI1NOTBM-NEXT: retq 2475; 2476; X64-BMI1BMI2-LABEL: bextr32_b3_load_indexzext: 2477; X64-BMI1BMI2: # %bb.0: 2478; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %eax 2479; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2480; X64-BMI1BMI2-NEXT: retq 2481 %val = load i32, i32* %w 2482 %skip = zext i8 %numskipbits to i32 2483 %shifted = lshr i32 %val, %skip 2484 %conv = zext i8 %numlowbits to i32 2485 %notmask = shl i32 -1, %conv 2486 %mask = xor i32 %notmask, -1 2487 %masked = and i32 %mask, %shifted 2488 ret i32 %masked 2489} 2490 2491define i32 @bextr32_b4_commutative(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 2492; X86-NOBMI-LABEL: bextr32_b4_commutative: 2493; X86-NOBMI: # %bb.0: 2494; X86-NOBMI-NEXT: pushl %esi 2495; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2496; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2497; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 2498; X86-NOBMI-NEXT: shrl %cl, %esi 2499; X86-NOBMI-NEXT: movl $-1, %eax 2500; X86-NOBMI-NEXT: movl %edx, %ecx 2501; X86-NOBMI-NEXT: shll %cl, %eax 2502; X86-NOBMI-NEXT: notl %eax 2503; X86-NOBMI-NEXT: andl %esi, %eax 2504; X86-NOBMI-NEXT: popl %esi 2505; X86-NOBMI-NEXT: retl 2506; 2507; X86-BMI1NOTBM-LABEL: bextr32_b4_commutative: 2508; X86-BMI1NOTBM: # %bb.0: 2509; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2510; X86-BMI1NOTBM-NEXT: shll $8, %eax 2511; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 2512; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 2513; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 2514; X86-BMI1NOTBM-NEXT: retl 2515; 2516; X86-BMI1BMI2-LABEL: bextr32_b4_commutative: 2517; X86-BMI1BMI2: # %bb.0: 2518; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2519; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2520; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 2521; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 2522; X86-BMI1BMI2-NEXT: retl 2523; 2524; X64-NOBMI-LABEL: bextr32_b4_commutative: 2525; X64-NOBMI: # %bb.0: 2526; X64-NOBMI-NEXT: movl %esi, %ecx 2527; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 2528; X64-NOBMI-NEXT: shrl %cl, %edi 2529; X64-NOBMI-NEXT: movl $-1, %eax 2530; X64-NOBMI-NEXT: movl %edx, %ecx 2531; X64-NOBMI-NEXT: shll %cl, %eax 2532; X64-NOBMI-NEXT: notl %eax 2533; X64-NOBMI-NEXT: andl %edi, %eax 2534; X64-NOBMI-NEXT: retq 2535; 2536; X64-BMI1NOTBM-LABEL: bextr32_b4_commutative: 2537; X64-BMI1NOTBM: # %bb.0: 2538; X64-BMI1NOTBM-NEXT: shll $8, %edx 2539; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2540; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2541; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 2542; X64-BMI1NOTBM-NEXT: retq 2543; 2544; X64-BMI1BMI2-LABEL: bextr32_b4_commutative: 2545; X64-BMI1BMI2: # %bb.0: 2546; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 2547; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 2548; X64-BMI1BMI2-NEXT: retq 2549 %shifted = lshr i32 %val, %numskipbits 2550 %notmask = shl i32 -1, %numlowbits 2551 %mask = xor i32 %notmask, -1 2552 %masked = and i32 %shifted, %mask ; swapped order 2553 ret i32 %masked 2554} 2555 2556define i32 @bextr32_b5_skipextrauses(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 2557; X86-NOBMI-LABEL: bextr32_b5_skipextrauses: 2558; X86-NOBMI: # %bb.0: 2559; X86-NOBMI-NEXT: pushl %edi 2560; X86-NOBMI-NEXT: pushl %esi 2561; X86-NOBMI-NEXT: pushl %eax 2562; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 2563; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 2564; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2565; X86-NOBMI-NEXT: movl %eax, %ecx 2566; X86-NOBMI-NEXT: shrl %cl, %edi 2567; X86-NOBMI-NEXT: movl $-1, %esi 2568; X86-NOBMI-NEXT: movl %edx, %ecx 2569; X86-NOBMI-NEXT: shll %cl, %esi 2570; X86-NOBMI-NEXT: notl %esi 2571; X86-NOBMI-NEXT: andl %edi, %esi 2572; X86-NOBMI-NEXT: movl %eax, (%esp) 2573; X86-NOBMI-NEXT: calll use32 2574; X86-NOBMI-NEXT: movl %esi, %eax 2575; X86-NOBMI-NEXT: addl $4, %esp 2576; X86-NOBMI-NEXT: popl %esi 2577; X86-NOBMI-NEXT: popl %edi 2578; X86-NOBMI-NEXT: retl 2579; 2580; X86-BMI1NOTBM-LABEL: bextr32_b5_skipextrauses: 2581; X86-BMI1NOTBM: # %bb.0: 2582; X86-BMI1NOTBM-NEXT: pushl %esi 2583; X86-BMI1NOTBM-NEXT: subl $8, %esp 2584; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2585; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 2586; X86-BMI1NOTBM-NEXT: shll $8, %ecx 2587; X86-BMI1NOTBM-NEXT: movzbl %al, %edx 2588; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 2589; X86-BMI1NOTBM-NEXT: bextrl %edx, {{[0-9]+}}(%esp), %esi 2590; X86-BMI1NOTBM-NEXT: movl %eax, (%esp) 2591; X86-BMI1NOTBM-NEXT: calll use32 2592; X86-BMI1NOTBM-NEXT: movl %esi, %eax 2593; X86-BMI1NOTBM-NEXT: addl $8, %esp 2594; X86-BMI1NOTBM-NEXT: popl %esi 2595; X86-BMI1NOTBM-NEXT: retl 2596; 2597; X86-BMI1BMI2-LABEL: bextr32_b5_skipextrauses: 2598; X86-BMI1BMI2: # %bb.0: 2599; X86-BMI1BMI2-NEXT: pushl %esi 2600; X86-BMI1BMI2-NEXT: subl $8, %esp 2601; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 2602; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 2603; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %edx 2604; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %esi 2605; X86-BMI1BMI2-NEXT: movl %ecx, (%esp) 2606; X86-BMI1BMI2-NEXT: calll use32 2607; X86-BMI1BMI2-NEXT: movl %esi, %eax 2608; X86-BMI1BMI2-NEXT: addl $8, %esp 2609; X86-BMI1BMI2-NEXT: popl %esi 2610; X86-BMI1BMI2-NEXT: retl 2611; 2612; X64-NOBMI-LABEL: bextr32_b5_skipextrauses: 2613; X64-NOBMI: # %bb.0: 2614; X64-NOBMI-NEXT: pushq %rbx 2615; X64-NOBMI-NEXT: movl %esi, %ecx 2616; X64-NOBMI-NEXT: shrl %cl, %edi 2617; X64-NOBMI-NEXT: movl $-1, %ebx 2618; X64-NOBMI-NEXT: movl %edx, %ecx 2619; X64-NOBMI-NEXT: shll %cl, %ebx 2620; X64-NOBMI-NEXT: notl %ebx 2621; X64-NOBMI-NEXT: andl %edi, %ebx 2622; X64-NOBMI-NEXT: movl %esi, %edi 2623; X64-NOBMI-NEXT: callq use32 2624; X64-NOBMI-NEXT: movl %ebx, %eax 2625; X64-NOBMI-NEXT: popq %rbx 2626; X64-NOBMI-NEXT: retq 2627; 2628; X64-BMI1NOTBM-LABEL: bextr32_b5_skipextrauses: 2629; X64-BMI1NOTBM: # %bb.0: 2630; X64-BMI1NOTBM-NEXT: pushq %rbx 2631; X64-BMI1NOTBM-NEXT: shll $8, %edx 2632; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2633; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2634; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %ebx 2635; X64-BMI1NOTBM-NEXT: movl %esi, %edi 2636; X64-BMI1NOTBM-NEXT: callq use32 2637; X64-BMI1NOTBM-NEXT: movl %ebx, %eax 2638; X64-BMI1NOTBM-NEXT: popq %rbx 2639; X64-BMI1NOTBM-NEXT: retq 2640; 2641; X64-BMI1BMI2-LABEL: bextr32_b5_skipextrauses: 2642; X64-BMI1BMI2: # %bb.0: 2643; X64-BMI1BMI2-NEXT: pushq %rbx 2644; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 2645; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %ebx 2646; X64-BMI1BMI2-NEXT: movl %esi, %edi 2647; X64-BMI1BMI2-NEXT: callq use32 2648; X64-BMI1BMI2-NEXT: movl %ebx, %eax 2649; X64-BMI1BMI2-NEXT: popq %rbx 2650; X64-BMI1BMI2-NEXT: retq 2651 %shifted = lshr i32 %val, %numskipbits 2652 %notmask = shl i32 -1, %numlowbits 2653 %mask = xor i32 %notmask, -1 2654 %masked = and i32 %mask, %shifted 2655 call void @use32(i32 %numskipbits) 2656 ret i32 %masked 2657} 2658 2659; 64-bit 2660 2661define i64 @bextr64_b0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 2662; X86-NOBMI-LABEL: bextr64_b0: 2663; X86-NOBMI: # %bb.0: 2664; X86-NOBMI-NEXT: pushl %ebx 2665; X86-NOBMI-NEXT: pushl %edi 2666; X86-NOBMI-NEXT: pushl %esi 2667; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 2668; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2669; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 2670; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2671; X86-NOBMI-NEXT: movl %eax, %edi 2672; X86-NOBMI-NEXT: shrl %cl, %edi 2673; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 2674; X86-NOBMI-NEXT: xorl %eax, %eax 2675; X86-NOBMI-NEXT: testb $32, %cl 2676; X86-NOBMI-NEXT: je .LBB25_2 2677; X86-NOBMI-NEXT: # %bb.1: 2678; X86-NOBMI-NEXT: movl %edi, %esi 2679; X86-NOBMI-NEXT: xorl %edi, %edi 2680; X86-NOBMI-NEXT: .LBB25_2: 2681; X86-NOBMI-NEXT: movl $-1, %edx 2682; X86-NOBMI-NEXT: movl $-1, %ebx 2683; X86-NOBMI-NEXT: movb %ch, %cl 2684; X86-NOBMI-NEXT: shll %cl, %ebx 2685; X86-NOBMI-NEXT: testb $32, %ch 2686; X86-NOBMI-NEXT: jne .LBB25_3 2687; X86-NOBMI-NEXT: # %bb.4: 2688; X86-NOBMI-NEXT: movl %ebx, %eax 2689; X86-NOBMI-NEXT: jmp .LBB25_5 2690; X86-NOBMI-NEXT: .LBB25_3: 2691; X86-NOBMI-NEXT: movl %ebx, %edx 2692; X86-NOBMI-NEXT: .LBB25_5: 2693; X86-NOBMI-NEXT: notl %edx 2694; X86-NOBMI-NEXT: andl %edi, %edx 2695; X86-NOBMI-NEXT: notl %eax 2696; X86-NOBMI-NEXT: andl %esi, %eax 2697; X86-NOBMI-NEXT: popl %esi 2698; X86-NOBMI-NEXT: popl %edi 2699; X86-NOBMI-NEXT: popl %ebx 2700; X86-NOBMI-NEXT: retl 2701; 2702; X86-BMI1NOTBM-LABEL: bextr64_b0: 2703; X86-BMI1NOTBM: # %bb.0: 2704; X86-BMI1NOTBM-NEXT: pushl %ebx 2705; X86-BMI1NOTBM-NEXT: pushl %edi 2706; X86-BMI1NOTBM-NEXT: pushl %esi 2707; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2708; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2709; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 2710; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 2711; X86-BMI1NOTBM-NEXT: movl %edi, %edx 2712; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 2713; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 2714; X86-BMI1NOTBM-NEXT: testb $32, %cl 2715; X86-BMI1NOTBM-NEXT: je .LBB25_2 2716; X86-BMI1NOTBM-NEXT: # %bb.1: 2717; X86-BMI1NOTBM-NEXT: movl %edx, %esi 2718; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 2719; X86-BMI1NOTBM-NEXT: .LBB25_2: 2720; X86-BMI1NOTBM-NEXT: movl $-1, %edi 2721; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 2722; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 2723; X86-BMI1NOTBM-NEXT: shll %cl, %ebx 2724; X86-BMI1NOTBM-NEXT: testb $32, %al 2725; X86-BMI1NOTBM-NEXT: je .LBB25_4 2726; X86-BMI1NOTBM-NEXT: # %bb.3: 2727; X86-BMI1NOTBM-NEXT: movl %ebx, %edi 2728; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 2729; X86-BMI1NOTBM-NEXT: .LBB25_4: 2730; X86-BMI1NOTBM-NEXT: andnl %edx, %edi, %edx 2731; X86-BMI1NOTBM-NEXT: andnl %esi, %ebx, %eax 2732; X86-BMI1NOTBM-NEXT: popl %esi 2733; X86-BMI1NOTBM-NEXT: popl %edi 2734; X86-BMI1NOTBM-NEXT: popl %ebx 2735; X86-BMI1NOTBM-NEXT: retl 2736; 2737; X86-BMI1BMI2-LABEL: bextr64_b0: 2738; X86-BMI1BMI2: # %bb.0: 2739; X86-BMI1BMI2-NEXT: pushl %ebx 2740; X86-BMI1BMI2-NEXT: pushl %esi 2741; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 2742; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2743; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 2744; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 2745; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 2746; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edx 2747; X86-BMI1BMI2-NEXT: testb $32, %cl 2748; X86-BMI1BMI2-NEXT: je .LBB25_2 2749; X86-BMI1BMI2-NEXT: # %bb.1: 2750; X86-BMI1BMI2-NEXT: movl %edx, %eax 2751; X86-BMI1BMI2-NEXT: xorl %edx, %edx 2752; X86-BMI1BMI2-NEXT: .LBB25_2: 2753; X86-BMI1BMI2-NEXT: movl $-1, %esi 2754; X86-BMI1BMI2-NEXT: shlxl %ebx, %esi, %ecx 2755; X86-BMI1BMI2-NEXT: testb $32, %bl 2756; X86-BMI1BMI2-NEXT: je .LBB25_4 2757; X86-BMI1BMI2-NEXT: # %bb.3: 2758; X86-BMI1BMI2-NEXT: movl %ecx, %esi 2759; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 2760; X86-BMI1BMI2-NEXT: .LBB25_4: 2761; X86-BMI1BMI2-NEXT: andnl %edx, %esi, %edx 2762; X86-BMI1BMI2-NEXT: andnl %eax, %ecx, %eax 2763; X86-BMI1BMI2-NEXT: popl %esi 2764; X86-BMI1BMI2-NEXT: popl %ebx 2765; X86-BMI1BMI2-NEXT: retl 2766; 2767; X64-NOBMI-LABEL: bextr64_b0: 2768; X64-NOBMI: # %bb.0: 2769; X64-NOBMI-NEXT: movq %rsi, %rcx 2770; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 2771; X64-NOBMI-NEXT: shrq %cl, %rdi 2772; X64-NOBMI-NEXT: movq $-1, %rax 2773; X64-NOBMI-NEXT: movl %edx, %ecx 2774; X64-NOBMI-NEXT: shlq %cl, %rax 2775; X64-NOBMI-NEXT: notq %rax 2776; X64-NOBMI-NEXT: andq %rdi, %rax 2777; X64-NOBMI-NEXT: retq 2778; 2779; X64-BMI1NOTBM-LABEL: bextr64_b0: 2780; X64-BMI1NOTBM: # %bb.0: 2781; X64-BMI1NOTBM-NEXT: shll $8, %edx 2782; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2783; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2784; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 2785; X64-BMI1NOTBM-NEXT: retq 2786; 2787; X64-BMI1BMI2-LABEL: bextr64_b0: 2788; X64-BMI1BMI2: # %bb.0: 2789; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 2790; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 2791; X64-BMI1BMI2-NEXT: retq 2792 %shifted = lshr i64 %val, %numskipbits 2793 %notmask = shl i64 -1, %numlowbits 2794 %mask = xor i64 %notmask, -1 2795 %masked = and i64 %mask, %shifted 2796 ret i64 %masked 2797} 2798 2799define i64 @bextr64_b1_indexzext(i64 %val, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 2800; X86-NOBMI-LABEL: bextr64_b1_indexzext: 2801; X86-NOBMI: # %bb.0: 2802; X86-NOBMI-NEXT: pushl %ebx 2803; X86-NOBMI-NEXT: pushl %edi 2804; X86-NOBMI-NEXT: pushl %esi 2805; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 2806; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2807; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 2808; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2809; X86-NOBMI-NEXT: movl %eax, %edi 2810; X86-NOBMI-NEXT: shrl %cl, %edi 2811; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 2812; X86-NOBMI-NEXT: xorl %eax, %eax 2813; X86-NOBMI-NEXT: testb $32, %cl 2814; X86-NOBMI-NEXT: je .LBB26_2 2815; X86-NOBMI-NEXT: # %bb.1: 2816; X86-NOBMI-NEXT: movl %edi, %esi 2817; X86-NOBMI-NEXT: xorl %edi, %edi 2818; X86-NOBMI-NEXT: .LBB26_2: 2819; X86-NOBMI-NEXT: movl $-1, %edx 2820; X86-NOBMI-NEXT: movl $-1, %ebx 2821; X86-NOBMI-NEXT: movb %ch, %cl 2822; X86-NOBMI-NEXT: shll %cl, %ebx 2823; X86-NOBMI-NEXT: testb $32, %ch 2824; X86-NOBMI-NEXT: jne .LBB26_3 2825; X86-NOBMI-NEXT: # %bb.4: 2826; X86-NOBMI-NEXT: movl %ebx, %eax 2827; X86-NOBMI-NEXT: jmp .LBB26_5 2828; X86-NOBMI-NEXT: .LBB26_3: 2829; X86-NOBMI-NEXT: movl %ebx, %edx 2830; X86-NOBMI-NEXT: .LBB26_5: 2831; X86-NOBMI-NEXT: notl %edx 2832; X86-NOBMI-NEXT: andl %edi, %edx 2833; X86-NOBMI-NEXT: notl %eax 2834; X86-NOBMI-NEXT: andl %esi, %eax 2835; X86-NOBMI-NEXT: popl %esi 2836; X86-NOBMI-NEXT: popl %edi 2837; X86-NOBMI-NEXT: popl %ebx 2838; X86-NOBMI-NEXT: retl 2839; 2840; X86-BMI1NOTBM-LABEL: bextr64_b1_indexzext: 2841; X86-BMI1NOTBM: # %bb.0: 2842; X86-BMI1NOTBM-NEXT: pushl %ebx 2843; X86-BMI1NOTBM-NEXT: pushl %edi 2844; X86-BMI1NOTBM-NEXT: pushl %esi 2845; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2846; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2847; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 2848; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 2849; X86-BMI1NOTBM-NEXT: movl %edi, %edx 2850; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 2851; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 2852; X86-BMI1NOTBM-NEXT: testb $32, %cl 2853; X86-BMI1NOTBM-NEXT: je .LBB26_2 2854; X86-BMI1NOTBM-NEXT: # %bb.1: 2855; X86-BMI1NOTBM-NEXT: movl %edx, %esi 2856; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 2857; X86-BMI1NOTBM-NEXT: .LBB26_2: 2858; X86-BMI1NOTBM-NEXT: movl $-1, %edi 2859; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 2860; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 2861; X86-BMI1NOTBM-NEXT: shll %cl, %ebx 2862; X86-BMI1NOTBM-NEXT: testb $32, %al 2863; X86-BMI1NOTBM-NEXT: je .LBB26_4 2864; X86-BMI1NOTBM-NEXT: # %bb.3: 2865; X86-BMI1NOTBM-NEXT: movl %ebx, %edi 2866; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 2867; X86-BMI1NOTBM-NEXT: .LBB26_4: 2868; X86-BMI1NOTBM-NEXT: andnl %edx, %edi, %edx 2869; X86-BMI1NOTBM-NEXT: andnl %esi, %ebx, %eax 2870; X86-BMI1NOTBM-NEXT: popl %esi 2871; X86-BMI1NOTBM-NEXT: popl %edi 2872; X86-BMI1NOTBM-NEXT: popl %ebx 2873; X86-BMI1NOTBM-NEXT: retl 2874; 2875; X86-BMI1BMI2-LABEL: bextr64_b1_indexzext: 2876; X86-BMI1BMI2: # %bb.0: 2877; X86-BMI1BMI2-NEXT: pushl %ebx 2878; X86-BMI1BMI2-NEXT: pushl %esi 2879; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 2880; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 2881; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 2882; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 2883; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 2884; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edx 2885; X86-BMI1BMI2-NEXT: testb $32, %cl 2886; X86-BMI1BMI2-NEXT: je .LBB26_2 2887; X86-BMI1BMI2-NEXT: # %bb.1: 2888; X86-BMI1BMI2-NEXT: movl %edx, %eax 2889; X86-BMI1BMI2-NEXT: xorl %edx, %edx 2890; X86-BMI1BMI2-NEXT: .LBB26_2: 2891; X86-BMI1BMI2-NEXT: movl $-1, %esi 2892; X86-BMI1BMI2-NEXT: shlxl %ebx, %esi, %ecx 2893; X86-BMI1BMI2-NEXT: testb $32, %bl 2894; X86-BMI1BMI2-NEXT: je .LBB26_4 2895; X86-BMI1BMI2-NEXT: # %bb.3: 2896; X86-BMI1BMI2-NEXT: movl %ecx, %esi 2897; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 2898; X86-BMI1BMI2-NEXT: .LBB26_4: 2899; X86-BMI1BMI2-NEXT: andnl %edx, %esi, %edx 2900; X86-BMI1BMI2-NEXT: andnl %eax, %ecx, %eax 2901; X86-BMI1BMI2-NEXT: popl %esi 2902; X86-BMI1BMI2-NEXT: popl %ebx 2903; X86-BMI1BMI2-NEXT: retl 2904; 2905; X64-NOBMI-LABEL: bextr64_b1_indexzext: 2906; X64-NOBMI: # %bb.0: 2907; X64-NOBMI-NEXT: movl %esi, %ecx 2908; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 2909; X64-NOBMI-NEXT: shrq %cl, %rdi 2910; X64-NOBMI-NEXT: movq $-1, %rax 2911; X64-NOBMI-NEXT: movl %edx, %ecx 2912; X64-NOBMI-NEXT: shlq %cl, %rax 2913; X64-NOBMI-NEXT: notq %rax 2914; X64-NOBMI-NEXT: andq %rdi, %rax 2915; X64-NOBMI-NEXT: retq 2916; 2917; X64-BMI1NOTBM-LABEL: bextr64_b1_indexzext: 2918; X64-BMI1NOTBM: # %bb.0: 2919; X64-BMI1NOTBM-NEXT: shll $8, %edx 2920; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 2921; X64-BMI1NOTBM-NEXT: orl %edx, %eax 2922; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 2923; X64-BMI1NOTBM-NEXT: retq 2924; 2925; X64-BMI1BMI2-LABEL: bextr64_b1_indexzext: 2926; X64-BMI1BMI2: # %bb.0: 2927; X64-BMI1BMI2-NEXT: # kill: def $edx killed $edx def $rdx 2928; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 2929; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 2930; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 2931; X64-BMI1BMI2-NEXT: retq 2932 %skip = zext i8 %numskipbits to i64 2933 %shifted = lshr i64 %val, %skip 2934 %conv = zext i8 %numlowbits to i64 2935 %notmask = shl i64 -1, %conv 2936 %mask = xor i64 %notmask, -1 2937 %masked = and i64 %mask, %shifted 2938 ret i64 %masked 2939} 2940 2941define i64 @bextr64_b2_load(i64* %w, i64 %numskipbits, i64 %numlowbits) nounwind { 2942; X86-NOBMI-LABEL: bextr64_b2_load: 2943; X86-NOBMI: # %bb.0: 2944; X86-NOBMI-NEXT: pushl %ebx 2945; X86-NOBMI-NEXT: pushl %edi 2946; X86-NOBMI-NEXT: pushl %esi 2947; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 2948; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 2949; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 2950; X86-NOBMI-NEXT: movl (%eax), %esi 2951; X86-NOBMI-NEXT: movl 4(%eax), %eax 2952; X86-NOBMI-NEXT: movl %eax, %edi 2953; X86-NOBMI-NEXT: shrl %cl, %edi 2954; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 2955; X86-NOBMI-NEXT: xorl %eax, %eax 2956; X86-NOBMI-NEXT: testb $32, %cl 2957; X86-NOBMI-NEXT: je .LBB27_2 2958; X86-NOBMI-NEXT: # %bb.1: 2959; X86-NOBMI-NEXT: movl %edi, %esi 2960; X86-NOBMI-NEXT: xorl %edi, %edi 2961; X86-NOBMI-NEXT: .LBB27_2: 2962; X86-NOBMI-NEXT: movl $-1, %edx 2963; X86-NOBMI-NEXT: movl $-1, %ebx 2964; X86-NOBMI-NEXT: movb %ch, %cl 2965; X86-NOBMI-NEXT: shll %cl, %ebx 2966; X86-NOBMI-NEXT: testb $32, %ch 2967; X86-NOBMI-NEXT: jne .LBB27_3 2968; X86-NOBMI-NEXT: # %bb.4: 2969; X86-NOBMI-NEXT: movl %ebx, %eax 2970; X86-NOBMI-NEXT: jmp .LBB27_5 2971; X86-NOBMI-NEXT: .LBB27_3: 2972; X86-NOBMI-NEXT: movl %ebx, %edx 2973; X86-NOBMI-NEXT: .LBB27_5: 2974; X86-NOBMI-NEXT: notl %edx 2975; X86-NOBMI-NEXT: andl %edi, %edx 2976; X86-NOBMI-NEXT: notl %eax 2977; X86-NOBMI-NEXT: andl %esi, %eax 2978; X86-NOBMI-NEXT: popl %esi 2979; X86-NOBMI-NEXT: popl %edi 2980; X86-NOBMI-NEXT: popl %ebx 2981; X86-NOBMI-NEXT: retl 2982; 2983; X86-BMI1NOTBM-LABEL: bextr64_b2_load: 2984; X86-BMI1NOTBM: # %bb.0: 2985; X86-BMI1NOTBM-NEXT: pushl %ebx 2986; X86-BMI1NOTBM-NEXT: pushl %edi 2987; X86-BMI1NOTBM-NEXT: pushl %esi 2988; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 2989; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 2990; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 2991; X86-BMI1NOTBM-NEXT: movl (%edx), %esi 2992; X86-BMI1NOTBM-NEXT: movl 4(%edx), %edi 2993; X86-BMI1NOTBM-NEXT: movl %edi, %edx 2994; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 2995; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 2996; X86-BMI1NOTBM-NEXT: testb $32, %cl 2997; X86-BMI1NOTBM-NEXT: je .LBB27_2 2998; X86-BMI1NOTBM-NEXT: # %bb.1: 2999; X86-BMI1NOTBM-NEXT: movl %edx, %esi 3000; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 3001; X86-BMI1NOTBM-NEXT: .LBB27_2: 3002; X86-BMI1NOTBM-NEXT: movl $-1, %edi 3003; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 3004; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 3005; X86-BMI1NOTBM-NEXT: shll %cl, %ebx 3006; X86-BMI1NOTBM-NEXT: testb $32, %al 3007; X86-BMI1NOTBM-NEXT: je .LBB27_4 3008; X86-BMI1NOTBM-NEXT: # %bb.3: 3009; X86-BMI1NOTBM-NEXT: movl %ebx, %edi 3010; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 3011; X86-BMI1NOTBM-NEXT: .LBB27_4: 3012; X86-BMI1NOTBM-NEXT: andnl %edx, %edi, %edx 3013; X86-BMI1NOTBM-NEXT: andnl %esi, %ebx, %eax 3014; X86-BMI1NOTBM-NEXT: popl %esi 3015; X86-BMI1NOTBM-NEXT: popl %edi 3016; X86-BMI1NOTBM-NEXT: popl %ebx 3017; X86-BMI1NOTBM-NEXT: retl 3018; 3019; X86-BMI1BMI2-LABEL: bextr64_b2_load: 3020; X86-BMI1BMI2: # %bb.0: 3021; X86-BMI1BMI2-NEXT: pushl %ebx 3022; X86-BMI1BMI2-NEXT: pushl %esi 3023; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 3024; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3025; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3026; X86-BMI1BMI2-NEXT: movl (%edx), %eax 3027; X86-BMI1BMI2-NEXT: movl 4(%edx), %esi 3028; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 3029; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %eax 3030; X86-BMI1BMI2-NEXT: testb $32, %cl 3031; X86-BMI1BMI2-NEXT: je .LBB27_2 3032; X86-BMI1BMI2-NEXT: # %bb.1: 3033; X86-BMI1BMI2-NEXT: movl %edx, %eax 3034; X86-BMI1BMI2-NEXT: xorl %edx, %edx 3035; X86-BMI1BMI2-NEXT: .LBB27_2: 3036; X86-BMI1BMI2-NEXT: movl $-1, %esi 3037; X86-BMI1BMI2-NEXT: shlxl %ebx, %esi, %ecx 3038; X86-BMI1BMI2-NEXT: testb $32, %bl 3039; X86-BMI1BMI2-NEXT: je .LBB27_4 3040; X86-BMI1BMI2-NEXT: # %bb.3: 3041; X86-BMI1BMI2-NEXT: movl %ecx, %esi 3042; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 3043; X86-BMI1BMI2-NEXT: .LBB27_4: 3044; X86-BMI1BMI2-NEXT: andnl %edx, %esi, %edx 3045; X86-BMI1BMI2-NEXT: andnl %eax, %ecx, %eax 3046; X86-BMI1BMI2-NEXT: popl %esi 3047; X86-BMI1BMI2-NEXT: popl %ebx 3048; X86-BMI1BMI2-NEXT: retl 3049; 3050; X64-NOBMI-LABEL: bextr64_b2_load: 3051; X64-NOBMI: # %bb.0: 3052; X64-NOBMI-NEXT: movq %rsi, %rcx 3053; X64-NOBMI-NEXT: movq (%rdi), %rsi 3054; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 3055; X64-NOBMI-NEXT: shrq %cl, %rsi 3056; X64-NOBMI-NEXT: movq $-1, %rax 3057; X64-NOBMI-NEXT: movl %edx, %ecx 3058; X64-NOBMI-NEXT: shlq %cl, %rax 3059; X64-NOBMI-NEXT: notq %rax 3060; X64-NOBMI-NEXT: andq %rsi, %rax 3061; X64-NOBMI-NEXT: retq 3062; 3063; X64-BMI1NOTBM-LABEL: bextr64_b2_load: 3064; X64-BMI1NOTBM: # %bb.0: 3065; X64-BMI1NOTBM-NEXT: shll $8, %edx 3066; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3067; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3068; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax 3069; X64-BMI1NOTBM-NEXT: retq 3070; 3071; X64-BMI1BMI2-LABEL: bextr64_b2_load: 3072; X64-BMI1BMI2: # %bb.0: 3073; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %rax 3074; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 3075; X64-BMI1BMI2-NEXT: retq 3076 %val = load i64, i64* %w 3077 %shifted = lshr i64 %val, %numskipbits 3078 %notmask = shl i64 -1, %numlowbits 3079 %mask = xor i64 %notmask, -1 3080 %masked = and i64 %mask, %shifted 3081 ret i64 %masked 3082} 3083 3084define i64 @bextr64_b3_load_indexzext(i64* %w, i8 zeroext %numskipbits, i8 zeroext %numlowbits) nounwind { 3085; X86-NOBMI-LABEL: bextr64_b3_load_indexzext: 3086; X86-NOBMI: # %bb.0: 3087; X86-NOBMI-NEXT: pushl %ebx 3088; X86-NOBMI-NEXT: pushl %edi 3089; X86-NOBMI-NEXT: pushl %esi 3090; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 3091; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 3092; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 3093; X86-NOBMI-NEXT: movl (%eax), %esi 3094; X86-NOBMI-NEXT: movl 4(%eax), %eax 3095; X86-NOBMI-NEXT: movl %eax, %edi 3096; X86-NOBMI-NEXT: shrl %cl, %edi 3097; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 3098; X86-NOBMI-NEXT: xorl %eax, %eax 3099; X86-NOBMI-NEXT: testb $32, %cl 3100; X86-NOBMI-NEXT: je .LBB28_2 3101; X86-NOBMI-NEXT: # %bb.1: 3102; X86-NOBMI-NEXT: movl %edi, %esi 3103; X86-NOBMI-NEXT: xorl %edi, %edi 3104; X86-NOBMI-NEXT: .LBB28_2: 3105; X86-NOBMI-NEXT: movl $-1, %edx 3106; X86-NOBMI-NEXT: movl $-1, %ebx 3107; X86-NOBMI-NEXT: movb %ch, %cl 3108; X86-NOBMI-NEXT: shll %cl, %ebx 3109; X86-NOBMI-NEXT: testb $32, %ch 3110; X86-NOBMI-NEXT: jne .LBB28_3 3111; X86-NOBMI-NEXT: # %bb.4: 3112; X86-NOBMI-NEXT: movl %ebx, %eax 3113; X86-NOBMI-NEXT: jmp .LBB28_5 3114; X86-NOBMI-NEXT: .LBB28_3: 3115; X86-NOBMI-NEXT: movl %ebx, %edx 3116; X86-NOBMI-NEXT: .LBB28_5: 3117; X86-NOBMI-NEXT: notl %edx 3118; X86-NOBMI-NEXT: andl %edi, %edx 3119; X86-NOBMI-NEXT: notl %eax 3120; X86-NOBMI-NEXT: andl %esi, %eax 3121; X86-NOBMI-NEXT: popl %esi 3122; X86-NOBMI-NEXT: popl %edi 3123; X86-NOBMI-NEXT: popl %ebx 3124; X86-NOBMI-NEXT: retl 3125; 3126; X86-BMI1NOTBM-LABEL: bextr64_b3_load_indexzext: 3127; X86-BMI1NOTBM: # %bb.0: 3128; X86-BMI1NOTBM-NEXT: pushl %ebx 3129; X86-BMI1NOTBM-NEXT: pushl %edi 3130; X86-BMI1NOTBM-NEXT: pushl %esi 3131; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 3132; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 3133; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 3134; X86-BMI1NOTBM-NEXT: movl (%edx), %esi 3135; X86-BMI1NOTBM-NEXT: movl 4(%edx), %edi 3136; X86-BMI1NOTBM-NEXT: movl %edi, %edx 3137; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 3138; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 3139; X86-BMI1NOTBM-NEXT: testb $32, %cl 3140; X86-BMI1NOTBM-NEXT: je .LBB28_2 3141; X86-BMI1NOTBM-NEXT: # %bb.1: 3142; X86-BMI1NOTBM-NEXT: movl %edx, %esi 3143; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 3144; X86-BMI1NOTBM-NEXT: .LBB28_2: 3145; X86-BMI1NOTBM-NEXT: movl $-1, %edi 3146; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 3147; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 3148; X86-BMI1NOTBM-NEXT: shll %cl, %ebx 3149; X86-BMI1NOTBM-NEXT: testb $32, %al 3150; X86-BMI1NOTBM-NEXT: je .LBB28_4 3151; X86-BMI1NOTBM-NEXT: # %bb.3: 3152; X86-BMI1NOTBM-NEXT: movl %ebx, %edi 3153; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 3154; X86-BMI1NOTBM-NEXT: .LBB28_4: 3155; X86-BMI1NOTBM-NEXT: andnl %edx, %edi, %edx 3156; X86-BMI1NOTBM-NEXT: andnl %esi, %ebx, %eax 3157; X86-BMI1NOTBM-NEXT: popl %esi 3158; X86-BMI1NOTBM-NEXT: popl %edi 3159; X86-BMI1NOTBM-NEXT: popl %ebx 3160; X86-BMI1NOTBM-NEXT: retl 3161; 3162; X86-BMI1BMI2-LABEL: bextr64_b3_load_indexzext: 3163; X86-BMI1BMI2: # %bb.0: 3164; X86-BMI1BMI2-NEXT: pushl %ebx 3165; X86-BMI1BMI2-NEXT: pushl %esi 3166; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 3167; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3168; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3169; X86-BMI1BMI2-NEXT: movl (%edx), %eax 3170; X86-BMI1BMI2-NEXT: movl 4(%edx), %esi 3171; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 3172; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %eax 3173; X86-BMI1BMI2-NEXT: testb $32, %cl 3174; X86-BMI1BMI2-NEXT: je .LBB28_2 3175; X86-BMI1BMI2-NEXT: # %bb.1: 3176; X86-BMI1BMI2-NEXT: movl %edx, %eax 3177; X86-BMI1BMI2-NEXT: xorl %edx, %edx 3178; X86-BMI1BMI2-NEXT: .LBB28_2: 3179; X86-BMI1BMI2-NEXT: movl $-1, %esi 3180; X86-BMI1BMI2-NEXT: shlxl %ebx, %esi, %ecx 3181; X86-BMI1BMI2-NEXT: testb $32, %bl 3182; X86-BMI1BMI2-NEXT: je .LBB28_4 3183; X86-BMI1BMI2-NEXT: # %bb.3: 3184; X86-BMI1BMI2-NEXT: movl %ecx, %esi 3185; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 3186; X86-BMI1BMI2-NEXT: .LBB28_4: 3187; X86-BMI1BMI2-NEXT: andnl %edx, %esi, %edx 3188; X86-BMI1BMI2-NEXT: andnl %eax, %ecx, %eax 3189; X86-BMI1BMI2-NEXT: popl %esi 3190; X86-BMI1BMI2-NEXT: popl %ebx 3191; X86-BMI1BMI2-NEXT: retl 3192; 3193; X64-NOBMI-LABEL: bextr64_b3_load_indexzext: 3194; X64-NOBMI: # %bb.0: 3195; X64-NOBMI-NEXT: movl %esi, %ecx 3196; X64-NOBMI-NEXT: movq (%rdi), %rsi 3197; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 3198; X64-NOBMI-NEXT: shrq %cl, %rsi 3199; X64-NOBMI-NEXT: movq $-1, %rax 3200; X64-NOBMI-NEXT: movl %edx, %ecx 3201; X64-NOBMI-NEXT: shlq %cl, %rax 3202; X64-NOBMI-NEXT: notq %rax 3203; X64-NOBMI-NEXT: andq %rsi, %rax 3204; X64-NOBMI-NEXT: retq 3205; 3206; X64-BMI1NOTBM-LABEL: bextr64_b3_load_indexzext: 3207; X64-BMI1NOTBM: # %bb.0: 3208; X64-BMI1NOTBM-NEXT: shll $8, %edx 3209; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3210; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3211; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax 3212; X64-BMI1NOTBM-NEXT: retq 3213; 3214; X64-BMI1BMI2-LABEL: bextr64_b3_load_indexzext: 3215; X64-BMI1BMI2: # %bb.0: 3216; X64-BMI1BMI2-NEXT: # kill: def $edx killed $edx def $rdx 3217; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 3218; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %rax 3219; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 3220; X64-BMI1BMI2-NEXT: retq 3221 %val = load i64, i64* %w 3222 %skip = zext i8 %numskipbits to i64 3223 %shifted = lshr i64 %val, %skip 3224 %conv = zext i8 %numlowbits to i64 3225 %notmask = shl i64 -1, %conv 3226 %mask = xor i64 %notmask, -1 3227 %masked = and i64 %mask, %shifted 3228 ret i64 %masked 3229} 3230 3231define i64 @bextr64_b4_commutative(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 3232; X86-NOBMI-LABEL: bextr64_b4_commutative: 3233; X86-NOBMI: # %bb.0: 3234; X86-NOBMI-NEXT: pushl %ebx 3235; X86-NOBMI-NEXT: pushl %edi 3236; X86-NOBMI-NEXT: pushl %esi 3237; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 3238; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 3239; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 3240; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 3241; X86-NOBMI-NEXT: movl %esi, %edx 3242; X86-NOBMI-NEXT: shrl %cl, %edx 3243; X86-NOBMI-NEXT: shrdl %cl, %esi, %eax 3244; X86-NOBMI-NEXT: xorl %esi, %esi 3245; X86-NOBMI-NEXT: testb $32, %cl 3246; X86-NOBMI-NEXT: je .LBB29_2 3247; X86-NOBMI-NEXT: # %bb.1: 3248; X86-NOBMI-NEXT: movl %edx, %eax 3249; X86-NOBMI-NEXT: xorl %edx, %edx 3250; X86-NOBMI-NEXT: .LBB29_2: 3251; X86-NOBMI-NEXT: movl $-1, %edi 3252; X86-NOBMI-NEXT: movl $-1, %ebx 3253; X86-NOBMI-NEXT: movb %ch, %cl 3254; X86-NOBMI-NEXT: shll %cl, %ebx 3255; X86-NOBMI-NEXT: testb $32, %ch 3256; X86-NOBMI-NEXT: jne .LBB29_3 3257; X86-NOBMI-NEXT: # %bb.4: 3258; X86-NOBMI-NEXT: movl %ebx, %esi 3259; X86-NOBMI-NEXT: jmp .LBB29_5 3260; X86-NOBMI-NEXT: .LBB29_3: 3261; X86-NOBMI-NEXT: movl %ebx, %edi 3262; X86-NOBMI-NEXT: .LBB29_5: 3263; X86-NOBMI-NEXT: notl %edi 3264; X86-NOBMI-NEXT: andl %edi, %edx 3265; X86-NOBMI-NEXT: notl %esi 3266; X86-NOBMI-NEXT: andl %esi, %eax 3267; X86-NOBMI-NEXT: popl %esi 3268; X86-NOBMI-NEXT: popl %edi 3269; X86-NOBMI-NEXT: popl %ebx 3270; X86-NOBMI-NEXT: retl 3271; 3272; X86-BMI1NOTBM-LABEL: bextr64_b4_commutative: 3273; X86-BMI1NOTBM: # %bb.0: 3274; X86-BMI1NOTBM-NEXT: pushl %ebx 3275; X86-BMI1NOTBM-NEXT: pushl %edi 3276; X86-BMI1NOTBM-NEXT: pushl %esi 3277; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 3278; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 3279; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 3280; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 3281; X86-BMI1NOTBM-NEXT: movl %edi, %edx 3282; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 3283; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 3284; X86-BMI1NOTBM-NEXT: testb $32, %cl 3285; X86-BMI1NOTBM-NEXT: je .LBB29_2 3286; X86-BMI1NOTBM-NEXT: # %bb.1: 3287; X86-BMI1NOTBM-NEXT: movl %edx, %esi 3288; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 3289; X86-BMI1NOTBM-NEXT: .LBB29_2: 3290; X86-BMI1NOTBM-NEXT: movl $-1, %edi 3291; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 3292; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 3293; X86-BMI1NOTBM-NEXT: shll %cl, %ebx 3294; X86-BMI1NOTBM-NEXT: testb $32, %al 3295; X86-BMI1NOTBM-NEXT: je .LBB29_4 3296; X86-BMI1NOTBM-NEXT: # %bb.3: 3297; X86-BMI1NOTBM-NEXT: movl %ebx, %edi 3298; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 3299; X86-BMI1NOTBM-NEXT: .LBB29_4: 3300; X86-BMI1NOTBM-NEXT: andnl %edx, %edi, %edx 3301; X86-BMI1NOTBM-NEXT: andnl %esi, %ebx, %eax 3302; X86-BMI1NOTBM-NEXT: popl %esi 3303; X86-BMI1NOTBM-NEXT: popl %edi 3304; X86-BMI1NOTBM-NEXT: popl %ebx 3305; X86-BMI1NOTBM-NEXT: retl 3306; 3307; X86-BMI1BMI2-LABEL: bextr64_b4_commutative: 3308; X86-BMI1BMI2: # %bb.0: 3309; X86-BMI1BMI2-NEXT: pushl %ebx 3310; X86-BMI1BMI2-NEXT: pushl %esi 3311; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 3312; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3313; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 3314; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3315; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 3316; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edx 3317; X86-BMI1BMI2-NEXT: testb $32, %cl 3318; X86-BMI1BMI2-NEXT: je .LBB29_2 3319; X86-BMI1BMI2-NEXT: # %bb.1: 3320; X86-BMI1BMI2-NEXT: movl %edx, %eax 3321; X86-BMI1BMI2-NEXT: xorl %edx, %edx 3322; X86-BMI1BMI2-NEXT: .LBB29_2: 3323; X86-BMI1BMI2-NEXT: movl $-1, %esi 3324; X86-BMI1BMI2-NEXT: shlxl %ebx, %esi, %ecx 3325; X86-BMI1BMI2-NEXT: testb $32, %bl 3326; X86-BMI1BMI2-NEXT: je .LBB29_4 3327; X86-BMI1BMI2-NEXT: # %bb.3: 3328; X86-BMI1BMI2-NEXT: movl %ecx, %esi 3329; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 3330; X86-BMI1BMI2-NEXT: .LBB29_4: 3331; X86-BMI1BMI2-NEXT: andnl %edx, %esi, %edx 3332; X86-BMI1BMI2-NEXT: andnl %eax, %ecx, %eax 3333; X86-BMI1BMI2-NEXT: popl %esi 3334; X86-BMI1BMI2-NEXT: popl %ebx 3335; X86-BMI1BMI2-NEXT: retl 3336; 3337; X64-NOBMI-LABEL: bextr64_b4_commutative: 3338; X64-NOBMI: # %bb.0: 3339; X64-NOBMI-NEXT: movq %rsi, %rcx 3340; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 3341; X64-NOBMI-NEXT: shrq %cl, %rdi 3342; X64-NOBMI-NEXT: movq $-1, %rax 3343; X64-NOBMI-NEXT: movl %edx, %ecx 3344; X64-NOBMI-NEXT: shlq %cl, %rax 3345; X64-NOBMI-NEXT: notq %rax 3346; X64-NOBMI-NEXT: andq %rdi, %rax 3347; X64-NOBMI-NEXT: retq 3348; 3349; X64-BMI1NOTBM-LABEL: bextr64_b4_commutative: 3350; X64-BMI1NOTBM: # %bb.0: 3351; X64-BMI1NOTBM-NEXT: shll $8, %edx 3352; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3353; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3354; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 3355; X64-BMI1NOTBM-NEXT: retq 3356; 3357; X64-BMI1BMI2-LABEL: bextr64_b4_commutative: 3358; X64-BMI1BMI2: # %bb.0: 3359; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 3360; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 3361; X64-BMI1BMI2-NEXT: retq 3362 %shifted = lshr i64 %val, %numskipbits 3363 %notmask = shl i64 -1, %numlowbits 3364 %mask = xor i64 %notmask, -1 3365 %masked = and i64 %shifted, %mask ; swapped order 3366 ret i64 %masked 3367} 3368 3369define i64 @bextr64_b5_skipextrauses(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 3370; X86-NOBMI-LABEL: bextr64_b5_skipextrauses: 3371; X86-NOBMI: # %bb.0: 3372; X86-NOBMI-NEXT: pushl %ebp 3373; X86-NOBMI-NEXT: pushl %ebx 3374; X86-NOBMI-NEXT: pushl %edi 3375; X86-NOBMI-NEXT: pushl %esi 3376; X86-NOBMI-NEXT: subl $12, %esp 3377; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %ch 3378; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 3379; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 3380; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 3381; X86-NOBMI-NEXT: movl %esi, %ebp 3382; X86-NOBMI-NEXT: movb %al, %cl 3383; X86-NOBMI-NEXT: shrl %cl, %ebp 3384; X86-NOBMI-NEXT: shrdl %cl, %esi, %edx 3385; X86-NOBMI-NEXT: xorl %ebx, %ebx 3386; X86-NOBMI-NEXT: testb $32, %al 3387; X86-NOBMI-NEXT: je .LBB30_2 3388; X86-NOBMI-NEXT: # %bb.1: 3389; X86-NOBMI-NEXT: movl %ebp, %edx 3390; X86-NOBMI-NEXT: xorl %ebp, %ebp 3391; X86-NOBMI-NEXT: .LBB30_2: 3392; X86-NOBMI-NEXT: movl $-1, %edi 3393; X86-NOBMI-NEXT: movl $-1, %esi 3394; X86-NOBMI-NEXT: movb %ch, %cl 3395; X86-NOBMI-NEXT: shll %cl, %esi 3396; X86-NOBMI-NEXT: testb $32, %ch 3397; X86-NOBMI-NEXT: jne .LBB30_3 3398; X86-NOBMI-NEXT: # %bb.4: 3399; X86-NOBMI-NEXT: movl %esi, %ebx 3400; X86-NOBMI-NEXT: jmp .LBB30_5 3401; X86-NOBMI-NEXT: .LBB30_3: 3402; X86-NOBMI-NEXT: movl %esi, %edi 3403; X86-NOBMI-NEXT: .LBB30_5: 3404; X86-NOBMI-NEXT: notl %edi 3405; X86-NOBMI-NEXT: andl %ebp, %edi 3406; X86-NOBMI-NEXT: notl %ebx 3407; X86-NOBMI-NEXT: andl %edx, %ebx 3408; X86-NOBMI-NEXT: subl $8, %esp 3409; X86-NOBMI-NEXT: pushl {{[0-9]+}}(%esp) 3410; X86-NOBMI-NEXT: pushl %eax 3411; X86-NOBMI-NEXT: calll use64 3412; X86-NOBMI-NEXT: addl $16, %esp 3413; X86-NOBMI-NEXT: movl %ebx, %eax 3414; X86-NOBMI-NEXT: movl %edi, %edx 3415; X86-NOBMI-NEXT: addl $12, %esp 3416; X86-NOBMI-NEXT: popl %esi 3417; X86-NOBMI-NEXT: popl %edi 3418; X86-NOBMI-NEXT: popl %ebx 3419; X86-NOBMI-NEXT: popl %ebp 3420; X86-NOBMI-NEXT: retl 3421; 3422; X86-BMI1NOTBM-LABEL: bextr64_b5_skipextrauses: 3423; X86-BMI1NOTBM: # %bb.0: 3424; X86-BMI1NOTBM-NEXT: pushl %ebp 3425; X86-BMI1NOTBM-NEXT: pushl %ebx 3426; X86-BMI1NOTBM-NEXT: pushl %edi 3427; X86-BMI1NOTBM-NEXT: pushl %esi 3428; X86-BMI1NOTBM-NEXT: subl $12, %esp 3429; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %dl 3430; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 3431; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ebx 3432; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 3433; X86-BMI1NOTBM-NEXT: movl %ebx, %esi 3434; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 3435; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 3436; X86-BMI1NOTBM-NEXT: shrdl %cl, %ebx, %edi 3437; X86-BMI1NOTBM-NEXT: testb $32, %al 3438; X86-BMI1NOTBM-NEXT: je .LBB30_2 3439; X86-BMI1NOTBM-NEXT: # %bb.1: 3440; X86-BMI1NOTBM-NEXT: movl %esi, %edi 3441; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 3442; X86-BMI1NOTBM-NEXT: .LBB30_2: 3443; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 3444; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 3445; X86-BMI1NOTBM-NEXT: movl %edx, %ecx 3446; X86-BMI1NOTBM-NEXT: shll %cl, %ebp 3447; X86-BMI1NOTBM-NEXT: testb $32, %dl 3448; X86-BMI1NOTBM-NEXT: je .LBB30_4 3449; X86-BMI1NOTBM-NEXT: # %bb.3: 3450; X86-BMI1NOTBM-NEXT: movl %ebp, %ebx 3451; X86-BMI1NOTBM-NEXT: xorl %ebp, %ebp 3452; X86-BMI1NOTBM-NEXT: .LBB30_4: 3453; X86-BMI1NOTBM-NEXT: andnl %esi, %ebx, %esi 3454; X86-BMI1NOTBM-NEXT: andnl %edi, %ebp, %edi 3455; X86-BMI1NOTBM-NEXT: subl $8, %esp 3456; X86-BMI1NOTBM-NEXT: pushl {{[0-9]+}}(%esp) 3457; X86-BMI1NOTBM-NEXT: pushl %eax 3458; X86-BMI1NOTBM-NEXT: calll use64 3459; X86-BMI1NOTBM-NEXT: addl $16, %esp 3460; X86-BMI1NOTBM-NEXT: movl %edi, %eax 3461; X86-BMI1NOTBM-NEXT: movl %esi, %edx 3462; X86-BMI1NOTBM-NEXT: addl $12, %esp 3463; X86-BMI1NOTBM-NEXT: popl %esi 3464; X86-BMI1NOTBM-NEXT: popl %edi 3465; X86-BMI1NOTBM-NEXT: popl %ebx 3466; X86-BMI1NOTBM-NEXT: popl %ebp 3467; X86-BMI1NOTBM-NEXT: retl 3468; 3469; X86-BMI1BMI2-LABEL: bextr64_b5_skipextrauses: 3470; X86-BMI1BMI2: # %bb.0: 3471; X86-BMI1BMI2-NEXT: pushl %ebp 3472; X86-BMI1BMI2-NEXT: pushl %ebx 3473; X86-BMI1BMI2-NEXT: pushl %edi 3474; X86-BMI1BMI2-NEXT: pushl %esi 3475; X86-BMI1BMI2-NEXT: subl $12, %esp 3476; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 3477; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 3478; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3479; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 3480; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 3481; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edx 3482; X86-BMI1BMI2-NEXT: testb $32, %cl 3483; X86-BMI1BMI2-NEXT: je .LBB30_2 3484; X86-BMI1BMI2-NEXT: # %bb.1: 3485; X86-BMI1BMI2-NEXT: movl %edx, %eax 3486; X86-BMI1BMI2-NEXT: xorl %edx, %edx 3487; X86-BMI1BMI2-NEXT: .LBB30_2: 3488; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ebp 3489; X86-BMI1BMI2-NEXT: movl $-1, %esi 3490; X86-BMI1BMI2-NEXT: shlxl %ebx, %esi, %edi 3491; X86-BMI1BMI2-NEXT: testb $32, %bl 3492; X86-BMI1BMI2-NEXT: je .LBB30_4 3493; X86-BMI1BMI2-NEXT: # %bb.3: 3494; X86-BMI1BMI2-NEXT: movl %edi, %esi 3495; X86-BMI1BMI2-NEXT: xorl %edi, %edi 3496; X86-BMI1BMI2-NEXT: .LBB30_4: 3497; X86-BMI1BMI2-NEXT: andnl %edx, %esi, %esi 3498; X86-BMI1BMI2-NEXT: andnl %eax, %edi, %edi 3499; X86-BMI1BMI2-NEXT: subl $8, %esp 3500; X86-BMI1BMI2-NEXT: pushl %ebp 3501; X86-BMI1BMI2-NEXT: pushl %ecx 3502; X86-BMI1BMI2-NEXT: calll use64 3503; X86-BMI1BMI2-NEXT: addl $16, %esp 3504; X86-BMI1BMI2-NEXT: movl %edi, %eax 3505; X86-BMI1BMI2-NEXT: movl %esi, %edx 3506; X86-BMI1BMI2-NEXT: addl $12, %esp 3507; X86-BMI1BMI2-NEXT: popl %esi 3508; X86-BMI1BMI2-NEXT: popl %edi 3509; X86-BMI1BMI2-NEXT: popl %ebx 3510; X86-BMI1BMI2-NEXT: popl %ebp 3511; X86-BMI1BMI2-NEXT: retl 3512; 3513; X64-NOBMI-LABEL: bextr64_b5_skipextrauses: 3514; X64-NOBMI: # %bb.0: 3515; X64-NOBMI-NEXT: pushq %rbx 3516; X64-NOBMI-NEXT: movl %esi, %ecx 3517; X64-NOBMI-NEXT: shrq %cl, %rdi 3518; X64-NOBMI-NEXT: movq $-1, %rbx 3519; X64-NOBMI-NEXT: movl %edx, %ecx 3520; X64-NOBMI-NEXT: shlq %cl, %rbx 3521; X64-NOBMI-NEXT: notq %rbx 3522; X64-NOBMI-NEXT: andq %rdi, %rbx 3523; X64-NOBMI-NEXT: movq %rsi, %rdi 3524; X64-NOBMI-NEXT: callq use64 3525; X64-NOBMI-NEXT: movq %rbx, %rax 3526; X64-NOBMI-NEXT: popq %rbx 3527; X64-NOBMI-NEXT: retq 3528; 3529; X64-BMI1NOTBM-LABEL: bextr64_b5_skipextrauses: 3530; X64-BMI1NOTBM: # %bb.0: 3531; X64-BMI1NOTBM-NEXT: pushq %rbx 3532; X64-BMI1NOTBM-NEXT: shll $8, %edx 3533; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3534; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3535; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rbx 3536; X64-BMI1NOTBM-NEXT: movq %rsi, %rdi 3537; X64-BMI1NOTBM-NEXT: callq use64 3538; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 3539; X64-BMI1NOTBM-NEXT: popq %rbx 3540; X64-BMI1NOTBM-NEXT: retq 3541; 3542; X64-BMI1BMI2-LABEL: bextr64_b5_skipextrauses: 3543; X64-BMI1BMI2: # %bb.0: 3544; X64-BMI1BMI2-NEXT: pushq %rbx 3545; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 3546; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rbx 3547; X64-BMI1BMI2-NEXT: movq %rsi, %rdi 3548; X64-BMI1BMI2-NEXT: callq use64 3549; X64-BMI1BMI2-NEXT: movq %rbx, %rax 3550; X64-BMI1BMI2-NEXT: popq %rbx 3551; X64-BMI1BMI2-NEXT: retq 3552 %shifted = lshr i64 %val, %numskipbits 3553 %notmask = shl i64 -1, %numlowbits 3554 %mask = xor i64 %notmask, -1 3555 %masked = and i64 %mask, %shifted 3556 call void @use64(i64 %numskipbits) 3557 ret i64 %masked 3558} 3559 3560; 64-bit, but with 32-bit output 3561 3562; Everything done in 64-bit, truncation happens last. 3563define i32 @bextr64_32_b0(i64 %val, i64 %numskipbits, i8 %numlowbits) nounwind { 3564; X86-NOBMI-LABEL: bextr64_32_b0: 3565; X86-NOBMI: # %bb.0: 3566; X86-NOBMI-NEXT: pushl %edi 3567; X86-NOBMI-NEXT: pushl %esi 3568; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 3569; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 3570; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 3571; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 3572; X86-NOBMI-NEXT: movl %edi, %eax 3573; X86-NOBMI-NEXT: shrl %cl, %eax 3574; X86-NOBMI-NEXT: shrdl %cl, %edi, %esi 3575; X86-NOBMI-NEXT: testb $32, %cl 3576; X86-NOBMI-NEXT: jne .LBB31_2 3577; X86-NOBMI-NEXT: # %bb.1: 3578; X86-NOBMI-NEXT: movl %esi, %eax 3579; X86-NOBMI-NEXT: .LBB31_2: 3580; X86-NOBMI-NEXT: movl $-1, %esi 3581; X86-NOBMI-NEXT: movl %edx, %ecx 3582; X86-NOBMI-NEXT: shll %cl, %esi 3583; X86-NOBMI-NEXT: xorl %ecx, %ecx 3584; X86-NOBMI-NEXT: testb $32, %dl 3585; X86-NOBMI-NEXT: jne .LBB31_4 3586; X86-NOBMI-NEXT: # %bb.3: 3587; X86-NOBMI-NEXT: movl %esi, %ecx 3588; X86-NOBMI-NEXT: .LBB31_4: 3589; X86-NOBMI-NEXT: notl %ecx 3590; X86-NOBMI-NEXT: andl %ecx, %eax 3591; X86-NOBMI-NEXT: popl %esi 3592; X86-NOBMI-NEXT: popl %edi 3593; X86-NOBMI-NEXT: retl 3594; 3595; X86-BMI1NOTBM-LABEL: bextr64_32_b0: 3596; X86-BMI1NOTBM: # %bb.0: 3597; X86-BMI1NOTBM-NEXT: pushl %edi 3598; X86-BMI1NOTBM-NEXT: pushl %esi 3599; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 3600; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 3601; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 3602; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 3603; X86-BMI1NOTBM-NEXT: movl %edi, %edx 3604; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 3605; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 3606; X86-BMI1NOTBM-NEXT: testb $32, %cl 3607; X86-BMI1NOTBM-NEXT: jne .LBB31_2 3608; X86-BMI1NOTBM-NEXT: # %bb.1: 3609; X86-BMI1NOTBM-NEXT: movl %esi, %edx 3610; X86-BMI1NOTBM-NEXT: .LBB31_2: 3611; X86-BMI1NOTBM-NEXT: movl $-1, %esi 3612; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 3613; X86-BMI1NOTBM-NEXT: shll %cl, %esi 3614; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 3615; X86-BMI1NOTBM-NEXT: testb $32, %al 3616; X86-BMI1NOTBM-NEXT: jne .LBB31_4 3617; X86-BMI1NOTBM-NEXT: # %bb.3: 3618; X86-BMI1NOTBM-NEXT: movl %esi, %ecx 3619; X86-BMI1NOTBM-NEXT: .LBB31_4: 3620; X86-BMI1NOTBM-NEXT: andnl %edx, %ecx, %eax 3621; X86-BMI1NOTBM-NEXT: popl %esi 3622; X86-BMI1NOTBM-NEXT: popl %edi 3623; X86-BMI1NOTBM-NEXT: retl 3624; 3625; X86-BMI1BMI2-LABEL: bextr64_32_b0: 3626; X86-BMI1BMI2: # %bb.0: 3627; X86-BMI1BMI2-NEXT: pushl %esi 3628; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 3629; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3630; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3631; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 3632; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 3633; X86-BMI1BMI2-NEXT: testb $32, %cl 3634; X86-BMI1BMI2-NEXT: je .LBB31_2 3635; X86-BMI1BMI2-NEXT: # %bb.1: 3636; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 3637; X86-BMI1BMI2-NEXT: .LBB31_2: 3638; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 3639; X86-BMI1BMI2-NEXT: testb $32, %al 3640; X86-BMI1BMI2-NEXT: jne .LBB31_4 3641; X86-BMI1BMI2-NEXT: # %bb.3: 3642; X86-BMI1BMI2-NEXT: movl $-1, %ecx 3643; X86-BMI1BMI2-NEXT: shlxl %eax, %ecx, %ecx 3644; X86-BMI1BMI2-NEXT: .LBB31_4: 3645; X86-BMI1BMI2-NEXT: andnl %edx, %ecx, %eax 3646; X86-BMI1BMI2-NEXT: popl %esi 3647; X86-BMI1BMI2-NEXT: retl 3648; 3649; X64-NOBMI-LABEL: bextr64_32_b0: 3650; X64-NOBMI: # %bb.0: 3651; X64-NOBMI-NEXT: movq %rsi, %rcx 3652; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 3653; X64-NOBMI-NEXT: shrq %cl, %rdi 3654; X64-NOBMI-NEXT: movq $-1, %rax 3655; X64-NOBMI-NEXT: movl %edx, %ecx 3656; X64-NOBMI-NEXT: shlq %cl, %rax 3657; X64-NOBMI-NEXT: notl %eax 3658; X64-NOBMI-NEXT: andl %edi, %eax 3659; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 3660; X64-NOBMI-NEXT: retq 3661; 3662; X64-BMI1NOTBM-LABEL: bextr64_32_b0: 3663; X64-BMI1NOTBM: # %bb.0: 3664; X64-BMI1NOTBM-NEXT: shll $8, %edx 3665; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3666; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3667; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 3668; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 3669; X64-BMI1NOTBM-NEXT: retq 3670; 3671; X64-BMI1BMI2-LABEL: bextr64_32_b0: 3672; X64-BMI1BMI2: # %bb.0: 3673; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 3674; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 3675; X64-BMI1BMI2-NEXT: retq 3676 %shiftedval = lshr i64 %val, %numskipbits 3677 %widenumlowbits = zext i8 %numlowbits to i64 3678 %notmask = shl nsw i64 -1, %widenumlowbits 3679 %mask = xor i64 %notmask, -1 3680 %wideres = and i64 %shiftedval, %mask 3681 %res = trunc i64 %wideres to i32 3682 ret i32 %res 3683} 3684 3685; Shifting happens in 64-bit, then truncation. Masking is 32-bit. 3686define i32 @bextr64_32_b1(i64 %val, i64 %numskipbits, i8 %numlowbits) nounwind { 3687; X86-NOBMI-LABEL: bextr64_32_b1: 3688; X86-NOBMI: # %bb.0: 3689; X86-NOBMI-NEXT: pushl %edi 3690; X86-NOBMI-NEXT: pushl %esi 3691; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 3692; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 3693; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 3694; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 3695; X86-NOBMI-NEXT: movl %edi, %esi 3696; X86-NOBMI-NEXT: shrl %cl, %esi 3697; X86-NOBMI-NEXT: shrdl %cl, %edi, %eax 3698; X86-NOBMI-NEXT: testb $32, %cl 3699; X86-NOBMI-NEXT: jne .LBB32_2 3700; X86-NOBMI-NEXT: # %bb.1: 3701; X86-NOBMI-NEXT: movl %eax, %esi 3702; X86-NOBMI-NEXT: .LBB32_2: 3703; X86-NOBMI-NEXT: movl $-1, %eax 3704; X86-NOBMI-NEXT: movl %edx, %ecx 3705; X86-NOBMI-NEXT: shll %cl, %eax 3706; X86-NOBMI-NEXT: notl %eax 3707; X86-NOBMI-NEXT: andl %esi, %eax 3708; X86-NOBMI-NEXT: popl %esi 3709; X86-NOBMI-NEXT: popl %edi 3710; X86-NOBMI-NEXT: retl 3711; 3712; X86-BMI1NOTBM-LABEL: bextr64_32_b1: 3713; X86-BMI1NOTBM: # %bb.0: 3714; X86-BMI1NOTBM-NEXT: pushl %edi 3715; X86-BMI1NOTBM-NEXT: pushl %esi 3716; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 3717; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 3718; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 3719; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 3720; X86-BMI1NOTBM-NEXT: movl %edi, %edx 3721; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 3722; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 3723; X86-BMI1NOTBM-NEXT: testb $32, %cl 3724; X86-BMI1NOTBM-NEXT: jne .LBB32_2 3725; X86-BMI1NOTBM-NEXT: # %bb.1: 3726; X86-BMI1NOTBM-NEXT: movl %esi, %edx 3727; X86-BMI1NOTBM-NEXT: .LBB32_2: 3728; X86-BMI1NOTBM-NEXT: shll $8, %eax 3729; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 3730; X86-BMI1NOTBM-NEXT: popl %esi 3731; X86-BMI1NOTBM-NEXT: popl %edi 3732; X86-BMI1NOTBM-NEXT: retl 3733; 3734; X86-BMI1BMI2-LABEL: bextr64_32_b1: 3735; X86-BMI1BMI2: # %bb.0: 3736; X86-BMI1BMI2-NEXT: pushl %esi 3737; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 3738; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3739; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3740; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 3741; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 3742; X86-BMI1BMI2-NEXT: testb $32, %cl 3743; X86-BMI1BMI2-NEXT: je .LBB32_2 3744; X86-BMI1BMI2-NEXT: # %bb.1: 3745; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 3746; X86-BMI1BMI2-NEXT: .LBB32_2: 3747; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 3748; X86-BMI1BMI2-NEXT: popl %esi 3749; X86-BMI1BMI2-NEXT: retl 3750; 3751; X64-NOBMI-LABEL: bextr64_32_b1: 3752; X64-NOBMI: # %bb.0: 3753; X64-NOBMI-NEXT: movq %rsi, %rcx 3754; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 3755; X64-NOBMI-NEXT: shrq %cl, %rdi 3756; X64-NOBMI-NEXT: movl $-1, %eax 3757; X64-NOBMI-NEXT: movl %edx, %ecx 3758; X64-NOBMI-NEXT: shll %cl, %eax 3759; X64-NOBMI-NEXT: notl %eax 3760; X64-NOBMI-NEXT: andl %edi, %eax 3761; X64-NOBMI-NEXT: retq 3762; 3763; X64-BMI1NOTBM-LABEL: bextr64_32_b1: 3764; X64-BMI1NOTBM: # %bb.0: 3765; X64-BMI1NOTBM-NEXT: shll $8, %edx 3766; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3767; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3768; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 3769; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 3770; X64-BMI1NOTBM-NEXT: retq 3771; 3772; X64-BMI1BMI2-LABEL: bextr64_32_b1: 3773; X64-BMI1BMI2: # %bb.0: 3774; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 3775; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 3776; X64-BMI1BMI2-NEXT: retq 3777 %shiftedval = lshr i64 %val, %numskipbits 3778 %truncshiftedval = trunc i64 %shiftedval to i32 3779 %widenumlowbits = zext i8 %numlowbits to i32 3780 %notmask = shl nsw i32 -1, %widenumlowbits 3781 %mask = xor i32 %notmask, -1 3782 %res = and i32 %truncshiftedval, %mask 3783 ret i32 %res 3784} 3785 3786; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit. 3787; Masking is 64-bit. Then truncation. 3788define i32 @bextr64_32_b2(i64 %val, i64 %numskipbits, i8 %numlowbits) nounwind { 3789; X86-NOBMI-LABEL: bextr64_32_b2: 3790; X86-NOBMI: # %bb.0: 3791; X86-NOBMI-NEXT: pushl %edi 3792; X86-NOBMI-NEXT: pushl %esi 3793; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 3794; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 3795; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 3796; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 3797; X86-NOBMI-NEXT: movl %edi, %esi 3798; X86-NOBMI-NEXT: shrl %cl, %esi 3799; X86-NOBMI-NEXT: shrdl %cl, %edi, %eax 3800; X86-NOBMI-NEXT: testb $32, %cl 3801; X86-NOBMI-NEXT: jne .LBB33_2 3802; X86-NOBMI-NEXT: # %bb.1: 3803; X86-NOBMI-NEXT: movl %eax, %esi 3804; X86-NOBMI-NEXT: .LBB33_2: 3805; X86-NOBMI-NEXT: movl $-1, %eax 3806; X86-NOBMI-NEXT: movl %edx, %ecx 3807; X86-NOBMI-NEXT: shll %cl, %eax 3808; X86-NOBMI-NEXT: notl %eax 3809; X86-NOBMI-NEXT: andl %esi, %eax 3810; X86-NOBMI-NEXT: popl %esi 3811; X86-NOBMI-NEXT: popl %edi 3812; X86-NOBMI-NEXT: retl 3813; 3814; X86-BMI1NOTBM-LABEL: bextr64_32_b2: 3815; X86-BMI1NOTBM: # %bb.0: 3816; X86-BMI1NOTBM-NEXT: pushl %edi 3817; X86-BMI1NOTBM-NEXT: pushl %esi 3818; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 3819; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 3820; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 3821; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 3822; X86-BMI1NOTBM-NEXT: movl %edi, %edx 3823; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 3824; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 3825; X86-BMI1NOTBM-NEXT: testb $32, %cl 3826; X86-BMI1NOTBM-NEXT: jne .LBB33_2 3827; X86-BMI1NOTBM-NEXT: # %bb.1: 3828; X86-BMI1NOTBM-NEXT: movl %esi, %edx 3829; X86-BMI1NOTBM-NEXT: .LBB33_2: 3830; X86-BMI1NOTBM-NEXT: shll $8, %eax 3831; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 3832; X86-BMI1NOTBM-NEXT: popl %esi 3833; X86-BMI1NOTBM-NEXT: popl %edi 3834; X86-BMI1NOTBM-NEXT: retl 3835; 3836; X86-BMI1BMI2-LABEL: bextr64_32_b2: 3837; X86-BMI1BMI2: # %bb.0: 3838; X86-BMI1BMI2-NEXT: pushl %esi 3839; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 3840; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3841; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3842; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 3843; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 3844; X86-BMI1BMI2-NEXT: testb $32, %cl 3845; X86-BMI1BMI2-NEXT: je .LBB33_2 3846; X86-BMI1BMI2-NEXT: # %bb.1: 3847; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 3848; X86-BMI1BMI2-NEXT: .LBB33_2: 3849; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 3850; X86-BMI1BMI2-NEXT: popl %esi 3851; X86-BMI1BMI2-NEXT: retl 3852; 3853; X64-NOBMI-LABEL: bextr64_32_b2: 3854; X64-NOBMI: # %bb.0: 3855; X64-NOBMI-NEXT: movq %rsi, %rcx 3856; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 3857; X64-NOBMI-NEXT: shrq %cl, %rdi 3858; X64-NOBMI-NEXT: movl $-1, %eax 3859; X64-NOBMI-NEXT: movl %edx, %ecx 3860; X64-NOBMI-NEXT: shll %cl, %eax 3861; X64-NOBMI-NEXT: notl %eax 3862; X64-NOBMI-NEXT: andl %edi, %eax 3863; X64-NOBMI-NEXT: retq 3864; 3865; X64-BMI1NOTBM-LABEL: bextr64_32_b2: 3866; X64-BMI1NOTBM: # %bb.0: 3867; X64-BMI1NOTBM-NEXT: shll $8, %edx 3868; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3869; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3870; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 3871; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 3872; X64-BMI1NOTBM-NEXT: retq 3873; 3874; X64-BMI1BMI2-LABEL: bextr64_32_b2: 3875; X64-BMI1BMI2: # %bb.0: 3876; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 3877; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 3878; X64-BMI1BMI2-NEXT: retq 3879 %shiftedval = lshr i64 %val, %numskipbits 3880 %widenumlowbits = zext i8 %numlowbits to i32 3881 %notmask = shl nsw i32 -1, %widenumlowbits 3882 %mask = xor i32 %notmask, -1 3883 %zextmask = zext i32 %mask to i64 3884 %wideres = and i64 %shiftedval, %zextmask 3885 %res = trunc i64 %wideres to i32 3886 ret i32 %res 3887} 3888 3889; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit. 3890; Masking is 64-bit. Then truncation. 3891define i32 @bextr64_32_b3(i64 %val, i64 %numskipbits, i8 %numlowbits) nounwind { 3892; X86-NOBMI-LABEL: bextr64_32_b3: 3893; X86-NOBMI: # %bb.0: 3894; X86-NOBMI-NEXT: pushl %edi 3895; X86-NOBMI-NEXT: pushl %esi 3896; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %dl 3897; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 3898; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 3899; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 3900; X86-NOBMI-NEXT: movl %edi, %eax 3901; X86-NOBMI-NEXT: shrl %cl, %eax 3902; X86-NOBMI-NEXT: shrdl %cl, %edi, %esi 3903; X86-NOBMI-NEXT: testb $32, %cl 3904; X86-NOBMI-NEXT: jne .LBB34_2 3905; X86-NOBMI-NEXT: # %bb.1: 3906; X86-NOBMI-NEXT: movl %esi, %eax 3907; X86-NOBMI-NEXT: .LBB34_2: 3908; X86-NOBMI-NEXT: movl $-1, %esi 3909; X86-NOBMI-NEXT: movl %edx, %ecx 3910; X86-NOBMI-NEXT: shll %cl, %esi 3911; X86-NOBMI-NEXT: xorl %ecx, %ecx 3912; X86-NOBMI-NEXT: testb $32, %dl 3913; X86-NOBMI-NEXT: jne .LBB34_4 3914; X86-NOBMI-NEXT: # %bb.3: 3915; X86-NOBMI-NEXT: movl %esi, %ecx 3916; X86-NOBMI-NEXT: .LBB34_4: 3917; X86-NOBMI-NEXT: notl %ecx 3918; X86-NOBMI-NEXT: andl %ecx, %eax 3919; X86-NOBMI-NEXT: popl %esi 3920; X86-NOBMI-NEXT: popl %edi 3921; X86-NOBMI-NEXT: retl 3922; 3923; X86-BMI1NOTBM-LABEL: bextr64_32_b3: 3924; X86-BMI1NOTBM: # %bb.0: 3925; X86-BMI1NOTBM-NEXT: pushl %edi 3926; X86-BMI1NOTBM-NEXT: pushl %esi 3927; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 3928; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 3929; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 3930; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 3931; X86-BMI1NOTBM-NEXT: movl %edi, %edx 3932; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 3933; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 3934; X86-BMI1NOTBM-NEXT: testb $32, %cl 3935; X86-BMI1NOTBM-NEXT: jne .LBB34_2 3936; X86-BMI1NOTBM-NEXT: # %bb.1: 3937; X86-BMI1NOTBM-NEXT: movl %esi, %edx 3938; X86-BMI1NOTBM-NEXT: .LBB34_2: 3939; X86-BMI1NOTBM-NEXT: movl $-1, %esi 3940; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 3941; X86-BMI1NOTBM-NEXT: shll %cl, %esi 3942; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 3943; X86-BMI1NOTBM-NEXT: testb $32, %al 3944; X86-BMI1NOTBM-NEXT: jne .LBB34_4 3945; X86-BMI1NOTBM-NEXT: # %bb.3: 3946; X86-BMI1NOTBM-NEXT: movl %esi, %ecx 3947; X86-BMI1NOTBM-NEXT: .LBB34_4: 3948; X86-BMI1NOTBM-NEXT: andnl %edx, %ecx, %eax 3949; X86-BMI1NOTBM-NEXT: popl %esi 3950; X86-BMI1NOTBM-NEXT: popl %edi 3951; X86-BMI1NOTBM-NEXT: retl 3952; 3953; X86-BMI1BMI2-LABEL: bextr64_32_b3: 3954; X86-BMI1BMI2: # %bb.0: 3955; X86-BMI1BMI2-NEXT: pushl %esi 3956; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 3957; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 3958; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 3959; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 3960; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 3961; X86-BMI1BMI2-NEXT: testb $32, %cl 3962; X86-BMI1BMI2-NEXT: je .LBB34_2 3963; X86-BMI1BMI2-NEXT: # %bb.1: 3964; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 3965; X86-BMI1BMI2-NEXT: .LBB34_2: 3966; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx 3967; X86-BMI1BMI2-NEXT: testb $32, %al 3968; X86-BMI1BMI2-NEXT: jne .LBB34_4 3969; X86-BMI1BMI2-NEXT: # %bb.3: 3970; X86-BMI1BMI2-NEXT: movl $-1, %ecx 3971; X86-BMI1BMI2-NEXT: shlxl %eax, %ecx, %ecx 3972; X86-BMI1BMI2-NEXT: .LBB34_4: 3973; X86-BMI1BMI2-NEXT: andnl %edx, %ecx, %eax 3974; X86-BMI1BMI2-NEXT: popl %esi 3975; X86-BMI1BMI2-NEXT: retl 3976; 3977; X64-NOBMI-LABEL: bextr64_32_b3: 3978; X64-NOBMI: # %bb.0: 3979; X64-NOBMI-NEXT: movq %rsi, %rcx 3980; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 3981; X64-NOBMI-NEXT: shrq %cl, %rdi 3982; X64-NOBMI-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF 3983; X64-NOBMI-NEXT: movl $4294967295, %esi # imm = 0xFFFFFFFF 3984; X64-NOBMI-NEXT: movl %edx, %ecx 3985; X64-NOBMI-NEXT: shlq %cl, %rsi 3986; X64-NOBMI-NEXT: xorl %esi, %eax 3987; X64-NOBMI-NEXT: andl %edi, %eax 3988; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 3989; X64-NOBMI-NEXT: retq 3990; 3991; X64-BMI1NOTBM-LABEL: bextr64_32_b3: 3992; X64-BMI1NOTBM: # %bb.0: 3993; X64-BMI1NOTBM-NEXT: shll $8, %edx 3994; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 3995; X64-BMI1NOTBM-NEXT: orl %edx, %eax 3996; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 3997; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 3998; X64-BMI1NOTBM-NEXT: retq 3999; 4000; X64-BMI1BMI2-LABEL: bextr64_32_b3: 4001; X64-BMI1BMI2: # %bb.0: 4002; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 4003; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 4004; X64-BMI1BMI2-NEXT: retq 4005 %shiftedval = lshr i64 %val, %numskipbits 4006 %widenumlowbits = zext i8 %numlowbits to i64 4007 %notmask = shl nsw i64 4294967295, %widenumlowbits 4008 %mask = xor i64 %notmask, 4294967295 4009 %wideres = and i64 %shiftedval, %mask 4010 %res = trunc i64 %wideres to i32 4011 ret i32 %res 4012} 4013 4014; ---------------------------------------------------------------------------- ; 4015; Pattern c. 32-bit 4016; ---------------------------------------------------------------------------- ; 4017 4018define i32 @bextr32_c0(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 4019; X86-NOBMI-LABEL: bextr32_c0: 4020; X86-NOBMI: # %bb.0: 4021; X86-NOBMI-NEXT: pushl %edi 4022; X86-NOBMI-NEXT: pushl %esi 4023; X86-NOBMI-NEXT: pushl %eax 4024; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 4025; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 4026; X86-NOBMI-NEXT: shrl %cl, %edi 4027; X86-NOBMI-NEXT: xorl %ecx, %ecx 4028; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4029; X86-NOBMI-NEXT: movl $-1, %esi 4030; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4031; X86-NOBMI-NEXT: shrl %cl, %esi 4032; X86-NOBMI-NEXT: movl %esi, (%esp) 4033; X86-NOBMI-NEXT: calll use32 4034; X86-NOBMI-NEXT: andl %edi, %esi 4035; X86-NOBMI-NEXT: movl %esi, %eax 4036; X86-NOBMI-NEXT: addl $4, %esp 4037; X86-NOBMI-NEXT: popl %esi 4038; X86-NOBMI-NEXT: popl %edi 4039; X86-NOBMI-NEXT: retl 4040; 4041; X86-BMI1NOTBM-LABEL: bextr32_c0: 4042; X86-BMI1NOTBM: # %bb.0: 4043; X86-BMI1NOTBM-NEXT: pushl %edi 4044; X86-BMI1NOTBM-NEXT: pushl %esi 4045; X86-BMI1NOTBM-NEXT: pushl %eax 4046; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 4047; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 4048; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4049; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 4050; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4051; X86-BMI1NOTBM-NEXT: movl $-1, %esi 4052; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4053; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 4054; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 4055; X86-BMI1NOTBM-NEXT: calll use32 4056; X86-BMI1NOTBM-NEXT: andl %edi, %esi 4057; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4058; X86-BMI1NOTBM-NEXT: addl $4, %esp 4059; X86-BMI1NOTBM-NEXT: popl %esi 4060; X86-BMI1NOTBM-NEXT: popl %edi 4061; X86-BMI1NOTBM-NEXT: retl 4062; 4063; X86-BMI1BMI2-LABEL: bextr32_c0: 4064; X86-BMI1BMI2: # %bb.0: 4065; X86-BMI1BMI2-NEXT: pushl %ebx 4066; X86-BMI1BMI2-NEXT: pushl %esi 4067; X86-BMI1BMI2-NEXT: pushl %eax 4068; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 4069; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 4070; X86-BMI1BMI2-NEXT: shrxl %eax, {{[0-9]+}}(%esp), %esi 4071; X86-BMI1BMI2-NEXT: movl %ebx, %eax 4072; X86-BMI1BMI2-NEXT: negb %al 4073; X86-BMI1BMI2-NEXT: movl $-1, %ecx 4074; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax 4075; X86-BMI1BMI2-NEXT: movl %eax, (%esp) 4076; X86-BMI1BMI2-NEXT: calll use32 4077; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax 4078; X86-BMI1BMI2-NEXT: addl $4, %esp 4079; X86-BMI1BMI2-NEXT: popl %esi 4080; X86-BMI1BMI2-NEXT: popl %ebx 4081; X86-BMI1BMI2-NEXT: retl 4082; 4083; X64-NOBMI-LABEL: bextr32_c0: 4084; X64-NOBMI: # %bb.0: 4085; X64-NOBMI-NEXT: pushq %rbp 4086; X64-NOBMI-NEXT: pushq %rbx 4087; X64-NOBMI-NEXT: pushq %rax 4088; X64-NOBMI-NEXT: movl %esi, %ecx 4089; X64-NOBMI-NEXT: movl %edi, %ebx 4090; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4091; X64-NOBMI-NEXT: shrl %cl, %ebx 4092; X64-NOBMI-NEXT: negb %dl 4093; X64-NOBMI-NEXT: movl $-1, %ebp 4094; X64-NOBMI-NEXT: movl %edx, %ecx 4095; X64-NOBMI-NEXT: shrl %cl, %ebp 4096; X64-NOBMI-NEXT: movl %ebp, %edi 4097; X64-NOBMI-NEXT: callq use32 4098; X64-NOBMI-NEXT: andl %ebx, %ebp 4099; X64-NOBMI-NEXT: movl %ebp, %eax 4100; X64-NOBMI-NEXT: addq $8, %rsp 4101; X64-NOBMI-NEXT: popq %rbx 4102; X64-NOBMI-NEXT: popq %rbp 4103; X64-NOBMI-NEXT: retq 4104; 4105; X64-BMI1NOTBM-LABEL: bextr32_c0: 4106; X64-BMI1NOTBM: # %bb.0: 4107; X64-BMI1NOTBM-NEXT: pushq %rbp 4108; X64-BMI1NOTBM-NEXT: pushq %rbx 4109; X64-BMI1NOTBM-NEXT: pushq %rax 4110; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 4111; X64-BMI1NOTBM-NEXT: movl %edi, %ebx 4112; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4113; X64-BMI1NOTBM-NEXT: shrl %cl, %ebx 4114; X64-BMI1NOTBM-NEXT: negb %dl 4115; X64-BMI1NOTBM-NEXT: movl $-1, %ebp 4116; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 4117; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp 4118; X64-BMI1NOTBM-NEXT: movl %ebp, %edi 4119; X64-BMI1NOTBM-NEXT: callq use32 4120; X64-BMI1NOTBM-NEXT: andl %ebx, %ebp 4121; X64-BMI1NOTBM-NEXT: movl %ebp, %eax 4122; X64-BMI1NOTBM-NEXT: addq $8, %rsp 4123; X64-BMI1NOTBM-NEXT: popq %rbx 4124; X64-BMI1NOTBM-NEXT: popq %rbp 4125; X64-BMI1NOTBM-NEXT: retq 4126; 4127; X64-BMI1BMI2-LABEL: bextr32_c0: 4128; X64-BMI1BMI2: # %bb.0: 4129; X64-BMI1BMI2-NEXT: pushq %rbp 4130; X64-BMI1BMI2-NEXT: pushq %rbx 4131; X64-BMI1BMI2-NEXT: pushq %rax 4132; X64-BMI1BMI2-NEXT: movl %edx, %ebx 4133; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %ebp 4134; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4135; X64-BMI1BMI2-NEXT: negb %al 4136; X64-BMI1BMI2-NEXT: movl $-1, %ecx 4137; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi 4138; X64-BMI1BMI2-NEXT: callq use32 4139; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax 4140; X64-BMI1BMI2-NEXT: addq $8, %rsp 4141; X64-BMI1BMI2-NEXT: popq %rbx 4142; X64-BMI1BMI2-NEXT: popq %rbp 4143; X64-BMI1BMI2-NEXT: retq 4144 %shifted = lshr i32 %val, %numskipbits 4145 %numhighbits = sub i32 32, %numlowbits 4146 %mask = lshr i32 -1, %numhighbits 4147 call void @use32(i32 %mask) 4148 %masked = and i32 %mask, %shifted 4149 ret i32 %masked 4150} 4151 4152define i32 @bextr32_c1_indexzext(i32 %val, i8 %numskipbits, i8 %numlowbits) nounwind { 4153; X86-NOBMI-LABEL: bextr32_c1_indexzext: 4154; X86-NOBMI: # %bb.0: 4155; X86-NOBMI-NEXT: pushl %edi 4156; X86-NOBMI-NEXT: pushl %esi 4157; X86-NOBMI-NEXT: pushl %eax 4158; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 4159; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 4160; X86-NOBMI-NEXT: shrl %cl, %edi 4161; X86-NOBMI-NEXT: xorl %ecx, %ecx 4162; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4163; X86-NOBMI-NEXT: movl $-1, %esi 4164; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4165; X86-NOBMI-NEXT: shrl %cl, %esi 4166; X86-NOBMI-NEXT: movl %esi, (%esp) 4167; X86-NOBMI-NEXT: calll use32 4168; X86-NOBMI-NEXT: andl %edi, %esi 4169; X86-NOBMI-NEXT: movl %esi, %eax 4170; X86-NOBMI-NEXT: addl $4, %esp 4171; X86-NOBMI-NEXT: popl %esi 4172; X86-NOBMI-NEXT: popl %edi 4173; X86-NOBMI-NEXT: retl 4174; 4175; X86-BMI1NOTBM-LABEL: bextr32_c1_indexzext: 4176; X86-BMI1NOTBM: # %bb.0: 4177; X86-BMI1NOTBM-NEXT: pushl %edi 4178; X86-BMI1NOTBM-NEXT: pushl %esi 4179; X86-BMI1NOTBM-NEXT: pushl %eax 4180; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 4181; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 4182; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4183; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 4184; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4185; X86-BMI1NOTBM-NEXT: movl $-1, %esi 4186; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4187; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 4188; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 4189; X86-BMI1NOTBM-NEXT: calll use32 4190; X86-BMI1NOTBM-NEXT: andl %edi, %esi 4191; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4192; X86-BMI1NOTBM-NEXT: addl $4, %esp 4193; X86-BMI1NOTBM-NEXT: popl %esi 4194; X86-BMI1NOTBM-NEXT: popl %edi 4195; X86-BMI1NOTBM-NEXT: retl 4196; 4197; X86-BMI1BMI2-LABEL: bextr32_c1_indexzext: 4198; X86-BMI1BMI2: # %bb.0: 4199; X86-BMI1BMI2-NEXT: pushl %ebx 4200; X86-BMI1BMI2-NEXT: pushl %esi 4201; X86-BMI1BMI2-NEXT: pushl %eax 4202; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 4203; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 4204; X86-BMI1BMI2-NEXT: shrxl %eax, {{[0-9]+}}(%esp), %esi 4205; X86-BMI1BMI2-NEXT: movl %ebx, %eax 4206; X86-BMI1BMI2-NEXT: negb %al 4207; X86-BMI1BMI2-NEXT: movl $-1, %ecx 4208; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax 4209; X86-BMI1BMI2-NEXT: movl %eax, (%esp) 4210; X86-BMI1BMI2-NEXT: calll use32 4211; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax 4212; X86-BMI1BMI2-NEXT: addl $4, %esp 4213; X86-BMI1BMI2-NEXT: popl %esi 4214; X86-BMI1BMI2-NEXT: popl %ebx 4215; X86-BMI1BMI2-NEXT: retl 4216; 4217; X64-NOBMI-LABEL: bextr32_c1_indexzext: 4218; X64-NOBMI: # %bb.0: 4219; X64-NOBMI-NEXT: pushq %rbp 4220; X64-NOBMI-NEXT: pushq %rbx 4221; X64-NOBMI-NEXT: pushq %rax 4222; X64-NOBMI-NEXT: movl %esi, %ecx 4223; X64-NOBMI-NEXT: movl %edi, %ebx 4224; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4225; X64-NOBMI-NEXT: shrl %cl, %ebx 4226; X64-NOBMI-NEXT: negb %dl 4227; X64-NOBMI-NEXT: movl $-1, %ebp 4228; X64-NOBMI-NEXT: movl %edx, %ecx 4229; X64-NOBMI-NEXT: shrl %cl, %ebp 4230; X64-NOBMI-NEXT: movl %ebp, %edi 4231; X64-NOBMI-NEXT: callq use32 4232; X64-NOBMI-NEXT: andl %ebx, %ebp 4233; X64-NOBMI-NEXT: movl %ebp, %eax 4234; X64-NOBMI-NEXT: addq $8, %rsp 4235; X64-NOBMI-NEXT: popq %rbx 4236; X64-NOBMI-NEXT: popq %rbp 4237; X64-NOBMI-NEXT: retq 4238; 4239; X64-BMI1NOTBM-LABEL: bextr32_c1_indexzext: 4240; X64-BMI1NOTBM: # %bb.0: 4241; X64-BMI1NOTBM-NEXT: pushq %rbp 4242; X64-BMI1NOTBM-NEXT: pushq %rbx 4243; X64-BMI1NOTBM-NEXT: pushq %rax 4244; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 4245; X64-BMI1NOTBM-NEXT: movl %edi, %ebx 4246; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4247; X64-BMI1NOTBM-NEXT: shrl %cl, %ebx 4248; X64-BMI1NOTBM-NEXT: negb %dl 4249; X64-BMI1NOTBM-NEXT: movl $-1, %ebp 4250; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 4251; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp 4252; X64-BMI1NOTBM-NEXT: movl %ebp, %edi 4253; X64-BMI1NOTBM-NEXT: callq use32 4254; X64-BMI1NOTBM-NEXT: andl %ebx, %ebp 4255; X64-BMI1NOTBM-NEXT: movl %ebp, %eax 4256; X64-BMI1NOTBM-NEXT: addq $8, %rsp 4257; X64-BMI1NOTBM-NEXT: popq %rbx 4258; X64-BMI1NOTBM-NEXT: popq %rbp 4259; X64-BMI1NOTBM-NEXT: retq 4260; 4261; X64-BMI1BMI2-LABEL: bextr32_c1_indexzext: 4262; X64-BMI1BMI2: # %bb.0: 4263; X64-BMI1BMI2-NEXT: pushq %rbp 4264; X64-BMI1BMI2-NEXT: pushq %rbx 4265; X64-BMI1BMI2-NEXT: pushq %rax 4266; X64-BMI1BMI2-NEXT: movl %edx, %ebx 4267; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %ebp 4268; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4269; X64-BMI1BMI2-NEXT: negb %al 4270; X64-BMI1BMI2-NEXT: movl $-1, %ecx 4271; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi 4272; X64-BMI1BMI2-NEXT: callq use32 4273; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax 4274; X64-BMI1BMI2-NEXT: addq $8, %rsp 4275; X64-BMI1BMI2-NEXT: popq %rbx 4276; X64-BMI1BMI2-NEXT: popq %rbp 4277; X64-BMI1BMI2-NEXT: retq 4278 %skip = zext i8 %numskipbits to i32 4279 %shifted = lshr i32 %val, %skip 4280 %numhighbits = sub i8 32, %numlowbits 4281 %sh_prom = zext i8 %numhighbits to i32 4282 %mask = lshr i32 -1, %sh_prom 4283 call void @use32(i32 %mask) 4284 %masked = and i32 %mask, %shifted 4285 ret i32 %masked 4286} 4287 4288define i32 @bextr32_c2_load(i32* %w, i32 %numskipbits, i32 %numlowbits) nounwind { 4289; X86-NOBMI-LABEL: bextr32_c2_load: 4290; X86-NOBMI: # %bb.0: 4291; X86-NOBMI-NEXT: pushl %edi 4292; X86-NOBMI-NEXT: pushl %esi 4293; X86-NOBMI-NEXT: pushl %eax 4294; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 4295; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 4296; X86-NOBMI-NEXT: movl (%eax), %edi 4297; X86-NOBMI-NEXT: shrl %cl, %edi 4298; X86-NOBMI-NEXT: xorl %ecx, %ecx 4299; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4300; X86-NOBMI-NEXT: movl $-1, %esi 4301; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4302; X86-NOBMI-NEXT: shrl %cl, %esi 4303; X86-NOBMI-NEXT: movl %esi, (%esp) 4304; X86-NOBMI-NEXT: calll use32 4305; X86-NOBMI-NEXT: andl %edi, %esi 4306; X86-NOBMI-NEXT: movl %esi, %eax 4307; X86-NOBMI-NEXT: addl $4, %esp 4308; X86-NOBMI-NEXT: popl %esi 4309; X86-NOBMI-NEXT: popl %edi 4310; X86-NOBMI-NEXT: retl 4311; 4312; X86-BMI1NOTBM-LABEL: bextr32_c2_load: 4313; X86-BMI1NOTBM: # %bb.0: 4314; X86-BMI1NOTBM-NEXT: pushl %edi 4315; X86-BMI1NOTBM-NEXT: pushl %esi 4316; X86-BMI1NOTBM-NEXT: pushl %eax 4317; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 4318; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 4319; X86-BMI1NOTBM-NEXT: movl (%eax), %edi 4320; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4321; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 4322; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4323; X86-BMI1NOTBM-NEXT: movl $-1, %esi 4324; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4325; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 4326; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 4327; X86-BMI1NOTBM-NEXT: calll use32 4328; X86-BMI1NOTBM-NEXT: andl %edi, %esi 4329; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4330; X86-BMI1NOTBM-NEXT: addl $4, %esp 4331; X86-BMI1NOTBM-NEXT: popl %esi 4332; X86-BMI1NOTBM-NEXT: popl %edi 4333; X86-BMI1NOTBM-NEXT: retl 4334; 4335; X86-BMI1BMI2-LABEL: bextr32_c2_load: 4336; X86-BMI1BMI2: # %bb.0: 4337; X86-BMI1BMI2-NEXT: pushl %ebx 4338; X86-BMI1BMI2-NEXT: pushl %esi 4339; X86-BMI1BMI2-NEXT: pushl %eax 4340; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 4341; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 4342; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 4343; X86-BMI1BMI2-NEXT: shrxl %ecx, (%eax), %esi 4344; X86-BMI1BMI2-NEXT: movl %ebx, %eax 4345; X86-BMI1BMI2-NEXT: negb %al 4346; X86-BMI1BMI2-NEXT: movl $-1, %ecx 4347; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax 4348; X86-BMI1BMI2-NEXT: movl %eax, (%esp) 4349; X86-BMI1BMI2-NEXT: calll use32 4350; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax 4351; X86-BMI1BMI2-NEXT: addl $4, %esp 4352; X86-BMI1BMI2-NEXT: popl %esi 4353; X86-BMI1BMI2-NEXT: popl %ebx 4354; X86-BMI1BMI2-NEXT: retl 4355; 4356; X64-NOBMI-LABEL: bextr32_c2_load: 4357; X64-NOBMI: # %bb.0: 4358; X64-NOBMI-NEXT: pushq %rbp 4359; X64-NOBMI-NEXT: pushq %rbx 4360; X64-NOBMI-NEXT: pushq %rax 4361; X64-NOBMI-NEXT: movl %esi, %ecx 4362; X64-NOBMI-NEXT: movl (%rdi), %ebp 4363; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4364; X64-NOBMI-NEXT: shrl %cl, %ebp 4365; X64-NOBMI-NEXT: negb %dl 4366; X64-NOBMI-NEXT: movl $-1, %ebx 4367; X64-NOBMI-NEXT: movl %edx, %ecx 4368; X64-NOBMI-NEXT: shrl %cl, %ebx 4369; X64-NOBMI-NEXT: movl %ebx, %edi 4370; X64-NOBMI-NEXT: callq use32 4371; X64-NOBMI-NEXT: andl %ebp, %ebx 4372; X64-NOBMI-NEXT: movl %ebx, %eax 4373; X64-NOBMI-NEXT: addq $8, %rsp 4374; X64-NOBMI-NEXT: popq %rbx 4375; X64-NOBMI-NEXT: popq %rbp 4376; X64-NOBMI-NEXT: retq 4377; 4378; X64-BMI1NOTBM-LABEL: bextr32_c2_load: 4379; X64-BMI1NOTBM: # %bb.0: 4380; X64-BMI1NOTBM-NEXT: pushq %rbp 4381; X64-BMI1NOTBM-NEXT: pushq %rbx 4382; X64-BMI1NOTBM-NEXT: pushq %rax 4383; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 4384; X64-BMI1NOTBM-NEXT: movl (%rdi), %ebp 4385; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4386; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp 4387; X64-BMI1NOTBM-NEXT: negb %dl 4388; X64-BMI1NOTBM-NEXT: movl $-1, %ebx 4389; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 4390; X64-BMI1NOTBM-NEXT: shrl %cl, %ebx 4391; X64-BMI1NOTBM-NEXT: movl %ebx, %edi 4392; X64-BMI1NOTBM-NEXT: callq use32 4393; X64-BMI1NOTBM-NEXT: andl %ebp, %ebx 4394; X64-BMI1NOTBM-NEXT: movl %ebx, %eax 4395; X64-BMI1NOTBM-NEXT: addq $8, %rsp 4396; X64-BMI1NOTBM-NEXT: popq %rbx 4397; X64-BMI1NOTBM-NEXT: popq %rbp 4398; X64-BMI1NOTBM-NEXT: retq 4399; 4400; X64-BMI1BMI2-LABEL: bextr32_c2_load: 4401; X64-BMI1BMI2: # %bb.0: 4402; X64-BMI1BMI2-NEXT: pushq %rbp 4403; X64-BMI1BMI2-NEXT: pushq %rbx 4404; X64-BMI1BMI2-NEXT: pushq %rax 4405; X64-BMI1BMI2-NEXT: movl %edx, %ebx 4406; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %ebp 4407; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4408; X64-BMI1BMI2-NEXT: negb %al 4409; X64-BMI1BMI2-NEXT: movl $-1, %ecx 4410; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi 4411; X64-BMI1BMI2-NEXT: callq use32 4412; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax 4413; X64-BMI1BMI2-NEXT: addq $8, %rsp 4414; X64-BMI1BMI2-NEXT: popq %rbx 4415; X64-BMI1BMI2-NEXT: popq %rbp 4416; X64-BMI1BMI2-NEXT: retq 4417 %val = load i32, i32* %w 4418 %shifted = lshr i32 %val, %numskipbits 4419 %numhighbits = sub i32 32, %numlowbits 4420 %mask = lshr i32 -1, %numhighbits 4421 call void @use32(i32 %mask) 4422 %masked = and i32 %mask, %shifted 4423 ret i32 %masked 4424} 4425 4426define i32 @bextr32_c3_load_indexzext(i32* %w, i8 %numskipbits, i8 %numlowbits) nounwind { 4427; X86-NOBMI-LABEL: bextr32_c3_load_indexzext: 4428; X86-NOBMI: # %bb.0: 4429; X86-NOBMI-NEXT: pushl %edi 4430; X86-NOBMI-NEXT: pushl %esi 4431; X86-NOBMI-NEXT: pushl %eax 4432; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 4433; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 4434; X86-NOBMI-NEXT: movl (%eax), %edi 4435; X86-NOBMI-NEXT: shrl %cl, %edi 4436; X86-NOBMI-NEXT: xorl %ecx, %ecx 4437; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4438; X86-NOBMI-NEXT: movl $-1, %esi 4439; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4440; X86-NOBMI-NEXT: shrl %cl, %esi 4441; X86-NOBMI-NEXT: movl %esi, (%esp) 4442; X86-NOBMI-NEXT: calll use32 4443; X86-NOBMI-NEXT: andl %edi, %esi 4444; X86-NOBMI-NEXT: movl %esi, %eax 4445; X86-NOBMI-NEXT: addl $4, %esp 4446; X86-NOBMI-NEXT: popl %esi 4447; X86-NOBMI-NEXT: popl %edi 4448; X86-NOBMI-NEXT: retl 4449; 4450; X86-BMI1NOTBM-LABEL: bextr32_c3_load_indexzext: 4451; X86-BMI1NOTBM: # %bb.0: 4452; X86-BMI1NOTBM-NEXT: pushl %edi 4453; X86-BMI1NOTBM-NEXT: pushl %esi 4454; X86-BMI1NOTBM-NEXT: pushl %eax 4455; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 4456; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 4457; X86-BMI1NOTBM-NEXT: movl (%eax), %edi 4458; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4459; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 4460; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4461; X86-BMI1NOTBM-NEXT: movl $-1, %esi 4462; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4463; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 4464; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 4465; X86-BMI1NOTBM-NEXT: calll use32 4466; X86-BMI1NOTBM-NEXT: andl %edi, %esi 4467; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4468; X86-BMI1NOTBM-NEXT: addl $4, %esp 4469; X86-BMI1NOTBM-NEXT: popl %esi 4470; X86-BMI1NOTBM-NEXT: popl %edi 4471; X86-BMI1NOTBM-NEXT: retl 4472; 4473; X86-BMI1BMI2-LABEL: bextr32_c3_load_indexzext: 4474; X86-BMI1BMI2: # %bb.0: 4475; X86-BMI1BMI2-NEXT: pushl %ebx 4476; X86-BMI1BMI2-NEXT: pushl %esi 4477; X86-BMI1BMI2-NEXT: pushl %eax 4478; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 4479; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 4480; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 4481; X86-BMI1BMI2-NEXT: shrxl %ecx, (%eax), %esi 4482; X86-BMI1BMI2-NEXT: movl %ebx, %eax 4483; X86-BMI1BMI2-NEXT: negb %al 4484; X86-BMI1BMI2-NEXT: movl $-1, %ecx 4485; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax 4486; X86-BMI1BMI2-NEXT: movl %eax, (%esp) 4487; X86-BMI1BMI2-NEXT: calll use32 4488; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax 4489; X86-BMI1BMI2-NEXT: addl $4, %esp 4490; X86-BMI1BMI2-NEXT: popl %esi 4491; X86-BMI1BMI2-NEXT: popl %ebx 4492; X86-BMI1BMI2-NEXT: retl 4493; 4494; X64-NOBMI-LABEL: bextr32_c3_load_indexzext: 4495; X64-NOBMI: # %bb.0: 4496; X64-NOBMI-NEXT: pushq %rbp 4497; X64-NOBMI-NEXT: pushq %rbx 4498; X64-NOBMI-NEXT: pushq %rax 4499; X64-NOBMI-NEXT: movl %esi, %ecx 4500; X64-NOBMI-NEXT: movl (%rdi), %ebp 4501; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4502; X64-NOBMI-NEXT: shrl %cl, %ebp 4503; X64-NOBMI-NEXT: negb %dl 4504; X64-NOBMI-NEXT: movl $-1, %ebx 4505; X64-NOBMI-NEXT: movl %edx, %ecx 4506; X64-NOBMI-NEXT: shrl %cl, %ebx 4507; X64-NOBMI-NEXT: movl %ebx, %edi 4508; X64-NOBMI-NEXT: callq use32 4509; X64-NOBMI-NEXT: andl %ebp, %ebx 4510; X64-NOBMI-NEXT: movl %ebx, %eax 4511; X64-NOBMI-NEXT: addq $8, %rsp 4512; X64-NOBMI-NEXT: popq %rbx 4513; X64-NOBMI-NEXT: popq %rbp 4514; X64-NOBMI-NEXT: retq 4515; 4516; X64-BMI1NOTBM-LABEL: bextr32_c3_load_indexzext: 4517; X64-BMI1NOTBM: # %bb.0: 4518; X64-BMI1NOTBM-NEXT: pushq %rbp 4519; X64-BMI1NOTBM-NEXT: pushq %rbx 4520; X64-BMI1NOTBM-NEXT: pushq %rax 4521; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 4522; X64-BMI1NOTBM-NEXT: movl (%rdi), %ebp 4523; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4524; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp 4525; X64-BMI1NOTBM-NEXT: negb %dl 4526; X64-BMI1NOTBM-NEXT: movl $-1, %ebx 4527; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 4528; X64-BMI1NOTBM-NEXT: shrl %cl, %ebx 4529; X64-BMI1NOTBM-NEXT: movl %ebx, %edi 4530; X64-BMI1NOTBM-NEXT: callq use32 4531; X64-BMI1NOTBM-NEXT: andl %ebp, %ebx 4532; X64-BMI1NOTBM-NEXT: movl %ebx, %eax 4533; X64-BMI1NOTBM-NEXT: addq $8, %rsp 4534; X64-BMI1NOTBM-NEXT: popq %rbx 4535; X64-BMI1NOTBM-NEXT: popq %rbp 4536; X64-BMI1NOTBM-NEXT: retq 4537; 4538; X64-BMI1BMI2-LABEL: bextr32_c3_load_indexzext: 4539; X64-BMI1BMI2: # %bb.0: 4540; X64-BMI1BMI2-NEXT: pushq %rbp 4541; X64-BMI1BMI2-NEXT: pushq %rbx 4542; X64-BMI1BMI2-NEXT: pushq %rax 4543; X64-BMI1BMI2-NEXT: movl %edx, %ebx 4544; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %ebp 4545; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4546; X64-BMI1BMI2-NEXT: negb %al 4547; X64-BMI1BMI2-NEXT: movl $-1, %ecx 4548; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi 4549; X64-BMI1BMI2-NEXT: callq use32 4550; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax 4551; X64-BMI1BMI2-NEXT: addq $8, %rsp 4552; X64-BMI1BMI2-NEXT: popq %rbx 4553; X64-BMI1BMI2-NEXT: popq %rbp 4554; X64-BMI1BMI2-NEXT: retq 4555 %val = load i32, i32* %w 4556 %skip = zext i8 %numskipbits to i32 4557 %shifted = lshr i32 %val, %skip 4558 %numhighbits = sub i8 32, %numlowbits 4559 %sh_prom = zext i8 %numhighbits to i32 4560 %mask = lshr i32 -1, %sh_prom 4561 call void @use32(i32 %mask) 4562 %masked = and i32 %mask, %shifted 4563 ret i32 %masked 4564} 4565 4566define i32 @bextr32_c4_commutative(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 4567; X86-NOBMI-LABEL: bextr32_c4_commutative: 4568; X86-NOBMI: # %bb.0: 4569; X86-NOBMI-NEXT: pushl %edi 4570; X86-NOBMI-NEXT: pushl %esi 4571; X86-NOBMI-NEXT: pushl %eax 4572; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 4573; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 4574; X86-NOBMI-NEXT: shrl %cl, %edi 4575; X86-NOBMI-NEXT: xorl %ecx, %ecx 4576; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4577; X86-NOBMI-NEXT: movl $-1, %esi 4578; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4579; X86-NOBMI-NEXT: shrl %cl, %esi 4580; X86-NOBMI-NEXT: movl %esi, (%esp) 4581; X86-NOBMI-NEXT: calll use32 4582; X86-NOBMI-NEXT: andl %edi, %esi 4583; X86-NOBMI-NEXT: movl %esi, %eax 4584; X86-NOBMI-NEXT: addl $4, %esp 4585; X86-NOBMI-NEXT: popl %esi 4586; X86-NOBMI-NEXT: popl %edi 4587; X86-NOBMI-NEXT: retl 4588; 4589; X86-BMI1NOTBM-LABEL: bextr32_c4_commutative: 4590; X86-BMI1NOTBM: # %bb.0: 4591; X86-BMI1NOTBM-NEXT: pushl %edi 4592; X86-BMI1NOTBM-NEXT: pushl %esi 4593; X86-BMI1NOTBM-NEXT: pushl %eax 4594; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 4595; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 4596; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4597; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 4598; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4599; X86-BMI1NOTBM-NEXT: movl $-1, %esi 4600; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4601; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 4602; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 4603; X86-BMI1NOTBM-NEXT: calll use32 4604; X86-BMI1NOTBM-NEXT: andl %edi, %esi 4605; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4606; X86-BMI1NOTBM-NEXT: addl $4, %esp 4607; X86-BMI1NOTBM-NEXT: popl %esi 4608; X86-BMI1NOTBM-NEXT: popl %edi 4609; X86-BMI1NOTBM-NEXT: retl 4610; 4611; X86-BMI1BMI2-LABEL: bextr32_c4_commutative: 4612; X86-BMI1BMI2: # %bb.0: 4613; X86-BMI1BMI2-NEXT: pushl %ebx 4614; X86-BMI1BMI2-NEXT: pushl %esi 4615; X86-BMI1BMI2-NEXT: pushl %eax 4616; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 4617; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 4618; X86-BMI1BMI2-NEXT: shrxl %eax, {{[0-9]+}}(%esp), %esi 4619; X86-BMI1BMI2-NEXT: movl %ebx, %eax 4620; X86-BMI1BMI2-NEXT: negb %al 4621; X86-BMI1BMI2-NEXT: movl $-1, %ecx 4622; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax 4623; X86-BMI1BMI2-NEXT: movl %eax, (%esp) 4624; X86-BMI1BMI2-NEXT: calll use32 4625; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax 4626; X86-BMI1BMI2-NEXT: addl $4, %esp 4627; X86-BMI1BMI2-NEXT: popl %esi 4628; X86-BMI1BMI2-NEXT: popl %ebx 4629; X86-BMI1BMI2-NEXT: retl 4630; 4631; X64-NOBMI-LABEL: bextr32_c4_commutative: 4632; X64-NOBMI: # %bb.0: 4633; X64-NOBMI-NEXT: pushq %rbp 4634; X64-NOBMI-NEXT: pushq %rbx 4635; X64-NOBMI-NEXT: pushq %rax 4636; X64-NOBMI-NEXT: movl %esi, %ecx 4637; X64-NOBMI-NEXT: movl %edi, %ebx 4638; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4639; X64-NOBMI-NEXT: shrl %cl, %ebx 4640; X64-NOBMI-NEXT: negb %dl 4641; X64-NOBMI-NEXT: movl $-1, %ebp 4642; X64-NOBMI-NEXT: movl %edx, %ecx 4643; X64-NOBMI-NEXT: shrl %cl, %ebp 4644; X64-NOBMI-NEXT: movl %ebp, %edi 4645; X64-NOBMI-NEXT: callq use32 4646; X64-NOBMI-NEXT: andl %ebx, %ebp 4647; X64-NOBMI-NEXT: movl %ebp, %eax 4648; X64-NOBMI-NEXT: addq $8, %rsp 4649; X64-NOBMI-NEXT: popq %rbx 4650; X64-NOBMI-NEXT: popq %rbp 4651; X64-NOBMI-NEXT: retq 4652; 4653; X64-BMI1NOTBM-LABEL: bextr32_c4_commutative: 4654; X64-BMI1NOTBM: # %bb.0: 4655; X64-BMI1NOTBM-NEXT: pushq %rbp 4656; X64-BMI1NOTBM-NEXT: pushq %rbx 4657; X64-BMI1NOTBM-NEXT: pushq %rax 4658; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 4659; X64-BMI1NOTBM-NEXT: movl %edi, %ebx 4660; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4661; X64-BMI1NOTBM-NEXT: shrl %cl, %ebx 4662; X64-BMI1NOTBM-NEXT: negb %dl 4663; X64-BMI1NOTBM-NEXT: movl $-1, %ebp 4664; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 4665; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp 4666; X64-BMI1NOTBM-NEXT: movl %ebp, %edi 4667; X64-BMI1NOTBM-NEXT: callq use32 4668; X64-BMI1NOTBM-NEXT: andl %ebx, %ebp 4669; X64-BMI1NOTBM-NEXT: movl %ebp, %eax 4670; X64-BMI1NOTBM-NEXT: addq $8, %rsp 4671; X64-BMI1NOTBM-NEXT: popq %rbx 4672; X64-BMI1NOTBM-NEXT: popq %rbp 4673; X64-BMI1NOTBM-NEXT: retq 4674; 4675; X64-BMI1BMI2-LABEL: bextr32_c4_commutative: 4676; X64-BMI1BMI2: # %bb.0: 4677; X64-BMI1BMI2-NEXT: pushq %rbp 4678; X64-BMI1BMI2-NEXT: pushq %rbx 4679; X64-BMI1BMI2-NEXT: pushq %rax 4680; X64-BMI1BMI2-NEXT: movl %edx, %ebx 4681; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %ebp 4682; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4683; X64-BMI1BMI2-NEXT: negb %al 4684; X64-BMI1BMI2-NEXT: movl $-1, %ecx 4685; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi 4686; X64-BMI1BMI2-NEXT: callq use32 4687; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax 4688; X64-BMI1BMI2-NEXT: addq $8, %rsp 4689; X64-BMI1BMI2-NEXT: popq %rbx 4690; X64-BMI1BMI2-NEXT: popq %rbp 4691; X64-BMI1BMI2-NEXT: retq 4692 %shifted = lshr i32 %val, %numskipbits 4693 %numhighbits = sub i32 32, %numlowbits 4694 %mask = lshr i32 -1, %numhighbits 4695 call void @use32(i32 %mask) 4696 %masked = and i32 %shifted, %mask ; swapped order 4697 ret i32 %masked 4698} 4699 4700define i32 @bextr32_c5_skipextrauses(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 4701; X86-NOBMI-LABEL: bextr32_c5_skipextrauses: 4702; X86-NOBMI: # %bb.0: 4703; X86-NOBMI-NEXT: pushl %ebx 4704; X86-NOBMI-NEXT: pushl %edi 4705; X86-NOBMI-NEXT: pushl %esi 4706; X86-NOBMI-NEXT: subl $16, %esp 4707; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 4708; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ebx 4709; X86-NOBMI-NEXT: movl %ebx, %ecx 4710; X86-NOBMI-NEXT: shrl %cl, %edi 4711; X86-NOBMI-NEXT: xorl %ecx, %ecx 4712; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4713; X86-NOBMI-NEXT: movl $-1, %esi 4714; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 4715; X86-NOBMI-NEXT: shrl %cl, %esi 4716; X86-NOBMI-NEXT: movl %esi, (%esp) 4717; X86-NOBMI-NEXT: calll use32 4718; X86-NOBMI-NEXT: andl %edi, %esi 4719; X86-NOBMI-NEXT: movl %ebx, (%esp) 4720; X86-NOBMI-NEXT: calll use32 4721; X86-NOBMI-NEXT: movl %esi, %eax 4722; X86-NOBMI-NEXT: addl $16, %esp 4723; X86-NOBMI-NEXT: popl %esi 4724; X86-NOBMI-NEXT: popl %edi 4725; X86-NOBMI-NEXT: popl %ebx 4726; X86-NOBMI-NEXT: retl 4727; 4728; X86-BMI1NOTBM-LABEL: bextr32_c5_skipextrauses: 4729; X86-BMI1NOTBM: # %bb.0: 4730; X86-BMI1NOTBM-NEXT: pushl %ebx 4731; X86-BMI1NOTBM-NEXT: pushl %edi 4732; X86-BMI1NOTBM-NEXT: pushl %esi 4733; X86-BMI1NOTBM-NEXT: subl $16, %esp 4734; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 4735; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ebx 4736; X86-BMI1NOTBM-NEXT: movl %ebx, %ecx 4737; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4738; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx 4739; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4740; X86-BMI1NOTBM-NEXT: movl $-1, %esi 4741; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 4742; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 4743; X86-BMI1NOTBM-NEXT: movl %esi, (%esp) 4744; X86-BMI1NOTBM-NEXT: calll use32 4745; X86-BMI1NOTBM-NEXT: andl %edi, %esi 4746; X86-BMI1NOTBM-NEXT: movl %ebx, (%esp) 4747; X86-BMI1NOTBM-NEXT: calll use32 4748; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4749; X86-BMI1NOTBM-NEXT: addl $16, %esp 4750; X86-BMI1NOTBM-NEXT: popl %esi 4751; X86-BMI1NOTBM-NEXT: popl %edi 4752; X86-BMI1NOTBM-NEXT: popl %ebx 4753; X86-BMI1NOTBM-NEXT: retl 4754; 4755; X86-BMI1BMI2-LABEL: bextr32_c5_skipextrauses: 4756; X86-BMI1BMI2: # %bb.0: 4757; X86-BMI1BMI2-NEXT: pushl %ebx 4758; X86-BMI1BMI2-NEXT: pushl %edi 4759; X86-BMI1BMI2-NEXT: pushl %esi 4760; X86-BMI1BMI2-NEXT: subl $16, %esp 4761; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl 4762; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edi 4763; X86-BMI1BMI2-NEXT: shrxl %edi, {{[0-9]+}}(%esp), %esi 4764; X86-BMI1BMI2-NEXT: movl %ebx, %eax 4765; X86-BMI1BMI2-NEXT: negb %al 4766; X86-BMI1BMI2-NEXT: movl $-1, %ecx 4767; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax 4768; X86-BMI1BMI2-NEXT: movl %eax, (%esp) 4769; X86-BMI1BMI2-NEXT: calll use32 4770; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %esi 4771; X86-BMI1BMI2-NEXT: movl %edi, (%esp) 4772; X86-BMI1BMI2-NEXT: calll use32 4773; X86-BMI1BMI2-NEXT: movl %esi, %eax 4774; X86-BMI1BMI2-NEXT: addl $16, %esp 4775; X86-BMI1BMI2-NEXT: popl %esi 4776; X86-BMI1BMI2-NEXT: popl %edi 4777; X86-BMI1BMI2-NEXT: popl %ebx 4778; X86-BMI1BMI2-NEXT: retl 4779; 4780; X64-NOBMI-LABEL: bextr32_c5_skipextrauses: 4781; X64-NOBMI: # %bb.0: 4782; X64-NOBMI-NEXT: pushq %rbp 4783; X64-NOBMI-NEXT: pushq %r14 4784; X64-NOBMI-NEXT: pushq %rbx 4785; X64-NOBMI-NEXT: movl %esi, %r14d 4786; X64-NOBMI-NEXT: movl %edi, %ebp 4787; X64-NOBMI-NEXT: movl %r14d, %ecx 4788; X64-NOBMI-NEXT: shrl %cl, %ebp 4789; X64-NOBMI-NEXT: negb %dl 4790; X64-NOBMI-NEXT: movl $-1, %ebx 4791; X64-NOBMI-NEXT: movl %edx, %ecx 4792; X64-NOBMI-NEXT: shrl %cl, %ebx 4793; X64-NOBMI-NEXT: movl %ebx, %edi 4794; X64-NOBMI-NEXT: callq use32 4795; X64-NOBMI-NEXT: andl %ebp, %ebx 4796; X64-NOBMI-NEXT: movl %r14d, %edi 4797; X64-NOBMI-NEXT: callq use32 4798; X64-NOBMI-NEXT: movl %ebx, %eax 4799; X64-NOBMI-NEXT: popq %rbx 4800; X64-NOBMI-NEXT: popq %r14 4801; X64-NOBMI-NEXT: popq %rbp 4802; X64-NOBMI-NEXT: retq 4803; 4804; X64-BMI1NOTBM-LABEL: bextr32_c5_skipextrauses: 4805; X64-BMI1NOTBM: # %bb.0: 4806; X64-BMI1NOTBM-NEXT: pushq %rbp 4807; X64-BMI1NOTBM-NEXT: pushq %r14 4808; X64-BMI1NOTBM-NEXT: pushq %rbx 4809; X64-BMI1NOTBM-NEXT: movl %esi, %r14d 4810; X64-BMI1NOTBM-NEXT: movl %edi, %ebp 4811; X64-BMI1NOTBM-NEXT: movl %r14d, %ecx 4812; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp 4813; X64-BMI1NOTBM-NEXT: negb %dl 4814; X64-BMI1NOTBM-NEXT: movl $-1, %ebx 4815; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 4816; X64-BMI1NOTBM-NEXT: shrl %cl, %ebx 4817; X64-BMI1NOTBM-NEXT: movl %ebx, %edi 4818; X64-BMI1NOTBM-NEXT: callq use32 4819; X64-BMI1NOTBM-NEXT: andl %ebp, %ebx 4820; X64-BMI1NOTBM-NEXT: movl %r14d, %edi 4821; X64-BMI1NOTBM-NEXT: callq use32 4822; X64-BMI1NOTBM-NEXT: movl %ebx, %eax 4823; X64-BMI1NOTBM-NEXT: popq %rbx 4824; X64-BMI1NOTBM-NEXT: popq %r14 4825; X64-BMI1NOTBM-NEXT: popq %rbp 4826; X64-BMI1NOTBM-NEXT: retq 4827; 4828; X64-BMI1BMI2-LABEL: bextr32_c5_skipextrauses: 4829; X64-BMI1BMI2: # %bb.0: 4830; X64-BMI1BMI2-NEXT: pushq %rbp 4831; X64-BMI1BMI2-NEXT: pushq %r14 4832; X64-BMI1BMI2-NEXT: pushq %rbx 4833; X64-BMI1BMI2-NEXT: movl %edx, %ebx 4834; X64-BMI1BMI2-NEXT: movl %esi, %ebp 4835; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %r14d 4836; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4837; X64-BMI1BMI2-NEXT: negb %al 4838; X64-BMI1BMI2-NEXT: movl $-1, %ecx 4839; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi 4840; X64-BMI1BMI2-NEXT: callq use32 4841; X64-BMI1BMI2-NEXT: bzhil %ebx, %r14d, %ebx 4842; X64-BMI1BMI2-NEXT: movl %ebp, %edi 4843; X64-BMI1BMI2-NEXT: callq use32 4844; X64-BMI1BMI2-NEXT: movl %ebx, %eax 4845; X64-BMI1BMI2-NEXT: popq %rbx 4846; X64-BMI1BMI2-NEXT: popq %r14 4847; X64-BMI1BMI2-NEXT: popq %rbp 4848; X64-BMI1BMI2-NEXT: retq 4849 %shifted = lshr i32 %val, %numskipbits 4850 %numhighbits = sub i32 32, %numlowbits 4851 %mask = lshr i32 -1, %numhighbits 4852 call void @use32(i32 %mask) 4853 %masked = and i32 %mask, %shifted 4854 call void @use32(i32 %numskipbits) 4855 ret i32 %masked 4856} 4857 4858; 64-bit 4859 4860define i64 @bextr64_c0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 4861; X86-NOBMI-LABEL: bextr64_c0: 4862; X86-NOBMI: # %bb.0: 4863; X86-NOBMI-NEXT: pushl %ebp 4864; X86-NOBMI-NEXT: pushl %ebx 4865; X86-NOBMI-NEXT: pushl %edi 4866; X86-NOBMI-NEXT: pushl %esi 4867; X86-NOBMI-NEXT: subl $12, %esp 4868; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 4869; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 4870; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 4871; X86-NOBMI-NEXT: movl %eax, %edi 4872; X86-NOBMI-NEXT: shrl %cl, %edi 4873; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 4874; X86-NOBMI-NEXT: testb $32, %cl 4875; X86-NOBMI-NEXT: je .LBB41_2 4876; X86-NOBMI-NEXT: # %bb.1: 4877; X86-NOBMI-NEXT: movl %edi, %esi 4878; X86-NOBMI-NEXT: xorl %edi, %edi 4879; X86-NOBMI-NEXT: .LBB41_2: 4880; X86-NOBMI-NEXT: movb $64, %cl 4881; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 4882; X86-NOBMI-NEXT: movl $-1, %ebp 4883; X86-NOBMI-NEXT: movl $-1, %ebx 4884; X86-NOBMI-NEXT: shrl %cl, %ebx 4885; X86-NOBMI-NEXT: testb $32, %cl 4886; X86-NOBMI-NEXT: je .LBB41_4 4887; X86-NOBMI-NEXT: # %bb.3: 4888; X86-NOBMI-NEXT: movl %ebx, %ebp 4889; X86-NOBMI-NEXT: xorl %ebx, %ebx 4890; X86-NOBMI-NEXT: .LBB41_4: 4891; X86-NOBMI-NEXT: subl $8, %esp 4892; X86-NOBMI-NEXT: pushl %ebx 4893; X86-NOBMI-NEXT: pushl %ebp 4894; X86-NOBMI-NEXT: calll use64 4895; X86-NOBMI-NEXT: addl $16, %esp 4896; X86-NOBMI-NEXT: andl %ebp, %esi 4897; X86-NOBMI-NEXT: andl %ebx, %edi 4898; X86-NOBMI-NEXT: movl %esi, %eax 4899; X86-NOBMI-NEXT: movl %edi, %edx 4900; X86-NOBMI-NEXT: addl $12, %esp 4901; X86-NOBMI-NEXT: popl %esi 4902; X86-NOBMI-NEXT: popl %edi 4903; X86-NOBMI-NEXT: popl %ebx 4904; X86-NOBMI-NEXT: popl %ebp 4905; X86-NOBMI-NEXT: retl 4906; 4907; X86-BMI1NOTBM-LABEL: bextr64_c0: 4908; X86-BMI1NOTBM: # %bb.0: 4909; X86-BMI1NOTBM-NEXT: pushl %ebp 4910; X86-BMI1NOTBM-NEXT: pushl %ebx 4911; X86-BMI1NOTBM-NEXT: pushl %edi 4912; X86-BMI1NOTBM-NEXT: pushl %esi 4913; X86-BMI1NOTBM-NEXT: subl $12, %esp 4914; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 4915; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 4916; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 4917; X86-BMI1NOTBM-NEXT: movl %eax, %edi 4918; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 4919; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 4920; X86-BMI1NOTBM-NEXT: testb $32, %cl 4921; X86-BMI1NOTBM-NEXT: je .LBB41_2 4922; X86-BMI1NOTBM-NEXT: # %bb.1: 4923; X86-BMI1NOTBM-NEXT: movl %edi, %esi 4924; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 4925; X86-BMI1NOTBM-NEXT: .LBB41_2: 4926; X86-BMI1NOTBM-NEXT: movb $64, %cl 4927; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 4928; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 4929; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 4930; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx 4931; X86-BMI1NOTBM-NEXT: testb $32, %cl 4932; X86-BMI1NOTBM-NEXT: je .LBB41_4 4933; X86-BMI1NOTBM-NEXT: # %bb.3: 4934; X86-BMI1NOTBM-NEXT: movl %ebx, %ebp 4935; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 4936; X86-BMI1NOTBM-NEXT: .LBB41_4: 4937; X86-BMI1NOTBM-NEXT: subl $8, %esp 4938; X86-BMI1NOTBM-NEXT: pushl %ebx 4939; X86-BMI1NOTBM-NEXT: pushl %ebp 4940; X86-BMI1NOTBM-NEXT: calll use64 4941; X86-BMI1NOTBM-NEXT: addl $16, %esp 4942; X86-BMI1NOTBM-NEXT: andl %ebp, %esi 4943; X86-BMI1NOTBM-NEXT: andl %ebx, %edi 4944; X86-BMI1NOTBM-NEXT: movl %esi, %eax 4945; X86-BMI1NOTBM-NEXT: movl %edi, %edx 4946; X86-BMI1NOTBM-NEXT: addl $12, %esp 4947; X86-BMI1NOTBM-NEXT: popl %esi 4948; X86-BMI1NOTBM-NEXT: popl %edi 4949; X86-BMI1NOTBM-NEXT: popl %ebx 4950; X86-BMI1NOTBM-NEXT: popl %ebp 4951; X86-BMI1NOTBM-NEXT: retl 4952; 4953; X86-BMI1BMI2-LABEL: bextr64_c0: 4954; X86-BMI1BMI2: # %bb.0: 4955; X86-BMI1BMI2-NEXT: pushl %ebp 4956; X86-BMI1BMI2-NEXT: pushl %ebx 4957; X86-BMI1BMI2-NEXT: pushl %edi 4958; X86-BMI1BMI2-NEXT: pushl %esi 4959; X86-BMI1BMI2-NEXT: subl $12, %esp 4960; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 4961; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 4962; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 4963; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 4964; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 4965; X86-BMI1BMI2-NEXT: testb $32, %cl 4966; X86-BMI1BMI2-NEXT: je .LBB41_2 4967; X86-BMI1BMI2-NEXT: # %bb.1: 4968; X86-BMI1BMI2-NEXT: movl %edi, %esi 4969; X86-BMI1BMI2-NEXT: xorl %edi, %edi 4970; X86-BMI1BMI2-NEXT: .LBB41_2: 4971; X86-BMI1BMI2-NEXT: movb $64, %al 4972; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %al 4973; X86-BMI1BMI2-NEXT: movl $-1, %ebp 4974; X86-BMI1BMI2-NEXT: shrxl %eax, %ebp, %ebx 4975; X86-BMI1BMI2-NEXT: testb $32, %al 4976; X86-BMI1BMI2-NEXT: je .LBB41_4 4977; X86-BMI1BMI2-NEXT: # %bb.3: 4978; X86-BMI1BMI2-NEXT: movl %ebx, %ebp 4979; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx 4980; X86-BMI1BMI2-NEXT: .LBB41_4: 4981; X86-BMI1BMI2-NEXT: subl $8, %esp 4982; X86-BMI1BMI2-NEXT: pushl %ebx 4983; X86-BMI1BMI2-NEXT: pushl %ebp 4984; X86-BMI1BMI2-NEXT: calll use64 4985; X86-BMI1BMI2-NEXT: addl $16, %esp 4986; X86-BMI1BMI2-NEXT: andl %ebp, %esi 4987; X86-BMI1BMI2-NEXT: andl %ebx, %edi 4988; X86-BMI1BMI2-NEXT: movl %esi, %eax 4989; X86-BMI1BMI2-NEXT: movl %edi, %edx 4990; X86-BMI1BMI2-NEXT: addl $12, %esp 4991; X86-BMI1BMI2-NEXT: popl %esi 4992; X86-BMI1BMI2-NEXT: popl %edi 4993; X86-BMI1BMI2-NEXT: popl %ebx 4994; X86-BMI1BMI2-NEXT: popl %ebp 4995; X86-BMI1BMI2-NEXT: retl 4996; 4997; X64-NOBMI-LABEL: bextr64_c0: 4998; X64-NOBMI: # %bb.0: 4999; X64-NOBMI-NEXT: pushq %r14 5000; X64-NOBMI-NEXT: pushq %rbx 5001; X64-NOBMI-NEXT: pushq %rax 5002; X64-NOBMI-NEXT: movq %rsi, %rcx 5003; X64-NOBMI-NEXT: movq %rdi, %r14 5004; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 5005; X64-NOBMI-NEXT: shrq %cl, %r14 5006; X64-NOBMI-NEXT: negb %dl 5007; X64-NOBMI-NEXT: movq $-1, %rbx 5008; X64-NOBMI-NEXT: movl %edx, %ecx 5009; X64-NOBMI-NEXT: shrq %cl, %rbx 5010; X64-NOBMI-NEXT: movq %rbx, %rdi 5011; X64-NOBMI-NEXT: callq use64 5012; X64-NOBMI-NEXT: andq %r14, %rbx 5013; X64-NOBMI-NEXT: movq %rbx, %rax 5014; X64-NOBMI-NEXT: addq $8, %rsp 5015; X64-NOBMI-NEXT: popq %rbx 5016; X64-NOBMI-NEXT: popq %r14 5017; X64-NOBMI-NEXT: retq 5018; 5019; X64-BMI1NOTBM-LABEL: bextr64_c0: 5020; X64-BMI1NOTBM: # %bb.0: 5021; X64-BMI1NOTBM-NEXT: pushq %r14 5022; X64-BMI1NOTBM-NEXT: pushq %rbx 5023; X64-BMI1NOTBM-NEXT: pushq %rax 5024; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx 5025; X64-BMI1NOTBM-NEXT: movq %rdi, %r14 5026; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx 5027; X64-BMI1NOTBM-NEXT: shrq %cl, %r14 5028; X64-BMI1NOTBM-NEXT: negb %dl 5029; X64-BMI1NOTBM-NEXT: movq $-1, %rbx 5030; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 5031; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 5032; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi 5033; X64-BMI1NOTBM-NEXT: callq use64 5034; X64-BMI1NOTBM-NEXT: andq %r14, %rbx 5035; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 5036; X64-BMI1NOTBM-NEXT: addq $8, %rsp 5037; X64-BMI1NOTBM-NEXT: popq %rbx 5038; X64-BMI1NOTBM-NEXT: popq %r14 5039; X64-BMI1NOTBM-NEXT: retq 5040; 5041; X64-BMI1BMI2-LABEL: bextr64_c0: 5042; X64-BMI1BMI2: # %bb.0: 5043; X64-BMI1BMI2-NEXT: pushq %r14 5044; X64-BMI1BMI2-NEXT: pushq %rbx 5045; X64-BMI1BMI2-NEXT: pushq %rax 5046; X64-BMI1BMI2-NEXT: movq %rdx, %rbx 5047; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %r14 5048; X64-BMI1BMI2-NEXT: movl %ebx, %eax 5049; X64-BMI1BMI2-NEXT: negb %al 5050; X64-BMI1BMI2-NEXT: movq $-1, %rcx 5051; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi 5052; X64-BMI1BMI2-NEXT: callq use64 5053; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax 5054; X64-BMI1BMI2-NEXT: addq $8, %rsp 5055; X64-BMI1BMI2-NEXT: popq %rbx 5056; X64-BMI1BMI2-NEXT: popq %r14 5057; X64-BMI1BMI2-NEXT: retq 5058 %shifted = lshr i64 %val, %numskipbits 5059 %numhighbits = sub i64 64, %numlowbits 5060 %mask = lshr i64 -1, %numhighbits 5061 call void @use64(i64 %mask) 5062 %masked = and i64 %mask, %shifted 5063 ret i64 %masked 5064} 5065 5066define i64 @bextr64_c1_indexzext(i64 %val, i8 %numskipbits, i8 %numlowbits) nounwind { 5067; X86-NOBMI-LABEL: bextr64_c1_indexzext: 5068; X86-NOBMI: # %bb.0: 5069; X86-NOBMI-NEXT: pushl %ebp 5070; X86-NOBMI-NEXT: pushl %ebx 5071; X86-NOBMI-NEXT: pushl %edi 5072; X86-NOBMI-NEXT: pushl %esi 5073; X86-NOBMI-NEXT: subl $12, %esp 5074; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 5075; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 5076; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 5077; X86-NOBMI-NEXT: movl %eax, %edi 5078; X86-NOBMI-NEXT: shrl %cl, %edi 5079; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 5080; X86-NOBMI-NEXT: testb $32, %cl 5081; X86-NOBMI-NEXT: je .LBB42_2 5082; X86-NOBMI-NEXT: # %bb.1: 5083; X86-NOBMI-NEXT: movl %edi, %esi 5084; X86-NOBMI-NEXT: xorl %edi, %edi 5085; X86-NOBMI-NEXT: .LBB42_2: 5086; X86-NOBMI-NEXT: movb $64, %cl 5087; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 5088; X86-NOBMI-NEXT: movl $-1, %ebp 5089; X86-NOBMI-NEXT: movl $-1, %ebx 5090; X86-NOBMI-NEXT: shrl %cl, %ebx 5091; X86-NOBMI-NEXT: testb $32, %cl 5092; X86-NOBMI-NEXT: je .LBB42_4 5093; X86-NOBMI-NEXT: # %bb.3: 5094; X86-NOBMI-NEXT: movl %ebx, %ebp 5095; X86-NOBMI-NEXT: xorl %ebx, %ebx 5096; X86-NOBMI-NEXT: .LBB42_4: 5097; X86-NOBMI-NEXT: subl $8, %esp 5098; X86-NOBMI-NEXT: pushl %ebx 5099; X86-NOBMI-NEXT: pushl %ebp 5100; X86-NOBMI-NEXT: calll use64 5101; X86-NOBMI-NEXT: addl $16, %esp 5102; X86-NOBMI-NEXT: andl %ebp, %esi 5103; X86-NOBMI-NEXT: andl %ebx, %edi 5104; X86-NOBMI-NEXT: movl %esi, %eax 5105; X86-NOBMI-NEXT: movl %edi, %edx 5106; X86-NOBMI-NEXT: addl $12, %esp 5107; X86-NOBMI-NEXT: popl %esi 5108; X86-NOBMI-NEXT: popl %edi 5109; X86-NOBMI-NEXT: popl %ebx 5110; X86-NOBMI-NEXT: popl %ebp 5111; X86-NOBMI-NEXT: retl 5112; 5113; X86-BMI1NOTBM-LABEL: bextr64_c1_indexzext: 5114; X86-BMI1NOTBM: # %bb.0: 5115; X86-BMI1NOTBM-NEXT: pushl %ebp 5116; X86-BMI1NOTBM-NEXT: pushl %ebx 5117; X86-BMI1NOTBM-NEXT: pushl %edi 5118; X86-BMI1NOTBM-NEXT: pushl %esi 5119; X86-BMI1NOTBM-NEXT: subl $12, %esp 5120; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 5121; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 5122; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 5123; X86-BMI1NOTBM-NEXT: movl %eax, %edi 5124; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 5125; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 5126; X86-BMI1NOTBM-NEXT: testb $32, %cl 5127; X86-BMI1NOTBM-NEXT: je .LBB42_2 5128; X86-BMI1NOTBM-NEXT: # %bb.1: 5129; X86-BMI1NOTBM-NEXT: movl %edi, %esi 5130; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 5131; X86-BMI1NOTBM-NEXT: .LBB42_2: 5132; X86-BMI1NOTBM-NEXT: movb $64, %cl 5133; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 5134; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 5135; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 5136; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx 5137; X86-BMI1NOTBM-NEXT: testb $32, %cl 5138; X86-BMI1NOTBM-NEXT: je .LBB42_4 5139; X86-BMI1NOTBM-NEXT: # %bb.3: 5140; X86-BMI1NOTBM-NEXT: movl %ebx, %ebp 5141; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 5142; X86-BMI1NOTBM-NEXT: .LBB42_4: 5143; X86-BMI1NOTBM-NEXT: subl $8, %esp 5144; X86-BMI1NOTBM-NEXT: pushl %ebx 5145; X86-BMI1NOTBM-NEXT: pushl %ebp 5146; X86-BMI1NOTBM-NEXT: calll use64 5147; X86-BMI1NOTBM-NEXT: addl $16, %esp 5148; X86-BMI1NOTBM-NEXT: andl %ebp, %esi 5149; X86-BMI1NOTBM-NEXT: andl %ebx, %edi 5150; X86-BMI1NOTBM-NEXT: movl %esi, %eax 5151; X86-BMI1NOTBM-NEXT: movl %edi, %edx 5152; X86-BMI1NOTBM-NEXT: addl $12, %esp 5153; X86-BMI1NOTBM-NEXT: popl %esi 5154; X86-BMI1NOTBM-NEXT: popl %edi 5155; X86-BMI1NOTBM-NEXT: popl %ebx 5156; X86-BMI1NOTBM-NEXT: popl %ebp 5157; X86-BMI1NOTBM-NEXT: retl 5158; 5159; X86-BMI1BMI2-LABEL: bextr64_c1_indexzext: 5160; X86-BMI1BMI2: # %bb.0: 5161; X86-BMI1BMI2-NEXT: pushl %ebp 5162; X86-BMI1BMI2-NEXT: pushl %ebx 5163; X86-BMI1BMI2-NEXT: pushl %edi 5164; X86-BMI1BMI2-NEXT: pushl %esi 5165; X86-BMI1BMI2-NEXT: subl $12, %esp 5166; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 5167; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 5168; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 5169; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 5170; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 5171; X86-BMI1BMI2-NEXT: testb $32, %cl 5172; X86-BMI1BMI2-NEXT: je .LBB42_2 5173; X86-BMI1BMI2-NEXT: # %bb.1: 5174; X86-BMI1BMI2-NEXT: movl %edi, %esi 5175; X86-BMI1BMI2-NEXT: xorl %edi, %edi 5176; X86-BMI1BMI2-NEXT: .LBB42_2: 5177; X86-BMI1BMI2-NEXT: movb $64, %al 5178; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %al 5179; X86-BMI1BMI2-NEXT: movl $-1, %ebp 5180; X86-BMI1BMI2-NEXT: shrxl %eax, %ebp, %ebx 5181; X86-BMI1BMI2-NEXT: testb $32, %al 5182; X86-BMI1BMI2-NEXT: je .LBB42_4 5183; X86-BMI1BMI2-NEXT: # %bb.3: 5184; X86-BMI1BMI2-NEXT: movl %ebx, %ebp 5185; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx 5186; X86-BMI1BMI2-NEXT: .LBB42_4: 5187; X86-BMI1BMI2-NEXT: subl $8, %esp 5188; X86-BMI1BMI2-NEXT: pushl %ebx 5189; X86-BMI1BMI2-NEXT: pushl %ebp 5190; X86-BMI1BMI2-NEXT: calll use64 5191; X86-BMI1BMI2-NEXT: addl $16, %esp 5192; X86-BMI1BMI2-NEXT: andl %ebp, %esi 5193; X86-BMI1BMI2-NEXT: andl %ebx, %edi 5194; X86-BMI1BMI2-NEXT: movl %esi, %eax 5195; X86-BMI1BMI2-NEXT: movl %edi, %edx 5196; X86-BMI1BMI2-NEXT: addl $12, %esp 5197; X86-BMI1BMI2-NEXT: popl %esi 5198; X86-BMI1BMI2-NEXT: popl %edi 5199; X86-BMI1BMI2-NEXT: popl %ebx 5200; X86-BMI1BMI2-NEXT: popl %ebp 5201; X86-BMI1BMI2-NEXT: retl 5202; 5203; X64-NOBMI-LABEL: bextr64_c1_indexzext: 5204; X64-NOBMI: # %bb.0: 5205; X64-NOBMI-NEXT: pushq %r14 5206; X64-NOBMI-NEXT: pushq %rbx 5207; X64-NOBMI-NEXT: pushq %rax 5208; X64-NOBMI-NEXT: movl %esi, %ecx 5209; X64-NOBMI-NEXT: movq %rdi, %r14 5210; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 5211; X64-NOBMI-NEXT: shrq %cl, %r14 5212; X64-NOBMI-NEXT: negb %dl 5213; X64-NOBMI-NEXT: movq $-1, %rbx 5214; X64-NOBMI-NEXT: movl %edx, %ecx 5215; X64-NOBMI-NEXT: shrq %cl, %rbx 5216; X64-NOBMI-NEXT: movq %rbx, %rdi 5217; X64-NOBMI-NEXT: callq use64 5218; X64-NOBMI-NEXT: andq %r14, %rbx 5219; X64-NOBMI-NEXT: movq %rbx, %rax 5220; X64-NOBMI-NEXT: addq $8, %rsp 5221; X64-NOBMI-NEXT: popq %rbx 5222; X64-NOBMI-NEXT: popq %r14 5223; X64-NOBMI-NEXT: retq 5224; 5225; X64-BMI1NOTBM-LABEL: bextr64_c1_indexzext: 5226; X64-BMI1NOTBM: # %bb.0: 5227; X64-BMI1NOTBM-NEXT: pushq %r14 5228; X64-BMI1NOTBM-NEXT: pushq %rbx 5229; X64-BMI1NOTBM-NEXT: pushq %rax 5230; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 5231; X64-BMI1NOTBM-NEXT: movq %rdi, %r14 5232; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 5233; X64-BMI1NOTBM-NEXT: shrq %cl, %r14 5234; X64-BMI1NOTBM-NEXT: negb %dl 5235; X64-BMI1NOTBM-NEXT: movq $-1, %rbx 5236; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 5237; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 5238; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi 5239; X64-BMI1NOTBM-NEXT: callq use64 5240; X64-BMI1NOTBM-NEXT: andq %r14, %rbx 5241; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 5242; X64-BMI1NOTBM-NEXT: addq $8, %rsp 5243; X64-BMI1NOTBM-NEXT: popq %rbx 5244; X64-BMI1NOTBM-NEXT: popq %r14 5245; X64-BMI1NOTBM-NEXT: retq 5246; 5247; X64-BMI1BMI2-LABEL: bextr64_c1_indexzext: 5248; X64-BMI1BMI2: # %bb.0: 5249; X64-BMI1BMI2-NEXT: pushq %r14 5250; X64-BMI1BMI2-NEXT: pushq %rbx 5251; X64-BMI1BMI2-NEXT: pushq %rax 5252; X64-BMI1BMI2-NEXT: movl %edx, %ebx 5253; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 5254; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %r14 5255; X64-BMI1BMI2-NEXT: movl %ebx, %eax 5256; X64-BMI1BMI2-NEXT: negb %al 5257; X64-BMI1BMI2-NEXT: movq $-1, %rcx 5258; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi 5259; X64-BMI1BMI2-NEXT: callq use64 5260; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax 5261; X64-BMI1BMI2-NEXT: addq $8, %rsp 5262; X64-BMI1BMI2-NEXT: popq %rbx 5263; X64-BMI1BMI2-NEXT: popq %r14 5264; X64-BMI1BMI2-NEXT: retq 5265 %skip = zext i8 %numskipbits to i64 5266 %shifted = lshr i64 %val, %skip 5267 %numhighbits = sub i8 64, %numlowbits 5268 %sh_prom = zext i8 %numhighbits to i64 5269 %mask = lshr i64 -1, %sh_prom 5270 call void @use64(i64 %mask) 5271 %masked = and i64 %mask, %shifted 5272 ret i64 %masked 5273} 5274 5275define i64 @bextr64_c2_load(i64* %w, i64 %numskipbits, i64 %numlowbits) nounwind { 5276; X86-NOBMI-LABEL: bextr64_c2_load: 5277; X86-NOBMI: # %bb.0: 5278; X86-NOBMI-NEXT: pushl %ebp 5279; X86-NOBMI-NEXT: pushl %ebx 5280; X86-NOBMI-NEXT: pushl %edi 5281; X86-NOBMI-NEXT: pushl %esi 5282; X86-NOBMI-NEXT: subl $12, %esp 5283; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 5284; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 5285; X86-NOBMI-NEXT: movl (%eax), %esi 5286; X86-NOBMI-NEXT: movl 4(%eax), %eax 5287; X86-NOBMI-NEXT: movl %eax, %edi 5288; X86-NOBMI-NEXT: shrl %cl, %edi 5289; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 5290; X86-NOBMI-NEXT: testb $32, %cl 5291; X86-NOBMI-NEXT: je .LBB43_2 5292; X86-NOBMI-NEXT: # %bb.1: 5293; X86-NOBMI-NEXT: movl %edi, %esi 5294; X86-NOBMI-NEXT: xorl %edi, %edi 5295; X86-NOBMI-NEXT: .LBB43_2: 5296; X86-NOBMI-NEXT: movb $64, %cl 5297; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 5298; X86-NOBMI-NEXT: movl $-1, %ebp 5299; X86-NOBMI-NEXT: movl $-1, %ebx 5300; X86-NOBMI-NEXT: shrl %cl, %ebx 5301; X86-NOBMI-NEXT: testb $32, %cl 5302; X86-NOBMI-NEXT: je .LBB43_4 5303; X86-NOBMI-NEXT: # %bb.3: 5304; X86-NOBMI-NEXT: movl %ebx, %ebp 5305; X86-NOBMI-NEXT: xorl %ebx, %ebx 5306; X86-NOBMI-NEXT: .LBB43_4: 5307; X86-NOBMI-NEXT: subl $8, %esp 5308; X86-NOBMI-NEXT: pushl %ebx 5309; X86-NOBMI-NEXT: pushl %ebp 5310; X86-NOBMI-NEXT: calll use64 5311; X86-NOBMI-NEXT: addl $16, %esp 5312; X86-NOBMI-NEXT: andl %ebp, %esi 5313; X86-NOBMI-NEXT: andl %ebx, %edi 5314; X86-NOBMI-NEXT: movl %esi, %eax 5315; X86-NOBMI-NEXT: movl %edi, %edx 5316; X86-NOBMI-NEXT: addl $12, %esp 5317; X86-NOBMI-NEXT: popl %esi 5318; X86-NOBMI-NEXT: popl %edi 5319; X86-NOBMI-NEXT: popl %ebx 5320; X86-NOBMI-NEXT: popl %ebp 5321; X86-NOBMI-NEXT: retl 5322; 5323; X86-BMI1NOTBM-LABEL: bextr64_c2_load: 5324; X86-BMI1NOTBM: # %bb.0: 5325; X86-BMI1NOTBM-NEXT: pushl %ebp 5326; X86-BMI1NOTBM-NEXT: pushl %ebx 5327; X86-BMI1NOTBM-NEXT: pushl %edi 5328; X86-BMI1NOTBM-NEXT: pushl %esi 5329; X86-BMI1NOTBM-NEXT: subl $12, %esp 5330; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 5331; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 5332; X86-BMI1NOTBM-NEXT: movl (%eax), %esi 5333; X86-BMI1NOTBM-NEXT: movl 4(%eax), %eax 5334; X86-BMI1NOTBM-NEXT: movl %eax, %edi 5335; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 5336; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 5337; X86-BMI1NOTBM-NEXT: testb $32, %cl 5338; X86-BMI1NOTBM-NEXT: je .LBB43_2 5339; X86-BMI1NOTBM-NEXT: # %bb.1: 5340; X86-BMI1NOTBM-NEXT: movl %edi, %esi 5341; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 5342; X86-BMI1NOTBM-NEXT: .LBB43_2: 5343; X86-BMI1NOTBM-NEXT: movb $64, %cl 5344; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 5345; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 5346; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 5347; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx 5348; X86-BMI1NOTBM-NEXT: testb $32, %cl 5349; X86-BMI1NOTBM-NEXT: je .LBB43_4 5350; X86-BMI1NOTBM-NEXT: # %bb.3: 5351; X86-BMI1NOTBM-NEXT: movl %ebx, %ebp 5352; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 5353; X86-BMI1NOTBM-NEXT: .LBB43_4: 5354; X86-BMI1NOTBM-NEXT: subl $8, %esp 5355; X86-BMI1NOTBM-NEXT: pushl %ebx 5356; X86-BMI1NOTBM-NEXT: pushl %ebp 5357; X86-BMI1NOTBM-NEXT: calll use64 5358; X86-BMI1NOTBM-NEXT: addl $16, %esp 5359; X86-BMI1NOTBM-NEXT: andl %ebp, %esi 5360; X86-BMI1NOTBM-NEXT: andl %ebx, %edi 5361; X86-BMI1NOTBM-NEXT: movl %esi, %eax 5362; X86-BMI1NOTBM-NEXT: movl %edi, %edx 5363; X86-BMI1NOTBM-NEXT: addl $12, %esp 5364; X86-BMI1NOTBM-NEXT: popl %esi 5365; X86-BMI1NOTBM-NEXT: popl %edi 5366; X86-BMI1NOTBM-NEXT: popl %ebx 5367; X86-BMI1NOTBM-NEXT: popl %ebp 5368; X86-BMI1NOTBM-NEXT: retl 5369; 5370; X86-BMI1BMI2-LABEL: bextr64_c2_load: 5371; X86-BMI1BMI2: # %bb.0: 5372; X86-BMI1BMI2-NEXT: pushl %ebp 5373; X86-BMI1BMI2-NEXT: pushl %ebx 5374; X86-BMI1BMI2-NEXT: pushl %edi 5375; X86-BMI1BMI2-NEXT: pushl %esi 5376; X86-BMI1BMI2-NEXT: subl $12, %esp 5377; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 5378; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 5379; X86-BMI1BMI2-NEXT: movl (%eax), %esi 5380; X86-BMI1BMI2-NEXT: movl 4(%eax), %eax 5381; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 5382; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 5383; X86-BMI1BMI2-NEXT: testb $32, %cl 5384; X86-BMI1BMI2-NEXT: je .LBB43_2 5385; X86-BMI1BMI2-NEXT: # %bb.1: 5386; X86-BMI1BMI2-NEXT: movl %edi, %esi 5387; X86-BMI1BMI2-NEXT: xorl %edi, %edi 5388; X86-BMI1BMI2-NEXT: .LBB43_2: 5389; X86-BMI1BMI2-NEXT: movb $64, %al 5390; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %al 5391; X86-BMI1BMI2-NEXT: movl $-1, %ebp 5392; X86-BMI1BMI2-NEXT: shrxl %eax, %ebp, %ebx 5393; X86-BMI1BMI2-NEXT: testb $32, %al 5394; X86-BMI1BMI2-NEXT: je .LBB43_4 5395; X86-BMI1BMI2-NEXT: # %bb.3: 5396; X86-BMI1BMI2-NEXT: movl %ebx, %ebp 5397; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx 5398; X86-BMI1BMI2-NEXT: .LBB43_4: 5399; X86-BMI1BMI2-NEXT: subl $8, %esp 5400; X86-BMI1BMI2-NEXT: pushl %ebx 5401; X86-BMI1BMI2-NEXT: pushl %ebp 5402; X86-BMI1BMI2-NEXT: calll use64 5403; X86-BMI1BMI2-NEXT: addl $16, %esp 5404; X86-BMI1BMI2-NEXT: andl %ebp, %esi 5405; X86-BMI1BMI2-NEXT: andl %ebx, %edi 5406; X86-BMI1BMI2-NEXT: movl %esi, %eax 5407; X86-BMI1BMI2-NEXT: movl %edi, %edx 5408; X86-BMI1BMI2-NEXT: addl $12, %esp 5409; X86-BMI1BMI2-NEXT: popl %esi 5410; X86-BMI1BMI2-NEXT: popl %edi 5411; X86-BMI1BMI2-NEXT: popl %ebx 5412; X86-BMI1BMI2-NEXT: popl %ebp 5413; X86-BMI1BMI2-NEXT: retl 5414; 5415; X64-NOBMI-LABEL: bextr64_c2_load: 5416; X64-NOBMI: # %bb.0: 5417; X64-NOBMI-NEXT: pushq %r14 5418; X64-NOBMI-NEXT: pushq %rbx 5419; X64-NOBMI-NEXT: pushq %rax 5420; X64-NOBMI-NEXT: movq %rsi, %rcx 5421; X64-NOBMI-NEXT: movq (%rdi), %r14 5422; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 5423; X64-NOBMI-NEXT: shrq %cl, %r14 5424; X64-NOBMI-NEXT: negb %dl 5425; X64-NOBMI-NEXT: movq $-1, %rbx 5426; X64-NOBMI-NEXT: movl %edx, %ecx 5427; X64-NOBMI-NEXT: shrq %cl, %rbx 5428; X64-NOBMI-NEXT: movq %rbx, %rdi 5429; X64-NOBMI-NEXT: callq use64 5430; X64-NOBMI-NEXT: andq %r14, %rbx 5431; X64-NOBMI-NEXT: movq %rbx, %rax 5432; X64-NOBMI-NEXT: addq $8, %rsp 5433; X64-NOBMI-NEXT: popq %rbx 5434; X64-NOBMI-NEXT: popq %r14 5435; X64-NOBMI-NEXT: retq 5436; 5437; X64-BMI1NOTBM-LABEL: bextr64_c2_load: 5438; X64-BMI1NOTBM: # %bb.0: 5439; X64-BMI1NOTBM-NEXT: pushq %r14 5440; X64-BMI1NOTBM-NEXT: pushq %rbx 5441; X64-BMI1NOTBM-NEXT: pushq %rax 5442; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx 5443; X64-BMI1NOTBM-NEXT: movq (%rdi), %r14 5444; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx 5445; X64-BMI1NOTBM-NEXT: shrq %cl, %r14 5446; X64-BMI1NOTBM-NEXT: negb %dl 5447; X64-BMI1NOTBM-NEXT: movq $-1, %rbx 5448; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 5449; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 5450; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi 5451; X64-BMI1NOTBM-NEXT: callq use64 5452; X64-BMI1NOTBM-NEXT: andq %r14, %rbx 5453; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 5454; X64-BMI1NOTBM-NEXT: addq $8, %rsp 5455; X64-BMI1NOTBM-NEXT: popq %rbx 5456; X64-BMI1NOTBM-NEXT: popq %r14 5457; X64-BMI1NOTBM-NEXT: retq 5458; 5459; X64-BMI1BMI2-LABEL: bextr64_c2_load: 5460; X64-BMI1BMI2: # %bb.0: 5461; X64-BMI1BMI2-NEXT: pushq %r14 5462; X64-BMI1BMI2-NEXT: pushq %rbx 5463; X64-BMI1BMI2-NEXT: pushq %rax 5464; X64-BMI1BMI2-NEXT: movq %rdx, %rbx 5465; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %r14 5466; X64-BMI1BMI2-NEXT: movl %ebx, %eax 5467; X64-BMI1BMI2-NEXT: negb %al 5468; X64-BMI1BMI2-NEXT: movq $-1, %rcx 5469; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi 5470; X64-BMI1BMI2-NEXT: callq use64 5471; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax 5472; X64-BMI1BMI2-NEXT: addq $8, %rsp 5473; X64-BMI1BMI2-NEXT: popq %rbx 5474; X64-BMI1BMI2-NEXT: popq %r14 5475; X64-BMI1BMI2-NEXT: retq 5476 %val = load i64, i64* %w 5477 %shifted = lshr i64 %val, %numskipbits 5478 %numhighbits = sub i64 64, %numlowbits 5479 %mask = lshr i64 -1, %numhighbits 5480 call void @use64(i64 %mask) 5481 %masked = and i64 %mask, %shifted 5482 ret i64 %masked 5483} 5484 5485define i64 @bextr64_c3_load_indexzext(i64* %w, i8 %numskipbits, i8 %numlowbits) nounwind { 5486; X86-NOBMI-LABEL: bextr64_c3_load_indexzext: 5487; X86-NOBMI: # %bb.0: 5488; X86-NOBMI-NEXT: pushl %ebp 5489; X86-NOBMI-NEXT: pushl %ebx 5490; X86-NOBMI-NEXT: pushl %edi 5491; X86-NOBMI-NEXT: pushl %esi 5492; X86-NOBMI-NEXT: subl $12, %esp 5493; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 5494; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 5495; X86-NOBMI-NEXT: movl (%eax), %esi 5496; X86-NOBMI-NEXT: movl 4(%eax), %eax 5497; X86-NOBMI-NEXT: movl %eax, %edi 5498; X86-NOBMI-NEXT: shrl %cl, %edi 5499; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 5500; X86-NOBMI-NEXT: testb $32, %cl 5501; X86-NOBMI-NEXT: je .LBB44_2 5502; X86-NOBMI-NEXT: # %bb.1: 5503; X86-NOBMI-NEXT: movl %edi, %esi 5504; X86-NOBMI-NEXT: xorl %edi, %edi 5505; X86-NOBMI-NEXT: .LBB44_2: 5506; X86-NOBMI-NEXT: movb $64, %cl 5507; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 5508; X86-NOBMI-NEXT: movl $-1, %ebp 5509; X86-NOBMI-NEXT: movl $-1, %ebx 5510; X86-NOBMI-NEXT: shrl %cl, %ebx 5511; X86-NOBMI-NEXT: testb $32, %cl 5512; X86-NOBMI-NEXT: je .LBB44_4 5513; X86-NOBMI-NEXT: # %bb.3: 5514; X86-NOBMI-NEXT: movl %ebx, %ebp 5515; X86-NOBMI-NEXT: xorl %ebx, %ebx 5516; X86-NOBMI-NEXT: .LBB44_4: 5517; X86-NOBMI-NEXT: subl $8, %esp 5518; X86-NOBMI-NEXT: pushl %ebx 5519; X86-NOBMI-NEXT: pushl %ebp 5520; X86-NOBMI-NEXT: calll use64 5521; X86-NOBMI-NEXT: addl $16, %esp 5522; X86-NOBMI-NEXT: andl %ebp, %esi 5523; X86-NOBMI-NEXT: andl %ebx, %edi 5524; X86-NOBMI-NEXT: movl %esi, %eax 5525; X86-NOBMI-NEXT: movl %edi, %edx 5526; X86-NOBMI-NEXT: addl $12, %esp 5527; X86-NOBMI-NEXT: popl %esi 5528; X86-NOBMI-NEXT: popl %edi 5529; X86-NOBMI-NEXT: popl %ebx 5530; X86-NOBMI-NEXT: popl %ebp 5531; X86-NOBMI-NEXT: retl 5532; 5533; X86-BMI1NOTBM-LABEL: bextr64_c3_load_indexzext: 5534; X86-BMI1NOTBM: # %bb.0: 5535; X86-BMI1NOTBM-NEXT: pushl %ebp 5536; X86-BMI1NOTBM-NEXT: pushl %ebx 5537; X86-BMI1NOTBM-NEXT: pushl %edi 5538; X86-BMI1NOTBM-NEXT: pushl %esi 5539; X86-BMI1NOTBM-NEXT: subl $12, %esp 5540; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 5541; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 5542; X86-BMI1NOTBM-NEXT: movl (%eax), %esi 5543; X86-BMI1NOTBM-NEXT: movl 4(%eax), %eax 5544; X86-BMI1NOTBM-NEXT: movl %eax, %edi 5545; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 5546; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 5547; X86-BMI1NOTBM-NEXT: testb $32, %cl 5548; X86-BMI1NOTBM-NEXT: je .LBB44_2 5549; X86-BMI1NOTBM-NEXT: # %bb.1: 5550; X86-BMI1NOTBM-NEXT: movl %edi, %esi 5551; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 5552; X86-BMI1NOTBM-NEXT: .LBB44_2: 5553; X86-BMI1NOTBM-NEXT: movb $64, %cl 5554; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 5555; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 5556; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 5557; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx 5558; X86-BMI1NOTBM-NEXT: testb $32, %cl 5559; X86-BMI1NOTBM-NEXT: je .LBB44_4 5560; X86-BMI1NOTBM-NEXT: # %bb.3: 5561; X86-BMI1NOTBM-NEXT: movl %ebx, %ebp 5562; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 5563; X86-BMI1NOTBM-NEXT: .LBB44_4: 5564; X86-BMI1NOTBM-NEXT: subl $8, %esp 5565; X86-BMI1NOTBM-NEXT: pushl %ebx 5566; X86-BMI1NOTBM-NEXT: pushl %ebp 5567; X86-BMI1NOTBM-NEXT: calll use64 5568; X86-BMI1NOTBM-NEXT: addl $16, %esp 5569; X86-BMI1NOTBM-NEXT: andl %ebp, %esi 5570; X86-BMI1NOTBM-NEXT: andl %ebx, %edi 5571; X86-BMI1NOTBM-NEXT: movl %esi, %eax 5572; X86-BMI1NOTBM-NEXT: movl %edi, %edx 5573; X86-BMI1NOTBM-NEXT: addl $12, %esp 5574; X86-BMI1NOTBM-NEXT: popl %esi 5575; X86-BMI1NOTBM-NEXT: popl %edi 5576; X86-BMI1NOTBM-NEXT: popl %ebx 5577; X86-BMI1NOTBM-NEXT: popl %ebp 5578; X86-BMI1NOTBM-NEXT: retl 5579; 5580; X86-BMI1BMI2-LABEL: bextr64_c3_load_indexzext: 5581; X86-BMI1BMI2: # %bb.0: 5582; X86-BMI1BMI2-NEXT: pushl %ebp 5583; X86-BMI1BMI2-NEXT: pushl %ebx 5584; X86-BMI1BMI2-NEXT: pushl %edi 5585; X86-BMI1BMI2-NEXT: pushl %esi 5586; X86-BMI1BMI2-NEXT: subl $12, %esp 5587; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 5588; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 5589; X86-BMI1BMI2-NEXT: movl (%eax), %esi 5590; X86-BMI1BMI2-NEXT: movl 4(%eax), %eax 5591; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 5592; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 5593; X86-BMI1BMI2-NEXT: testb $32, %cl 5594; X86-BMI1BMI2-NEXT: je .LBB44_2 5595; X86-BMI1BMI2-NEXT: # %bb.1: 5596; X86-BMI1BMI2-NEXT: movl %edi, %esi 5597; X86-BMI1BMI2-NEXT: xorl %edi, %edi 5598; X86-BMI1BMI2-NEXT: .LBB44_2: 5599; X86-BMI1BMI2-NEXT: movb $64, %al 5600; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %al 5601; X86-BMI1BMI2-NEXT: movl $-1, %ebp 5602; X86-BMI1BMI2-NEXT: shrxl %eax, %ebp, %ebx 5603; X86-BMI1BMI2-NEXT: testb $32, %al 5604; X86-BMI1BMI2-NEXT: je .LBB44_4 5605; X86-BMI1BMI2-NEXT: # %bb.3: 5606; X86-BMI1BMI2-NEXT: movl %ebx, %ebp 5607; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx 5608; X86-BMI1BMI2-NEXT: .LBB44_4: 5609; X86-BMI1BMI2-NEXT: subl $8, %esp 5610; X86-BMI1BMI2-NEXT: pushl %ebx 5611; X86-BMI1BMI2-NEXT: pushl %ebp 5612; X86-BMI1BMI2-NEXT: calll use64 5613; X86-BMI1BMI2-NEXT: addl $16, %esp 5614; X86-BMI1BMI2-NEXT: andl %ebp, %esi 5615; X86-BMI1BMI2-NEXT: andl %ebx, %edi 5616; X86-BMI1BMI2-NEXT: movl %esi, %eax 5617; X86-BMI1BMI2-NEXT: movl %edi, %edx 5618; X86-BMI1BMI2-NEXT: addl $12, %esp 5619; X86-BMI1BMI2-NEXT: popl %esi 5620; X86-BMI1BMI2-NEXT: popl %edi 5621; X86-BMI1BMI2-NEXT: popl %ebx 5622; X86-BMI1BMI2-NEXT: popl %ebp 5623; X86-BMI1BMI2-NEXT: retl 5624; 5625; X64-NOBMI-LABEL: bextr64_c3_load_indexzext: 5626; X64-NOBMI: # %bb.0: 5627; X64-NOBMI-NEXT: pushq %r14 5628; X64-NOBMI-NEXT: pushq %rbx 5629; X64-NOBMI-NEXT: pushq %rax 5630; X64-NOBMI-NEXT: movl %esi, %ecx 5631; X64-NOBMI-NEXT: movq (%rdi), %r14 5632; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 5633; X64-NOBMI-NEXT: shrq %cl, %r14 5634; X64-NOBMI-NEXT: negb %dl 5635; X64-NOBMI-NEXT: movq $-1, %rbx 5636; X64-NOBMI-NEXT: movl %edx, %ecx 5637; X64-NOBMI-NEXT: shrq %cl, %rbx 5638; X64-NOBMI-NEXT: movq %rbx, %rdi 5639; X64-NOBMI-NEXT: callq use64 5640; X64-NOBMI-NEXT: andq %r14, %rbx 5641; X64-NOBMI-NEXT: movq %rbx, %rax 5642; X64-NOBMI-NEXT: addq $8, %rsp 5643; X64-NOBMI-NEXT: popq %rbx 5644; X64-NOBMI-NEXT: popq %r14 5645; X64-NOBMI-NEXT: retq 5646; 5647; X64-BMI1NOTBM-LABEL: bextr64_c3_load_indexzext: 5648; X64-BMI1NOTBM: # %bb.0: 5649; X64-BMI1NOTBM-NEXT: pushq %r14 5650; X64-BMI1NOTBM-NEXT: pushq %rbx 5651; X64-BMI1NOTBM-NEXT: pushq %rax 5652; X64-BMI1NOTBM-NEXT: movl %esi, %ecx 5653; X64-BMI1NOTBM-NEXT: movq (%rdi), %r14 5654; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx 5655; X64-BMI1NOTBM-NEXT: shrq %cl, %r14 5656; X64-BMI1NOTBM-NEXT: negb %dl 5657; X64-BMI1NOTBM-NEXT: movq $-1, %rbx 5658; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 5659; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 5660; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi 5661; X64-BMI1NOTBM-NEXT: callq use64 5662; X64-BMI1NOTBM-NEXT: andq %r14, %rbx 5663; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 5664; X64-BMI1NOTBM-NEXT: addq $8, %rsp 5665; X64-BMI1NOTBM-NEXT: popq %rbx 5666; X64-BMI1NOTBM-NEXT: popq %r14 5667; X64-BMI1NOTBM-NEXT: retq 5668; 5669; X64-BMI1BMI2-LABEL: bextr64_c3_load_indexzext: 5670; X64-BMI1BMI2: # %bb.0: 5671; X64-BMI1BMI2-NEXT: pushq %r14 5672; X64-BMI1BMI2-NEXT: pushq %rbx 5673; X64-BMI1BMI2-NEXT: pushq %rax 5674; X64-BMI1BMI2-NEXT: movl %edx, %ebx 5675; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 5676; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %r14 5677; X64-BMI1BMI2-NEXT: movl %ebx, %eax 5678; X64-BMI1BMI2-NEXT: negb %al 5679; X64-BMI1BMI2-NEXT: movq $-1, %rcx 5680; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi 5681; X64-BMI1BMI2-NEXT: callq use64 5682; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax 5683; X64-BMI1BMI2-NEXT: addq $8, %rsp 5684; X64-BMI1BMI2-NEXT: popq %rbx 5685; X64-BMI1BMI2-NEXT: popq %r14 5686; X64-BMI1BMI2-NEXT: retq 5687 %val = load i64, i64* %w 5688 %skip = zext i8 %numskipbits to i64 5689 %shifted = lshr i64 %val, %skip 5690 %numhighbits = sub i8 64, %numlowbits 5691 %sh_prom = zext i8 %numhighbits to i64 5692 %mask = lshr i64 -1, %sh_prom 5693 call void @use64(i64 %mask) 5694 %masked = and i64 %mask, %shifted 5695 ret i64 %masked 5696} 5697 5698define i64 @bextr64_c4_commutative(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 5699; X86-NOBMI-LABEL: bextr64_c4_commutative: 5700; X86-NOBMI: # %bb.0: 5701; X86-NOBMI-NEXT: pushl %ebp 5702; X86-NOBMI-NEXT: pushl %ebx 5703; X86-NOBMI-NEXT: pushl %edi 5704; X86-NOBMI-NEXT: pushl %esi 5705; X86-NOBMI-NEXT: subl $12, %esp 5706; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 5707; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 5708; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 5709; X86-NOBMI-NEXT: movl %eax, %edi 5710; X86-NOBMI-NEXT: shrl %cl, %edi 5711; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 5712; X86-NOBMI-NEXT: testb $32, %cl 5713; X86-NOBMI-NEXT: je .LBB45_2 5714; X86-NOBMI-NEXT: # %bb.1: 5715; X86-NOBMI-NEXT: movl %edi, %esi 5716; X86-NOBMI-NEXT: xorl %edi, %edi 5717; X86-NOBMI-NEXT: .LBB45_2: 5718; X86-NOBMI-NEXT: movb $64, %cl 5719; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 5720; X86-NOBMI-NEXT: movl $-1, %ebp 5721; X86-NOBMI-NEXT: movl $-1, %ebx 5722; X86-NOBMI-NEXT: shrl %cl, %ebx 5723; X86-NOBMI-NEXT: testb $32, %cl 5724; X86-NOBMI-NEXT: je .LBB45_4 5725; X86-NOBMI-NEXT: # %bb.3: 5726; X86-NOBMI-NEXT: movl %ebx, %ebp 5727; X86-NOBMI-NEXT: xorl %ebx, %ebx 5728; X86-NOBMI-NEXT: .LBB45_4: 5729; X86-NOBMI-NEXT: subl $8, %esp 5730; X86-NOBMI-NEXT: pushl %ebx 5731; X86-NOBMI-NEXT: pushl %ebp 5732; X86-NOBMI-NEXT: calll use64 5733; X86-NOBMI-NEXT: addl $16, %esp 5734; X86-NOBMI-NEXT: andl %ebp, %esi 5735; X86-NOBMI-NEXT: andl %ebx, %edi 5736; X86-NOBMI-NEXT: movl %esi, %eax 5737; X86-NOBMI-NEXT: movl %edi, %edx 5738; X86-NOBMI-NEXT: addl $12, %esp 5739; X86-NOBMI-NEXT: popl %esi 5740; X86-NOBMI-NEXT: popl %edi 5741; X86-NOBMI-NEXT: popl %ebx 5742; X86-NOBMI-NEXT: popl %ebp 5743; X86-NOBMI-NEXT: retl 5744; 5745; X86-BMI1NOTBM-LABEL: bextr64_c4_commutative: 5746; X86-BMI1NOTBM: # %bb.0: 5747; X86-BMI1NOTBM-NEXT: pushl %ebp 5748; X86-BMI1NOTBM-NEXT: pushl %ebx 5749; X86-BMI1NOTBM-NEXT: pushl %edi 5750; X86-BMI1NOTBM-NEXT: pushl %esi 5751; X86-BMI1NOTBM-NEXT: subl $12, %esp 5752; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 5753; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 5754; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 5755; X86-BMI1NOTBM-NEXT: movl %eax, %edi 5756; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 5757; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 5758; X86-BMI1NOTBM-NEXT: testb $32, %cl 5759; X86-BMI1NOTBM-NEXT: je .LBB45_2 5760; X86-BMI1NOTBM-NEXT: # %bb.1: 5761; X86-BMI1NOTBM-NEXT: movl %edi, %esi 5762; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 5763; X86-BMI1NOTBM-NEXT: .LBB45_2: 5764; X86-BMI1NOTBM-NEXT: movb $64, %cl 5765; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 5766; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 5767; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 5768; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx 5769; X86-BMI1NOTBM-NEXT: testb $32, %cl 5770; X86-BMI1NOTBM-NEXT: je .LBB45_4 5771; X86-BMI1NOTBM-NEXT: # %bb.3: 5772; X86-BMI1NOTBM-NEXT: movl %ebx, %ebp 5773; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx 5774; X86-BMI1NOTBM-NEXT: .LBB45_4: 5775; X86-BMI1NOTBM-NEXT: subl $8, %esp 5776; X86-BMI1NOTBM-NEXT: pushl %ebx 5777; X86-BMI1NOTBM-NEXT: pushl %ebp 5778; X86-BMI1NOTBM-NEXT: calll use64 5779; X86-BMI1NOTBM-NEXT: addl $16, %esp 5780; X86-BMI1NOTBM-NEXT: andl %ebp, %esi 5781; X86-BMI1NOTBM-NEXT: andl %ebx, %edi 5782; X86-BMI1NOTBM-NEXT: movl %esi, %eax 5783; X86-BMI1NOTBM-NEXT: movl %edi, %edx 5784; X86-BMI1NOTBM-NEXT: addl $12, %esp 5785; X86-BMI1NOTBM-NEXT: popl %esi 5786; X86-BMI1NOTBM-NEXT: popl %edi 5787; X86-BMI1NOTBM-NEXT: popl %ebx 5788; X86-BMI1NOTBM-NEXT: popl %ebp 5789; X86-BMI1NOTBM-NEXT: retl 5790; 5791; X86-BMI1BMI2-LABEL: bextr64_c4_commutative: 5792; X86-BMI1BMI2: # %bb.0: 5793; X86-BMI1BMI2-NEXT: pushl %ebp 5794; X86-BMI1BMI2-NEXT: pushl %ebx 5795; X86-BMI1BMI2-NEXT: pushl %edi 5796; X86-BMI1BMI2-NEXT: pushl %esi 5797; X86-BMI1BMI2-NEXT: subl $12, %esp 5798; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 5799; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 5800; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 5801; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 5802; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 5803; X86-BMI1BMI2-NEXT: testb $32, %cl 5804; X86-BMI1BMI2-NEXT: je .LBB45_2 5805; X86-BMI1BMI2-NEXT: # %bb.1: 5806; X86-BMI1BMI2-NEXT: movl %edi, %esi 5807; X86-BMI1BMI2-NEXT: xorl %edi, %edi 5808; X86-BMI1BMI2-NEXT: .LBB45_2: 5809; X86-BMI1BMI2-NEXT: movb $64, %al 5810; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %al 5811; X86-BMI1BMI2-NEXT: movl $-1, %ebp 5812; X86-BMI1BMI2-NEXT: shrxl %eax, %ebp, %ebx 5813; X86-BMI1BMI2-NEXT: testb $32, %al 5814; X86-BMI1BMI2-NEXT: je .LBB45_4 5815; X86-BMI1BMI2-NEXT: # %bb.3: 5816; X86-BMI1BMI2-NEXT: movl %ebx, %ebp 5817; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx 5818; X86-BMI1BMI2-NEXT: .LBB45_4: 5819; X86-BMI1BMI2-NEXT: subl $8, %esp 5820; X86-BMI1BMI2-NEXT: pushl %ebx 5821; X86-BMI1BMI2-NEXT: pushl %ebp 5822; X86-BMI1BMI2-NEXT: calll use64 5823; X86-BMI1BMI2-NEXT: addl $16, %esp 5824; X86-BMI1BMI2-NEXT: andl %ebp, %esi 5825; X86-BMI1BMI2-NEXT: andl %ebx, %edi 5826; X86-BMI1BMI2-NEXT: movl %esi, %eax 5827; X86-BMI1BMI2-NEXT: movl %edi, %edx 5828; X86-BMI1BMI2-NEXT: addl $12, %esp 5829; X86-BMI1BMI2-NEXT: popl %esi 5830; X86-BMI1BMI2-NEXT: popl %edi 5831; X86-BMI1BMI2-NEXT: popl %ebx 5832; X86-BMI1BMI2-NEXT: popl %ebp 5833; X86-BMI1BMI2-NEXT: retl 5834; 5835; X64-NOBMI-LABEL: bextr64_c4_commutative: 5836; X64-NOBMI: # %bb.0: 5837; X64-NOBMI-NEXT: pushq %r14 5838; X64-NOBMI-NEXT: pushq %rbx 5839; X64-NOBMI-NEXT: pushq %rax 5840; X64-NOBMI-NEXT: movq %rsi, %rcx 5841; X64-NOBMI-NEXT: movq %rdi, %r14 5842; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 5843; X64-NOBMI-NEXT: shrq %cl, %r14 5844; X64-NOBMI-NEXT: negb %dl 5845; X64-NOBMI-NEXT: movq $-1, %rbx 5846; X64-NOBMI-NEXT: movl %edx, %ecx 5847; X64-NOBMI-NEXT: shrq %cl, %rbx 5848; X64-NOBMI-NEXT: movq %rbx, %rdi 5849; X64-NOBMI-NEXT: callq use64 5850; X64-NOBMI-NEXT: andq %r14, %rbx 5851; X64-NOBMI-NEXT: movq %rbx, %rax 5852; X64-NOBMI-NEXT: addq $8, %rsp 5853; X64-NOBMI-NEXT: popq %rbx 5854; X64-NOBMI-NEXT: popq %r14 5855; X64-NOBMI-NEXT: retq 5856; 5857; X64-BMI1NOTBM-LABEL: bextr64_c4_commutative: 5858; X64-BMI1NOTBM: # %bb.0: 5859; X64-BMI1NOTBM-NEXT: pushq %r14 5860; X64-BMI1NOTBM-NEXT: pushq %rbx 5861; X64-BMI1NOTBM-NEXT: pushq %rax 5862; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx 5863; X64-BMI1NOTBM-NEXT: movq %rdi, %r14 5864; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx 5865; X64-BMI1NOTBM-NEXT: shrq %cl, %r14 5866; X64-BMI1NOTBM-NEXT: negb %dl 5867; X64-BMI1NOTBM-NEXT: movq $-1, %rbx 5868; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 5869; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 5870; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi 5871; X64-BMI1NOTBM-NEXT: callq use64 5872; X64-BMI1NOTBM-NEXT: andq %r14, %rbx 5873; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 5874; X64-BMI1NOTBM-NEXT: addq $8, %rsp 5875; X64-BMI1NOTBM-NEXT: popq %rbx 5876; X64-BMI1NOTBM-NEXT: popq %r14 5877; X64-BMI1NOTBM-NEXT: retq 5878; 5879; X64-BMI1BMI2-LABEL: bextr64_c4_commutative: 5880; X64-BMI1BMI2: # %bb.0: 5881; X64-BMI1BMI2-NEXT: pushq %r14 5882; X64-BMI1BMI2-NEXT: pushq %rbx 5883; X64-BMI1BMI2-NEXT: pushq %rax 5884; X64-BMI1BMI2-NEXT: movq %rdx, %rbx 5885; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %r14 5886; X64-BMI1BMI2-NEXT: movl %ebx, %eax 5887; X64-BMI1BMI2-NEXT: negb %al 5888; X64-BMI1BMI2-NEXT: movq $-1, %rcx 5889; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi 5890; X64-BMI1BMI2-NEXT: callq use64 5891; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax 5892; X64-BMI1BMI2-NEXT: addq $8, %rsp 5893; X64-BMI1BMI2-NEXT: popq %rbx 5894; X64-BMI1BMI2-NEXT: popq %r14 5895; X64-BMI1BMI2-NEXT: retq 5896 %shifted = lshr i64 %val, %numskipbits 5897 %numhighbits = sub i64 64, %numlowbits 5898 %mask = lshr i64 -1, %numhighbits 5899 call void @use64(i64 %mask) 5900 %masked = and i64 %shifted, %mask ; swapped order 5901 ret i64 %masked 5902} 5903 5904define i64 @bextr64_c5_skipextrauses(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 5905; X86-NOBMI-LABEL: bextr64_c5_skipextrauses: 5906; X86-NOBMI: # %bb.0: 5907; X86-NOBMI-NEXT: pushl %ebp 5908; X86-NOBMI-NEXT: pushl %ebx 5909; X86-NOBMI-NEXT: pushl %edi 5910; X86-NOBMI-NEXT: pushl %esi 5911; X86-NOBMI-NEXT: subl $12, %esp 5912; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 5913; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 5914; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 5915; X86-NOBMI-NEXT: movl %eax, %edi 5916; X86-NOBMI-NEXT: shrl %cl, %edi 5917; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 5918; X86-NOBMI-NEXT: testb $32, %cl 5919; X86-NOBMI-NEXT: je .LBB46_2 5920; X86-NOBMI-NEXT: # %bb.1: 5921; X86-NOBMI-NEXT: movl %edi, %esi 5922; X86-NOBMI-NEXT: xorl %edi, %edi 5923; X86-NOBMI-NEXT: .LBB46_2: 5924; X86-NOBMI-NEXT: movb $64, %cl 5925; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 5926; X86-NOBMI-NEXT: movl $-1, %ebx 5927; X86-NOBMI-NEXT: movl $-1, %ebp 5928; X86-NOBMI-NEXT: shrl %cl, %ebp 5929; X86-NOBMI-NEXT: testb $32, %cl 5930; X86-NOBMI-NEXT: je .LBB46_4 5931; X86-NOBMI-NEXT: # %bb.3: 5932; X86-NOBMI-NEXT: movl %ebp, %ebx 5933; X86-NOBMI-NEXT: xorl %ebp, %ebp 5934; X86-NOBMI-NEXT: .LBB46_4: 5935; X86-NOBMI-NEXT: subl $8, %esp 5936; X86-NOBMI-NEXT: pushl %ebp 5937; X86-NOBMI-NEXT: pushl %ebx 5938; X86-NOBMI-NEXT: calll use64 5939; X86-NOBMI-NEXT: addl $16, %esp 5940; X86-NOBMI-NEXT: andl %ebx, %esi 5941; X86-NOBMI-NEXT: andl %ebp, %edi 5942; X86-NOBMI-NEXT: subl $8, %esp 5943; X86-NOBMI-NEXT: pushl {{[0-9]+}}(%esp) 5944; X86-NOBMI-NEXT: pushl {{[0-9]+}}(%esp) 5945; X86-NOBMI-NEXT: calll use64 5946; X86-NOBMI-NEXT: addl $16, %esp 5947; X86-NOBMI-NEXT: movl %esi, %eax 5948; X86-NOBMI-NEXT: movl %edi, %edx 5949; X86-NOBMI-NEXT: addl $12, %esp 5950; X86-NOBMI-NEXT: popl %esi 5951; X86-NOBMI-NEXT: popl %edi 5952; X86-NOBMI-NEXT: popl %ebx 5953; X86-NOBMI-NEXT: popl %ebp 5954; X86-NOBMI-NEXT: retl 5955; 5956; X86-BMI1NOTBM-LABEL: bextr64_c5_skipextrauses: 5957; X86-BMI1NOTBM: # %bb.0: 5958; X86-BMI1NOTBM-NEXT: pushl %ebp 5959; X86-BMI1NOTBM-NEXT: pushl %ebx 5960; X86-BMI1NOTBM-NEXT: pushl %edi 5961; X86-BMI1NOTBM-NEXT: pushl %esi 5962; X86-BMI1NOTBM-NEXT: subl $12, %esp 5963; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 5964; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 5965; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ecx 5966; X86-BMI1NOTBM-NEXT: movl %eax, %edi 5967; X86-BMI1NOTBM-NEXT: shrl %cl, %edi 5968; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 5969; X86-BMI1NOTBM-NEXT: testb $32, %cl 5970; X86-BMI1NOTBM-NEXT: je .LBB46_2 5971; X86-BMI1NOTBM-NEXT: # %bb.1: 5972; X86-BMI1NOTBM-NEXT: movl %edi, %esi 5973; X86-BMI1NOTBM-NEXT: xorl %edi, %edi 5974; X86-BMI1NOTBM-NEXT: .LBB46_2: 5975; X86-BMI1NOTBM-NEXT: movb $64, %cl 5976; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 5977; X86-BMI1NOTBM-NEXT: movl $-1, %ebx 5978; X86-BMI1NOTBM-NEXT: movl $-1, %ebp 5979; X86-BMI1NOTBM-NEXT: shrl %cl, %ebp 5980; X86-BMI1NOTBM-NEXT: testb $32, %cl 5981; X86-BMI1NOTBM-NEXT: je .LBB46_4 5982; X86-BMI1NOTBM-NEXT: # %bb.3: 5983; X86-BMI1NOTBM-NEXT: movl %ebp, %ebx 5984; X86-BMI1NOTBM-NEXT: xorl %ebp, %ebp 5985; X86-BMI1NOTBM-NEXT: .LBB46_4: 5986; X86-BMI1NOTBM-NEXT: subl $8, %esp 5987; X86-BMI1NOTBM-NEXT: pushl %ebp 5988; X86-BMI1NOTBM-NEXT: pushl %ebx 5989; X86-BMI1NOTBM-NEXT: calll use64 5990; X86-BMI1NOTBM-NEXT: addl $16, %esp 5991; X86-BMI1NOTBM-NEXT: andl %ebx, %esi 5992; X86-BMI1NOTBM-NEXT: andl %ebp, %edi 5993; X86-BMI1NOTBM-NEXT: subl $8, %esp 5994; X86-BMI1NOTBM-NEXT: pushl {{[0-9]+}}(%esp) 5995; X86-BMI1NOTBM-NEXT: pushl {{[0-9]+}}(%esp) 5996; X86-BMI1NOTBM-NEXT: calll use64 5997; X86-BMI1NOTBM-NEXT: addl $16, %esp 5998; X86-BMI1NOTBM-NEXT: movl %esi, %eax 5999; X86-BMI1NOTBM-NEXT: movl %edi, %edx 6000; X86-BMI1NOTBM-NEXT: addl $12, %esp 6001; X86-BMI1NOTBM-NEXT: popl %esi 6002; X86-BMI1NOTBM-NEXT: popl %edi 6003; X86-BMI1NOTBM-NEXT: popl %ebx 6004; X86-BMI1NOTBM-NEXT: popl %ebp 6005; X86-BMI1NOTBM-NEXT: retl 6006; 6007; X86-BMI1BMI2-LABEL: bextr64_c5_skipextrauses: 6008; X86-BMI1BMI2: # %bb.0: 6009; X86-BMI1BMI2-NEXT: pushl %ebp 6010; X86-BMI1BMI2-NEXT: pushl %ebx 6011; X86-BMI1BMI2-NEXT: pushl %edi 6012; X86-BMI1BMI2-NEXT: pushl %esi 6013; X86-BMI1BMI2-NEXT: subl $12, %esp 6014; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 6015; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 6016; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 6017; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 6018; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edi 6019; X86-BMI1BMI2-NEXT: testb $32, %cl 6020; X86-BMI1BMI2-NEXT: je .LBB46_2 6021; X86-BMI1BMI2-NEXT: # %bb.1: 6022; X86-BMI1BMI2-NEXT: movl %edi, %esi 6023; X86-BMI1BMI2-NEXT: xorl %edi, %edi 6024; X86-BMI1BMI2-NEXT: .LBB46_2: 6025; X86-BMI1BMI2-NEXT: movb $64, %al 6026; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %al 6027; X86-BMI1BMI2-NEXT: movl $-1, %ebp 6028; X86-BMI1BMI2-NEXT: shrxl %eax, %ebp, %ebx 6029; X86-BMI1BMI2-NEXT: testb $32, %al 6030; X86-BMI1BMI2-NEXT: je .LBB46_4 6031; X86-BMI1BMI2-NEXT: # %bb.3: 6032; X86-BMI1BMI2-NEXT: movl %ebx, %ebp 6033; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx 6034; X86-BMI1BMI2-NEXT: .LBB46_4: 6035; X86-BMI1BMI2-NEXT: subl $8, %esp 6036; X86-BMI1BMI2-NEXT: pushl %ebx 6037; X86-BMI1BMI2-NEXT: pushl %ebp 6038; X86-BMI1BMI2-NEXT: calll use64 6039; X86-BMI1BMI2-NEXT: addl $16, %esp 6040; X86-BMI1BMI2-NEXT: andl %ebp, %esi 6041; X86-BMI1BMI2-NEXT: andl %ebx, %edi 6042; X86-BMI1BMI2-NEXT: subl $8, %esp 6043; X86-BMI1BMI2-NEXT: pushl {{[0-9]+}}(%esp) 6044; X86-BMI1BMI2-NEXT: pushl {{[0-9]+}}(%esp) 6045; X86-BMI1BMI2-NEXT: calll use64 6046; X86-BMI1BMI2-NEXT: addl $16, %esp 6047; X86-BMI1BMI2-NEXT: movl %esi, %eax 6048; X86-BMI1BMI2-NEXT: movl %edi, %edx 6049; X86-BMI1BMI2-NEXT: addl $12, %esp 6050; X86-BMI1BMI2-NEXT: popl %esi 6051; X86-BMI1BMI2-NEXT: popl %edi 6052; X86-BMI1BMI2-NEXT: popl %ebx 6053; X86-BMI1BMI2-NEXT: popl %ebp 6054; X86-BMI1BMI2-NEXT: retl 6055; 6056; X64-NOBMI-LABEL: bextr64_c5_skipextrauses: 6057; X64-NOBMI: # %bb.0: 6058; X64-NOBMI-NEXT: pushq %r15 6059; X64-NOBMI-NEXT: pushq %r14 6060; X64-NOBMI-NEXT: pushq %rbx 6061; X64-NOBMI-NEXT: movq %rsi, %r14 6062; X64-NOBMI-NEXT: movq %rdi, %r15 6063; X64-NOBMI-NEXT: movl %r14d, %ecx 6064; X64-NOBMI-NEXT: shrq %cl, %r15 6065; X64-NOBMI-NEXT: negb %dl 6066; X64-NOBMI-NEXT: movq $-1, %rbx 6067; X64-NOBMI-NEXT: movl %edx, %ecx 6068; X64-NOBMI-NEXT: shrq %cl, %rbx 6069; X64-NOBMI-NEXT: movq %rbx, %rdi 6070; X64-NOBMI-NEXT: callq use64 6071; X64-NOBMI-NEXT: andq %r15, %rbx 6072; X64-NOBMI-NEXT: movq %r14, %rdi 6073; X64-NOBMI-NEXT: callq use64 6074; X64-NOBMI-NEXT: movq %rbx, %rax 6075; X64-NOBMI-NEXT: popq %rbx 6076; X64-NOBMI-NEXT: popq %r14 6077; X64-NOBMI-NEXT: popq %r15 6078; X64-NOBMI-NEXT: retq 6079; 6080; X64-BMI1NOTBM-LABEL: bextr64_c5_skipextrauses: 6081; X64-BMI1NOTBM: # %bb.0: 6082; X64-BMI1NOTBM-NEXT: pushq %r15 6083; X64-BMI1NOTBM-NEXT: pushq %r14 6084; X64-BMI1NOTBM-NEXT: pushq %rbx 6085; X64-BMI1NOTBM-NEXT: movq %rsi, %r14 6086; X64-BMI1NOTBM-NEXT: movq %rdi, %r15 6087; X64-BMI1NOTBM-NEXT: movl %r14d, %ecx 6088; X64-BMI1NOTBM-NEXT: shrq %cl, %r15 6089; X64-BMI1NOTBM-NEXT: negb %dl 6090; X64-BMI1NOTBM-NEXT: movq $-1, %rbx 6091; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 6092; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx 6093; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi 6094; X64-BMI1NOTBM-NEXT: callq use64 6095; X64-BMI1NOTBM-NEXT: andq %r15, %rbx 6096; X64-BMI1NOTBM-NEXT: movq %r14, %rdi 6097; X64-BMI1NOTBM-NEXT: callq use64 6098; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 6099; X64-BMI1NOTBM-NEXT: popq %rbx 6100; X64-BMI1NOTBM-NEXT: popq %r14 6101; X64-BMI1NOTBM-NEXT: popq %r15 6102; X64-BMI1NOTBM-NEXT: retq 6103; 6104; X64-BMI1BMI2-LABEL: bextr64_c5_skipextrauses: 6105; X64-BMI1BMI2: # %bb.0: 6106; X64-BMI1BMI2-NEXT: pushq %r15 6107; X64-BMI1BMI2-NEXT: pushq %r14 6108; X64-BMI1BMI2-NEXT: pushq %rbx 6109; X64-BMI1BMI2-NEXT: movq %rdx, %rbx 6110; X64-BMI1BMI2-NEXT: movq %rsi, %r14 6111; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %r15 6112; X64-BMI1BMI2-NEXT: movl %ebx, %eax 6113; X64-BMI1BMI2-NEXT: negb %al 6114; X64-BMI1BMI2-NEXT: movq $-1, %rcx 6115; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi 6116; X64-BMI1BMI2-NEXT: callq use64 6117; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r15, %rbx 6118; X64-BMI1BMI2-NEXT: movq %r14, %rdi 6119; X64-BMI1BMI2-NEXT: callq use64 6120; X64-BMI1BMI2-NEXT: movq %rbx, %rax 6121; X64-BMI1BMI2-NEXT: popq %rbx 6122; X64-BMI1BMI2-NEXT: popq %r14 6123; X64-BMI1BMI2-NEXT: popq %r15 6124; X64-BMI1BMI2-NEXT: retq 6125 %shifted = lshr i64 %val, %numskipbits 6126 %numhighbits = sub i64 64, %numlowbits 6127 %mask = lshr i64 -1, %numhighbits 6128 call void @use64(i64 %mask) 6129 %masked = and i64 %mask, %shifted 6130 call void @use64(i64 %numskipbits) 6131 ret i64 %masked 6132} 6133 6134; 64-bit, but with 32-bit output 6135 6136; Everything done in 64-bit, truncation happens last. 6137define i32 @bextr64_32_c0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 6138; X86-NOBMI-LABEL: bextr64_32_c0: 6139; X86-NOBMI: # %bb.0: 6140; X86-NOBMI-NEXT: pushl %esi 6141; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6142; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6143; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 6144; X86-NOBMI-NEXT: movl %esi, %edx 6145; X86-NOBMI-NEXT: shrl %cl, %edx 6146; X86-NOBMI-NEXT: shrdl %cl, %esi, %eax 6147; X86-NOBMI-NEXT: testb $32, %cl 6148; X86-NOBMI-NEXT: jne .LBB47_2 6149; X86-NOBMI-NEXT: # %bb.1: 6150; X86-NOBMI-NEXT: movl %eax, %edx 6151; X86-NOBMI-NEXT: .LBB47_2: 6152; X86-NOBMI-NEXT: movb $64, %cl 6153; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6154; X86-NOBMI-NEXT: movl $-1, %eax 6155; X86-NOBMI-NEXT: shrl %cl, %eax 6156; X86-NOBMI-NEXT: testb $32, %cl 6157; X86-NOBMI-NEXT: jne .LBB47_4 6158; X86-NOBMI-NEXT: # %bb.3: 6159; X86-NOBMI-NEXT: movl $-1, %eax 6160; X86-NOBMI-NEXT: .LBB47_4: 6161; X86-NOBMI-NEXT: andl %edx, %eax 6162; X86-NOBMI-NEXT: popl %esi 6163; X86-NOBMI-NEXT: retl 6164; 6165; X86-BMI1NOTBM-LABEL: bextr64_32_c0: 6166; X86-BMI1NOTBM: # %bb.0: 6167; X86-BMI1NOTBM-NEXT: pushl %esi 6168; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6169; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 6170; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 6171; X86-BMI1NOTBM-NEXT: movl %esi, %edx 6172; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 6173; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %eax 6174; X86-BMI1NOTBM-NEXT: testb $32, %cl 6175; X86-BMI1NOTBM-NEXT: jne .LBB47_2 6176; X86-BMI1NOTBM-NEXT: # %bb.1: 6177; X86-BMI1NOTBM-NEXT: movl %eax, %edx 6178; X86-BMI1NOTBM-NEXT: .LBB47_2: 6179; X86-BMI1NOTBM-NEXT: movb $64, %cl 6180; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 6181; X86-BMI1NOTBM-NEXT: movl $-1, %eax 6182; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 6183; X86-BMI1NOTBM-NEXT: testb $32, %cl 6184; X86-BMI1NOTBM-NEXT: jne .LBB47_4 6185; X86-BMI1NOTBM-NEXT: # %bb.3: 6186; X86-BMI1NOTBM-NEXT: movl $-1, %eax 6187; X86-BMI1NOTBM-NEXT: .LBB47_4: 6188; X86-BMI1NOTBM-NEXT: andl %edx, %eax 6189; X86-BMI1NOTBM-NEXT: popl %esi 6190; X86-BMI1NOTBM-NEXT: retl 6191; 6192; X86-BMI1BMI2-LABEL: bextr64_32_c0: 6193; X86-BMI1BMI2: # %bb.0: 6194; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 6195; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 6196; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 6197; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %edx 6198; X86-BMI1BMI2-NEXT: testb $32, %cl 6199; X86-BMI1BMI2-NEXT: je .LBB47_2 6200; X86-BMI1BMI2-NEXT: # %bb.1: 6201; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edx 6202; X86-BMI1BMI2-NEXT: .LBB47_2: 6203; X86-BMI1BMI2-NEXT: movb $64, %cl 6204; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 6205; X86-BMI1BMI2-NEXT: movl $-1, %eax 6206; X86-BMI1BMI2-NEXT: testb $32, %cl 6207; X86-BMI1BMI2-NEXT: je .LBB47_4 6208; X86-BMI1BMI2-NEXT: # %bb.3: 6209; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %eax 6210; X86-BMI1BMI2-NEXT: .LBB47_4: 6211; X86-BMI1BMI2-NEXT: andl %edx, %eax 6212; X86-BMI1BMI2-NEXT: retl 6213; 6214; X64-NOBMI-LABEL: bextr64_32_c0: 6215; X64-NOBMI: # %bb.0: 6216; X64-NOBMI-NEXT: movq %rsi, %rcx 6217; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 6218; X64-NOBMI-NEXT: shrq %cl, %rdi 6219; X64-NOBMI-NEXT: negb %dl 6220; X64-NOBMI-NEXT: movq $-1, %rax 6221; X64-NOBMI-NEXT: movl %edx, %ecx 6222; X64-NOBMI-NEXT: shrq %cl, %rax 6223; X64-NOBMI-NEXT: andl %edi, %eax 6224; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 6225; X64-NOBMI-NEXT: retq 6226; 6227; X64-BMI1NOTBM-LABEL: bextr64_32_c0: 6228; X64-BMI1NOTBM: # %bb.0: 6229; X64-BMI1NOTBM-NEXT: shll $8, %edx 6230; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6231; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6232; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 6233; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 6234; X64-BMI1NOTBM-NEXT: retq 6235; 6236; X64-BMI1BMI2-LABEL: bextr64_32_c0: 6237; X64-BMI1BMI2: # %bb.0: 6238; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 6239; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6240; X64-BMI1BMI2-NEXT: retq 6241 %shifted = lshr i64 %val, %numskipbits 6242 %numhighbits = sub i64 64, %numlowbits 6243 %mask = lshr i64 -1, %numhighbits 6244 %masked = and i64 %mask, %shifted 6245 %res = trunc i64 %masked to i32 6246 ret i32 %res 6247} 6248 6249; Shifting happens in 64-bit, then truncation. Masking is 32-bit. 6250define i32 @bextr64_32_c1(i64 %val, i64 %numskipbits, i32 %numlowbits) nounwind { 6251; X86-NOBMI-LABEL: bextr64_32_c1: 6252; X86-NOBMI: # %bb.0: 6253; X86-NOBMI-NEXT: pushl %esi 6254; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6255; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 6256; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 6257; X86-NOBMI-NEXT: movl %esi, %eax 6258; X86-NOBMI-NEXT: shrl %cl, %eax 6259; X86-NOBMI-NEXT: shrdl %cl, %esi, %edx 6260; X86-NOBMI-NEXT: testb $32, %cl 6261; X86-NOBMI-NEXT: jne .LBB48_2 6262; X86-NOBMI-NEXT: # %bb.1: 6263; X86-NOBMI-NEXT: movl %edx, %eax 6264; X86-NOBMI-NEXT: .LBB48_2: 6265; X86-NOBMI-NEXT: xorl %ecx, %ecx 6266; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6267; X86-NOBMI-NEXT: shll %cl, %eax 6268; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6269; X86-NOBMI-NEXT: shrl %cl, %eax 6270; X86-NOBMI-NEXT: popl %esi 6271; X86-NOBMI-NEXT: retl 6272; 6273; X86-BMI1NOTBM-LABEL: bextr64_32_c1: 6274; X86-BMI1NOTBM: # %bb.0: 6275; X86-BMI1NOTBM-NEXT: pushl %edi 6276; X86-BMI1NOTBM-NEXT: pushl %esi 6277; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 6278; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6279; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 6280; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 6281; X86-BMI1NOTBM-NEXT: movl %edi, %edx 6282; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 6283; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 6284; X86-BMI1NOTBM-NEXT: testb $32, %cl 6285; X86-BMI1NOTBM-NEXT: jne .LBB48_2 6286; X86-BMI1NOTBM-NEXT: # %bb.1: 6287; X86-BMI1NOTBM-NEXT: movl %esi, %edx 6288; X86-BMI1NOTBM-NEXT: .LBB48_2: 6289; X86-BMI1NOTBM-NEXT: shll $8, %eax 6290; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 6291; X86-BMI1NOTBM-NEXT: popl %esi 6292; X86-BMI1NOTBM-NEXT: popl %edi 6293; X86-BMI1NOTBM-NEXT: retl 6294; 6295; X86-BMI1BMI2-LABEL: bextr64_32_c1: 6296; X86-BMI1BMI2: # %bb.0: 6297; X86-BMI1BMI2-NEXT: pushl %esi 6298; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6299; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 6300; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 6301; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 6302; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 6303; X86-BMI1BMI2-NEXT: testb $32, %cl 6304; X86-BMI1BMI2-NEXT: je .LBB48_2 6305; X86-BMI1BMI2-NEXT: # %bb.1: 6306; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 6307; X86-BMI1BMI2-NEXT: .LBB48_2: 6308; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 6309; X86-BMI1BMI2-NEXT: popl %esi 6310; X86-BMI1BMI2-NEXT: retl 6311; 6312; X64-NOBMI-LABEL: bextr64_32_c1: 6313; X64-NOBMI: # %bb.0: 6314; X64-NOBMI-NEXT: movq %rsi, %rcx 6315; X64-NOBMI-NEXT: movq %rdi, %rax 6316; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 6317; X64-NOBMI-NEXT: shrq %cl, %rax 6318; X64-NOBMI-NEXT: negb %dl 6319; X64-NOBMI-NEXT: movl %edx, %ecx 6320; X64-NOBMI-NEXT: shll %cl, %eax 6321; X64-NOBMI-NEXT: shrl %cl, %eax 6322; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 6323; X64-NOBMI-NEXT: retq 6324; 6325; X64-BMI1NOTBM-LABEL: bextr64_32_c1: 6326; X64-BMI1NOTBM: # %bb.0: 6327; X64-BMI1NOTBM-NEXT: shll $8, %edx 6328; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6329; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6330; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 6331; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 6332; X64-BMI1NOTBM-NEXT: retq 6333; 6334; X64-BMI1BMI2-LABEL: bextr64_32_c1: 6335; X64-BMI1BMI2: # %bb.0: 6336; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 6337; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6338; X64-BMI1BMI2-NEXT: retq 6339 %shifted = lshr i64 %val, %numskipbits 6340 %truncshifted = trunc i64 %shifted to i32 6341 %numhighbits = sub i32 32, %numlowbits 6342 %mask = lshr i32 -1, %numhighbits 6343 %masked = and i32 %mask, %truncshifted 6344 ret i32 %masked 6345} 6346 6347; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit. 6348; Masking is 64-bit. Then truncation. 6349define i32 @bextr64_32_c2(i64 %val, i64 %numskipbits, i32 %numlowbits) nounwind { 6350; X86-NOBMI-LABEL: bextr64_32_c2: 6351; X86-NOBMI: # %bb.0: 6352; X86-NOBMI-NEXT: pushl %esi 6353; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6354; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 6355; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 6356; X86-NOBMI-NEXT: movl %esi, %eax 6357; X86-NOBMI-NEXT: shrl %cl, %eax 6358; X86-NOBMI-NEXT: shrdl %cl, %esi, %edx 6359; X86-NOBMI-NEXT: testb $32, %cl 6360; X86-NOBMI-NEXT: jne .LBB49_2 6361; X86-NOBMI-NEXT: # %bb.1: 6362; X86-NOBMI-NEXT: movl %edx, %eax 6363; X86-NOBMI-NEXT: .LBB49_2: 6364; X86-NOBMI-NEXT: xorl %ecx, %ecx 6365; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6366; X86-NOBMI-NEXT: shll %cl, %eax 6367; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6368; X86-NOBMI-NEXT: shrl %cl, %eax 6369; X86-NOBMI-NEXT: popl %esi 6370; X86-NOBMI-NEXT: retl 6371; 6372; X86-BMI1NOTBM-LABEL: bextr64_32_c2: 6373; X86-BMI1NOTBM: # %bb.0: 6374; X86-BMI1NOTBM-NEXT: pushl %edi 6375; X86-BMI1NOTBM-NEXT: pushl %esi 6376; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 6377; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6378; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 6379; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 6380; X86-BMI1NOTBM-NEXT: movl %edi, %edx 6381; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 6382; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 6383; X86-BMI1NOTBM-NEXT: testb $32, %cl 6384; X86-BMI1NOTBM-NEXT: jne .LBB49_2 6385; X86-BMI1NOTBM-NEXT: # %bb.1: 6386; X86-BMI1NOTBM-NEXT: movl %esi, %edx 6387; X86-BMI1NOTBM-NEXT: .LBB49_2: 6388; X86-BMI1NOTBM-NEXT: shll $8, %eax 6389; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 6390; X86-BMI1NOTBM-NEXT: popl %esi 6391; X86-BMI1NOTBM-NEXT: popl %edi 6392; X86-BMI1NOTBM-NEXT: retl 6393; 6394; X86-BMI1BMI2-LABEL: bextr64_32_c2: 6395; X86-BMI1BMI2: # %bb.0: 6396; X86-BMI1BMI2-NEXT: pushl %esi 6397; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6398; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 6399; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 6400; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 6401; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 6402; X86-BMI1BMI2-NEXT: testb $32, %cl 6403; X86-BMI1BMI2-NEXT: je .LBB49_2 6404; X86-BMI1BMI2-NEXT: # %bb.1: 6405; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 6406; X86-BMI1BMI2-NEXT: .LBB49_2: 6407; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 6408; X86-BMI1BMI2-NEXT: popl %esi 6409; X86-BMI1BMI2-NEXT: retl 6410; 6411; X64-NOBMI-LABEL: bextr64_32_c2: 6412; X64-NOBMI: # %bb.0: 6413; X64-NOBMI-NEXT: movq %rsi, %rcx 6414; X64-NOBMI-NEXT: movq %rdi, %rax 6415; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 6416; X64-NOBMI-NEXT: shrq %cl, %rax 6417; X64-NOBMI-NEXT: negb %dl 6418; X64-NOBMI-NEXT: movl %edx, %ecx 6419; X64-NOBMI-NEXT: shll %cl, %eax 6420; X64-NOBMI-NEXT: shrl %cl, %eax 6421; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 6422; X64-NOBMI-NEXT: retq 6423; 6424; X64-BMI1NOTBM-LABEL: bextr64_32_c2: 6425; X64-BMI1NOTBM: # %bb.0: 6426; X64-BMI1NOTBM-NEXT: shll $8, %edx 6427; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6428; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6429; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 6430; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 6431; X64-BMI1NOTBM-NEXT: retq 6432; 6433; X64-BMI1BMI2-LABEL: bextr64_32_c2: 6434; X64-BMI1BMI2: # %bb.0: 6435; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 6436; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6437; X64-BMI1BMI2-NEXT: retq 6438 %shifted = lshr i64 %val, %numskipbits 6439 %numhighbits = sub i32 32, %numlowbits 6440 %mask = lshr i32 -1, %numhighbits 6441 %zextmask = zext i32 %mask to i64 6442 %masked = and i64 %zextmask, %shifted 6443 %truncmasked = trunc i64 %masked to i32 6444 ret i32 %truncmasked 6445} 6446 6447; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit. 6448; Masking is 64-bit. Then truncation. 6449define i32 @bextr64_32_c3(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 6450; X86-NOBMI-LABEL: bextr64_32_c3: 6451; X86-NOBMI: # %bb.0: 6452; X86-NOBMI-NEXT: pushl %esi 6453; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6454; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6455; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 6456; X86-NOBMI-NEXT: movl %esi, %edx 6457; X86-NOBMI-NEXT: shrl %cl, %edx 6458; X86-NOBMI-NEXT: shrdl %cl, %esi, %eax 6459; X86-NOBMI-NEXT: testb $32, %cl 6460; X86-NOBMI-NEXT: jne .LBB50_2 6461; X86-NOBMI-NEXT: # %bb.1: 6462; X86-NOBMI-NEXT: movl %eax, %edx 6463; X86-NOBMI-NEXT: .LBB50_2: 6464; X86-NOBMI-NEXT: movb $64, %cl 6465; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6466; X86-NOBMI-NEXT: xorl %eax, %eax 6467; X86-NOBMI-NEXT: movl $-1, %esi 6468; X86-NOBMI-NEXT: shrdl %cl, %eax, %esi 6469; X86-NOBMI-NEXT: testb $32, %cl 6470; X86-NOBMI-NEXT: jne .LBB50_4 6471; X86-NOBMI-NEXT: # %bb.3: 6472; X86-NOBMI-NEXT: movl %esi, %eax 6473; X86-NOBMI-NEXT: .LBB50_4: 6474; X86-NOBMI-NEXT: andl %edx, %eax 6475; X86-NOBMI-NEXT: popl %esi 6476; X86-NOBMI-NEXT: retl 6477; 6478; X86-BMI1NOTBM-LABEL: bextr64_32_c3: 6479; X86-BMI1NOTBM: # %bb.0: 6480; X86-BMI1NOTBM-NEXT: pushl %esi 6481; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6482; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 6483; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 6484; X86-BMI1NOTBM-NEXT: movl %esi, %edx 6485; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 6486; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %eax 6487; X86-BMI1NOTBM-NEXT: testb $32, %cl 6488; X86-BMI1NOTBM-NEXT: jne .LBB50_2 6489; X86-BMI1NOTBM-NEXT: # %bb.1: 6490; X86-BMI1NOTBM-NEXT: movl %eax, %edx 6491; X86-BMI1NOTBM-NEXT: .LBB50_2: 6492; X86-BMI1NOTBM-NEXT: movb $64, %cl 6493; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 6494; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 6495; X86-BMI1NOTBM-NEXT: movl $-1, %esi 6496; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %esi 6497; X86-BMI1NOTBM-NEXT: testb $32, %cl 6498; X86-BMI1NOTBM-NEXT: jne .LBB50_4 6499; X86-BMI1NOTBM-NEXT: # %bb.3: 6500; X86-BMI1NOTBM-NEXT: movl %esi, %eax 6501; X86-BMI1NOTBM-NEXT: .LBB50_4: 6502; X86-BMI1NOTBM-NEXT: andl %edx, %eax 6503; X86-BMI1NOTBM-NEXT: popl %esi 6504; X86-BMI1NOTBM-NEXT: retl 6505; 6506; X86-BMI1BMI2-LABEL: bextr64_32_c3: 6507; X86-BMI1BMI2: # %bb.0: 6508; X86-BMI1BMI2-NEXT: pushl %esi 6509; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 6510; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 6511; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 6512; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %edx 6513; X86-BMI1BMI2-NEXT: testb $32, %cl 6514; X86-BMI1BMI2-NEXT: je .LBB50_2 6515; X86-BMI1BMI2-NEXT: # %bb.1: 6516; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %edx 6517; X86-BMI1BMI2-NEXT: .LBB50_2: 6518; X86-BMI1BMI2-NEXT: movb $64, %cl 6519; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 6520; X86-BMI1BMI2-NEXT: xorl %eax, %eax 6521; X86-BMI1BMI2-NEXT: movl $-1, %esi 6522; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %esi 6523; X86-BMI1BMI2-NEXT: testb $32, %cl 6524; X86-BMI1BMI2-NEXT: jne .LBB50_4 6525; X86-BMI1BMI2-NEXT: # %bb.3: 6526; X86-BMI1BMI2-NEXT: movl %esi, %eax 6527; X86-BMI1BMI2-NEXT: .LBB50_4: 6528; X86-BMI1BMI2-NEXT: andl %edx, %eax 6529; X86-BMI1BMI2-NEXT: popl %esi 6530; X86-BMI1BMI2-NEXT: retl 6531; 6532; X64-NOBMI-LABEL: bextr64_32_c3: 6533; X64-NOBMI: # %bb.0: 6534; X64-NOBMI-NEXT: movq %rsi, %rcx 6535; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 6536; X64-NOBMI-NEXT: shrq %cl, %rdi 6537; X64-NOBMI-NEXT: negb %dl 6538; X64-NOBMI-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF 6539; X64-NOBMI-NEXT: movl %edx, %ecx 6540; X64-NOBMI-NEXT: shrq %cl, %rax 6541; X64-NOBMI-NEXT: andl %edi, %eax 6542; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 6543; X64-NOBMI-NEXT: retq 6544; 6545; X64-BMI1NOTBM-LABEL: bextr64_32_c3: 6546; X64-BMI1NOTBM: # %bb.0: 6547; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx 6548; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx 6549; X64-BMI1NOTBM-NEXT: shrq %cl, %rdi 6550; X64-BMI1NOTBM-NEXT: negb %dl 6551; X64-BMI1NOTBM-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF 6552; X64-BMI1NOTBM-NEXT: movl %edx, %ecx 6553; X64-BMI1NOTBM-NEXT: shrq %cl, %rax 6554; X64-BMI1NOTBM-NEXT: andl %edi, %eax 6555; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 6556; X64-BMI1NOTBM-NEXT: retq 6557; 6558; X64-BMI1BMI2-LABEL: bextr64_32_c3: 6559; X64-BMI1BMI2: # %bb.0: 6560; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rcx 6561; X64-BMI1BMI2-NEXT: negb %dl 6562; X64-BMI1BMI2-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF 6563; X64-BMI1BMI2-NEXT: shrxq %rdx, %rax, %rax 6564; X64-BMI1BMI2-NEXT: andl %ecx, %eax 6565; X64-BMI1BMI2-NEXT: # kill: def $eax killed $eax killed $rax 6566; X64-BMI1BMI2-NEXT: retq 6567 %shifted = lshr i64 %val, %numskipbits 6568 %numhighbits = sub i64 64, %numlowbits 6569 %mask = lshr i64 4294967295, %numhighbits 6570 %masked = and i64 %mask, %shifted 6571 %truncmasked = trunc i64 %masked to i32 6572 ret i32 %truncmasked 6573} 6574 6575; ---------------------------------------------------------------------------- ; 6576; Pattern d. 32-bit. 6577; ---------------------------------------------------------------------------- ; 6578 6579define i32 @bextr32_d0(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 6580; X86-NOBMI-LABEL: bextr32_d0: 6581; X86-NOBMI: # %bb.0: 6582; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6583; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6584; X86-NOBMI-NEXT: shrl %cl, %eax 6585; X86-NOBMI-NEXT: xorl %ecx, %ecx 6586; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6587; X86-NOBMI-NEXT: shll %cl, %eax 6588; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6589; X86-NOBMI-NEXT: shrl %cl, %eax 6590; X86-NOBMI-NEXT: retl 6591; 6592; X86-BMI1NOTBM-LABEL: bextr32_d0: 6593; X86-BMI1NOTBM: # %bb.0: 6594; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 6595; X86-BMI1NOTBM-NEXT: shll $8, %eax 6596; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 6597; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 6598; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 6599; X86-BMI1NOTBM-NEXT: retl 6600; 6601; X86-BMI1BMI2-LABEL: bextr32_d0: 6602; X86-BMI1BMI2: # %bb.0: 6603; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6604; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 6605; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 6606; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 6607; X86-BMI1BMI2-NEXT: retl 6608; 6609; X64-NOBMI-LABEL: bextr32_d0: 6610; X64-NOBMI: # %bb.0: 6611; X64-NOBMI-NEXT: movl %esi, %ecx 6612; X64-NOBMI-NEXT: movl %edi, %eax 6613; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6614; X64-NOBMI-NEXT: shrl %cl, %eax 6615; X64-NOBMI-NEXT: negb %dl 6616; X64-NOBMI-NEXT: movl %edx, %ecx 6617; X64-NOBMI-NEXT: shll %cl, %eax 6618; X64-NOBMI-NEXT: shrl %cl, %eax 6619; X64-NOBMI-NEXT: retq 6620; 6621; X64-BMI1NOTBM-LABEL: bextr32_d0: 6622; X64-BMI1NOTBM: # %bb.0: 6623; X64-BMI1NOTBM-NEXT: shll $8, %edx 6624; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6625; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6626; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 6627; X64-BMI1NOTBM-NEXT: retq 6628; 6629; X64-BMI1BMI2-LABEL: bextr32_d0: 6630; X64-BMI1BMI2: # %bb.0: 6631; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 6632; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6633; X64-BMI1BMI2-NEXT: retq 6634 %shifted = lshr i32 %val, %numskipbits 6635 %numhighbits = sub i32 32, %numlowbits 6636 %highbitscleared = shl i32 %shifted, %numhighbits 6637 %masked = lshr i32 %highbitscleared, %numhighbits 6638 ret i32 %masked 6639} 6640 6641define i32 @bextr32_d1_indexzext(i32 %val, i8 %numskipbits, i8 %numlowbits) nounwind { 6642; X86-NOBMI-LABEL: bextr32_d1_indexzext: 6643; X86-NOBMI: # %bb.0: 6644; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6645; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6646; X86-NOBMI-NEXT: shrl %cl, %eax 6647; X86-NOBMI-NEXT: xorl %ecx, %ecx 6648; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6649; X86-NOBMI-NEXT: shll %cl, %eax 6650; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6651; X86-NOBMI-NEXT: shrl %cl, %eax 6652; X86-NOBMI-NEXT: retl 6653; 6654; X86-BMI1NOTBM-LABEL: bextr32_d1_indexzext: 6655; X86-BMI1NOTBM: # %bb.0: 6656; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 6657; X86-BMI1NOTBM-NEXT: shll $8, %eax 6658; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %ecx 6659; X86-BMI1NOTBM-NEXT: orl %eax, %ecx 6660; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %eax 6661; X86-BMI1NOTBM-NEXT: retl 6662; 6663; X86-BMI1BMI2-LABEL: bextr32_d1_indexzext: 6664; X86-BMI1BMI2: # %bb.0: 6665; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6666; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 6667; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %ecx 6668; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 6669; X86-BMI1BMI2-NEXT: retl 6670; 6671; X64-NOBMI-LABEL: bextr32_d1_indexzext: 6672; X64-NOBMI: # %bb.0: 6673; X64-NOBMI-NEXT: movl %esi, %ecx 6674; X64-NOBMI-NEXT: movl %edi, %eax 6675; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6676; X64-NOBMI-NEXT: shrl %cl, %eax 6677; X64-NOBMI-NEXT: negb %dl 6678; X64-NOBMI-NEXT: movl %edx, %ecx 6679; X64-NOBMI-NEXT: shll %cl, %eax 6680; X64-NOBMI-NEXT: shrl %cl, %eax 6681; X64-NOBMI-NEXT: retq 6682; 6683; X64-BMI1NOTBM-LABEL: bextr32_d1_indexzext: 6684; X64-BMI1NOTBM: # %bb.0: 6685; X64-BMI1NOTBM-NEXT: shll $8, %edx 6686; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6687; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6688; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 6689; X64-BMI1NOTBM-NEXT: retq 6690; 6691; X64-BMI1BMI2-LABEL: bextr32_d1_indexzext: 6692; X64-BMI1BMI2: # %bb.0: 6693; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 6694; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6695; X64-BMI1BMI2-NEXT: retq 6696 %skip = zext i8 %numskipbits to i32 6697 %shifted = lshr i32 %val, %skip 6698 %numhighbits = sub i8 32, %numlowbits 6699 %sh_prom = zext i8 %numhighbits to i32 6700 %highbitscleared = shl i32 %shifted, %sh_prom 6701 %masked = lshr i32 %highbitscleared, %sh_prom 6702 ret i32 %masked 6703} 6704 6705define i32 @bextr32_d2_load(i32* %w, i32 %numskipbits, i32 %numlowbits) nounwind { 6706; X86-NOBMI-LABEL: bextr32_d2_load: 6707; X86-NOBMI: # %bb.0: 6708; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6709; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6710; X86-NOBMI-NEXT: movl (%eax), %eax 6711; X86-NOBMI-NEXT: shrl %cl, %eax 6712; X86-NOBMI-NEXT: xorl %ecx, %ecx 6713; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6714; X86-NOBMI-NEXT: shll %cl, %eax 6715; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6716; X86-NOBMI-NEXT: shrl %cl, %eax 6717; X86-NOBMI-NEXT: retl 6718; 6719; X86-BMI1NOTBM-LABEL: bextr32_d2_load: 6720; X86-BMI1NOTBM: # %bb.0: 6721; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 6722; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6723; X86-BMI1NOTBM-NEXT: shll $8, %ecx 6724; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %edx 6725; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 6726; X86-BMI1NOTBM-NEXT: bextrl %edx, (%eax), %eax 6727; X86-BMI1NOTBM-NEXT: retl 6728; 6729; X86-BMI1BMI2-LABEL: bextr32_d2_load: 6730; X86-BMI1BMI2: # %bb.0: 6731; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6732; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 6733; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 6734; X86-BMI1BMI2-NEXT: shrxl %edx, (%ecx), %ecx 6735; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 6736; X86-BMI1BMI2-NEXT: retl 6737; 6738; X64-NOBMI-LABEL: bextr32_d2_load: 6739; X64-NOBMI: # %bb.0: 6740; X64-NOBMI-NEXT: movl %esi, %ecx 6741; X64-NOBMI-NEXT: movl (%rdi), %eax 6742; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6743; X64-NOBMI-NEXT: shrl %cl, %eax 6744; X64-NOBMI-NEXT: negb %dl 6745; X64-NOBMI-NEXT: movl %edx, %ecx 6746; X64-NOBMI-NEXT: shll %cl, %eax 6747; X64-NOBMI-NEXT: shrl %cl, %eax 6748; X64-NOBMI-NEXT: retq 6749; 6750; X64-BMI1NOTBM-LABEL: bextr32_d2_load: 6751; X64-BMI1NOTBM: # %bb.0: 6752; X64-BMI1NOTBM-NEXT: shll $8, %edx 6753; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6754; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6755; X64-BMI1NOTBM-NEXT: bextrl %eax, (%rdi), %eax 6756; X64-BMI1NOTBM-NEXT: retq 6757; 6758; X64-BMI1BMI2-LABEL: bextr32_d2_load: 6759; X64-BMI1BMI2: # %bb.0: 6760; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %eax 6761; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6762; X64-BMI1BMI2-NEXT: retq 6763 %val = load i32, i32* %w 6764 %shifted = lshr i32 %val, %numskipbits 6765 %numhighbits = sub i32 32, %numlowbits 6766 %highbitscleared = shl i32 %shifted, %numhighbits 6767 %masked = lshr i32 %highbitscleared, %numhighbits 6768 ret i32 %masked 6769} 6770 6771define i32 @bextr32_d3_load_indexzext(i32* %w, i8 %numskipbits, i8 %numlowbits) nounwind { 6772; X86-NOBMI-LABEL: bextr32_d3_load_indexzext: 6773; X86-NOBMI: # %bb.0: 6774; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6775; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6776; X86-NOBMI-NEXT: movl (%eax), %eax 6777; X86-NOBMI-NEXT: shrl %cl, %eax 6778; X86-NOBMI-NEXT: xorl %ecx, %ecx 6779; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6780; X86-NOBMI-NEXT: shll %cl, %eax 6781; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6782; X86-NOBMI-NEXT: shrl %cl, %eax 6783; X86-NOBMI-NEXT: retl 6784; 6785; X86-BMI1NOTBM-LABEL: bextr32_d3_load_indexzext: 6786; X86-BMI1NOTBM: # %bb.0: 6787; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 6788; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6789; X86-BMI1NOTBM-NEXT: shll $8, %ecx 6790; X86-BMI1NOTBM-NEXT: movzbl {{[0-9]+}}(%esp), %edx 6791; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 6792; X86-BMI1NOTBM-NEXT: bextrl %edx, (%eax), %eax 6793; X86-BMI1NOTBM-NEXT: retl 6794; 6795; X86-BMI1BMI2-LABEL: bextr32_d3_load_indexzext: 6796; X86-BMI1BMI2: # %bb.0: 6797; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6798; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 6799; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %dl 6800; X86-BMI1BMI2-NEXT: shrxl %edx, (%ecx), %ecx 6801; X86-BMI1BMI2-NEXT: bzhil %eax, %ecx, %eax 6802; X86-BMI1BMI2-NEXT: retl 6803; 6804; X64-NOBMI-LABEL: bextr32_d3_load_indexzext: 6805; X64-NOBMI: # %bb.0: 6806; X64-NOBMI-NEXT: movl %esi, %ecx 6807; X64-NOBMI-NEXT: movl (%rdi), %eax 6808; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6809; X64-NOBMI-NEXT: shrl %cl, %eax 6810; X64-NOBMI-NEXT: negb %dl 6811; X64-NOBMI-NEXT: movl %edx, %ecx 6812; X64-NOBMI-NEXT: shll %cl, %eax 6813; X64-NOBMI-NEXT: shrl %cl, %eax 6814; X64-NOBMI-NEXT: retq 6815; 6816; X64-BMI1NOTBM-LABEL: bextr32_d3_load_indexzext: 6817; X64-BMI1NOTBM: # %bb.0: 6818; X64-BMI1NOTBM-NEXT: shll $8, %edx 6819; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6820; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6821; X64-BMI1NOTBM-NEXT: bextrl %eax, (%rdi), %eax 6822; X64-BMI1NOTBM-NEXT: retq 6823; 6824; X64-BMI1BMI2-LABEL: bextr32_d3_load_indexzext: 6825; X64-BMI1BMI2: # %bb.0: 6826; X64-BMI1BMI2-NEXT: shrxl %esi, (%rdi), %eax 6827; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 6828; X64-BMI1BMI2-NEXT: retq 6829 %val = load i32, i32* %w 6830 %skip = zext i8 %numskipbits to i32 6831 %shifted = lshr i32 %val, %skip 6832 %numhighbits = sub i8 32, %numlowbits 6833 %sh_prom = zext i8 %numhighbits to i32 6834 %highbitscleared = shl i32 %shifted, %sh_prom 6835 %masked = lshr i32 %highbitscleared, %sh_prom 6836 ret i32 %masked 6837} 6838 6839define i32 @bextr32_d5_skipextrauses(i32 %val, i32 %numskipbits, i32 %numlowbits) nounwind { 6840; X86-NOBMI-LABEL: bextr32_d5_skipextrauses: 6841; X86-NOBMI: # %bb.0: 6842; X86-NOBMI-NEXT: pushl %esi 6843; X86-NOBMI-NEXT: subl $8, %esp 6844; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 6845; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 6846; X86-NOBMI-NEXT: movl %eax, %ecx 6847; X86-NOBMI-NEXT: shrl %cl, %esi 6848; X86-NOBMI-NEXT: xorl %ecx, %ecx 6849; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6850; X86-NOBMI-NEXT: shll %cl, %esi 6851; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 6852; X86-NOBMI-NEXT: shrl %cl, %esi 6853; X86-NOBMI-NEXT: movl %eax, (%esp) 6854; X86-NOBMI-NEXT: calll use32 6855; X86-NOBMI-NEXT: movl %esi, %eax 6856; X86-NOBMI-NEXT: addl $8, %esp 6857; X86-NOBMI-NEXT: popl %esi 6858; X86-NOBMI-NEXT: retl 6859; 6860; X86-BMI1NOTBM-LABEL: bextr32_d5_skipextrauses: 6861; X86-BMI1NOTBM: # %bb.0: 6862; X86-BMI1NOTBM-NEXT: pushl %esi 6863; X86-BMI1NOTBM-NEXT: subl $8, %esp 6864; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6865; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 6866; X86-BMI1NOTBM-NEXT: shll $8, %ecx 6867; X86-BMI1NOTBM-NEXT: movzbl %al, %edx 6868; X86-BMI1NOTBM-NEXT: orl %ecx, %edx 6869; X86-BMI1NOTBM-NEXT: bextrl %edx, {{[0-9]+}}(%esp), %esi 6870; X86-BMI1NOTBM-NEXT: movl %eax, (%esp) 6871; X86-BMI1NOTBM-NEXT: calll use32 6872; X86-BMI1NOTBM-NEXT: movl %esi, %eax 6873; X86-BMI1NOTBM-NEXT: addl $8, %esp 6874; X86-BMI1NOTBM-NEXT: popl %esi 6875; X86-BMI1NOTBM-NEXT: retl 6876; 6877; X86-BMI1BMI2-LABEL: bextr32_d5_skipextrauses: 6878; X86-BMI1BMI2: # %bb.0: 6879; X86-BMI1BMI2-NEXT: pushl %esi 6880; X86-BMI1BMI2-NEXT: subl $8, %esp 6881; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 6882; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 6883; X86-BMI1BMI2-NEXT: shrxl %ecx, {{[0-9]+}}(%esp), %edx 6884; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %esi 6885; X86-BMI1BMI2-NEXT: movl %ecx, (%esp) 6886; X86-BMI1BMI2-NEXT: calll use32 6887; X86-BMI1BMI2-NEXT: movl %esi, %eax 6888; X86-BMI1BMI2-NEXT: addl $8, %esp 6889; X86-BMI1BMI2-NEXT: popl %esi 6890; X86-BMI1BMI2-NEXT: retl 6891; 6892; X64-NOBMI-LABEL: bextr32_d5_skipextrauses: 6893; X64-NOBMI: # %bb.0: 6894; X64-NOBMI-NEXT: pushq %rbx 6895; X64-NOBMI-NEXT: movl %edi, %ebx 6896; X64-NOBMI-NEXT: movl %esi, %ecx 6897; X64-NOBMI-NEXT: shrl %cl, %ebx 6898; X64-NOBMI-NEXT: negb %dl 6899; X64-NOBMI-NEXT: movl %edx, %ecx 6900; X64-NOBMI-NEXT: shll %cl, %ebx 6901; X64-NOBMI-NEXT: shrl %cl, %ebx 6902; X64-NOBMI-NEXT: movl %esi, %edi 6903; X64-NOBMI-NEXT: callq use32 6904; X64-NOBMI-NEXT: movl %ebx, %eax 6905; X64-NOBMI-NEXT: popq %rbx 6906; X64-NOBMI-NEXT: retq 6907; 6908; X64-BMI1NOTBM-LABEL: bextr32_d5_skipextrauses: 6909; X64-BMI1NOTBM: # %bb.0: 6910; X64-BMI1NOTBM-NEXT: pushq %rbx 6911; X64-BMI1NOTBM-NEXT: shll $8, %edx 6912; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 6913; X64-BMI1NOTBM-NEXT: orl %edx, %eax 6914; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %ebx 6915; X64-BMI1NOTBM-NEXT: movl %esi, %edi 6916; X64-BMI1NOTBM-NEXT: callq use32 6917; X64-BMI1NOTBM-NEXT: movl %ebx, %eax 6918; X64-BMI1NOTBM-NEXT: popq %rbx 6919; X64-BMI1NOTBM-NEXT: retq 6920; 6921; X64-BMI1BMI2-LABEL: bextr32_d5_skipextrauses: 6922; X64-BMI1BMI2: # %bb.0: 6923; X64-BMI1BMI2-NEXT: pushq %rbx 6924; X64-BMI1BMI2-NEXT: shrxl %esi, %edi, %eax 6925; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %ebx 6926; X64-BMI1BMI2-NEXT: movl %esi, %edi 6927; X64-BMI1BMI2-NEXT: callq use32 6928; X64-BMI1BMI2-NEXT: movl %ebx, %eax 6929; X64-BMI1BMI2-NEXT: popq %rbx 6930; X64-BMI1BMI2-NEXT: retq 6931 %shifted = lshr i32 %val, %numskipbits 6932 %numhighbits = sub i32 32, %numlowbits 6933 %highbitscleared = shl i32 %shifted, %numhighbits 6934 %masked = lshr i32 %highbitscleared, %numhighbits 6935 call void @use32(i32 %numskipbits) 6936 ret i32 %masked 6937} 6938 6939; 64-bit. 6940 6941define i64 @bextr64_d0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 6942; X86-NOBMI-LABEL: bextr64_d0: 6943; X86-NOBMI: # %bb.0: 6944; X86-NOBMI-NEXT: pushl %ebx 6945; X86-NOBMI-NEXT: pushl %edi 6946; X86-NOBMI-NEXT: pushl %esi 6947; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 6948; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 6949; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 6950; X86-NOBMI-NEXT: movl %edx, %eax 6951; X86-NOBMI-NEXT: shrl %cl, %eax 6952; X86-NOBMI-NEXT: shrdl %cl, %edx, %edi 6953; X86-NOBMI-NEXT: xorl %esi, %esi 6954; X86-NOBMI-NEXT: testb $32, %cl 6955; X86-NOBMI-NEXT: je .LBB56_2 6956; X86-NOBMI-NEXT: # %bb.1: 6957; X86-NOBMI-NEXT: movl %eax, %edi 6958; X86-NOBMI-NEXT: xorl %eax, %eax 6959; X86-NOBMI-NEXT: .LBB56_2: 6960; X86-NOBMI-NEXT: movb $64, %cl 6961; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 6962; X86-NOBMI-NEXT: shldl %cl, %edi, %eax 6963; X86-NOBMI-NEXT: shll %cl, %edi 6964; X86-NOBMI-NEXT: testb $32, %cl 6965; X86-NOBMI-NEXT: movl %edi, %ebx 6966; X86-NOBMI-NEXT: jne .LBB56_4 6967; X86-NOBMI-NEXT: # %bb.3: 6968; X86-NOBMI-NEXT: movl %eax, %ebx 6969; X86-NOBMI-NEXT: .LBB56_4: 6970; X86-NOBMI-NEXT: movl %ebx, %eax 6971; X86-NOBMI-NEXT: shrl %cl, %eax 6972; X86-NOBMI-NEXT: testb $32, %cl 6973; X86-NOBMI-NEXT: movl $0, %edx 6974; X86-NOBMI-NEXT: jne .LBB56_6 6975; X86-NOBMI-NEXT: # %bb.5: 6976; X86-NOBMI-NEXT: movl %edi, %esi 6977; X86-NOBMI-NEXT: movl %eax, %edx 6978; X86-NOBMI-NEXT: .LBB56_6: 6979; X86-NOBMI-NEXT: shrdl %cl, %ebx, %esi 6980; X86-NOBMI-NEXT: testb $32, %cl 6981; X86-NOBMI-NEXT: jne .LBB56_8 6982; X86-NOBMI-NEXT: # %bb.7: 6983; X86-NOBMI-NEXT: movl %esi, %eax 6984; X86-NOBMI-NEXT: .LBB56_8: 6985; X86-NOBMI-NEXT: popl %esi 6986; X86-NOBMI-NEXT: popl %edi 6987; X86-NOBMI-NEXT: popl %ebx 6988; X86-NOBMI-NEXT: retl 6989; 6990; X86-BMI1NOTBM-LABEL: bextr64_d0: 6991; X86-BMI1NOTBM: # %bb.0: 6992; X86-BMI1NOTBM-NEXT: pushl %ebx 6993; X86-BMI1NOTBM-NEXT: pushl %edi 6994; X86-BMI1NOTBM-NEXT: pushl %esi 6995; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 6996; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 6997; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 6998; X86-BMI1NOTBM-NEXT: movl %edx, %eax 6999; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7000; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %edi 7001; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 7002; X86-BMI1NOTBM-NEXT: testb $32, %cl 7003; X86-BMI1NOTBM-NEXT: je .LBB56_2 7004; X86-BMI1NOTBM-NEXT: # %bb.1: 7005; X86-BMI1NOTBM-NEXT: movl %eax, %edi 7006; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 7007; X86-BMI1NOTBM-NEXT: .LBB56_2: 7008; X86-BMI1NOTBM-NEXT: movb $64, %cl 7009; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 7010; X86-BMI1NOTBM-NEXT: shldl %cl, %edi, %eax 7011; X86-BMI1NOTBM-NEXT: shll %cl, %edi 7012; X86-BMI1NOTBM-NEXT: testb $32, %cl 7013; X86-BMI1NOTBM-NEXT: movl %edi, %ebx 7014; X86-BMI1NOTBM-NEXT: jne .LBB56_4 7015; X86-BMI1NOTBM-NEXT: # %bb.3: 7016; X86-BMI1NOTBM-NEXT: movl %eax, %ebx 7017; X86-BMI1NOTBM-NEXT: .LBB56_4: 7018; X86-BMI1NOTBM-NEXT: movl %ebx, %eax 7019; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7020; X86-BMI1NOTBM-NEXT: testb $32, %cl 7021; X86-BMI1NOTBM-NEXT: movl $0, %edx 7022; X86-BMI1NOTBM-NEXT: jne .LBB56_6 7023; X86-BMI1NOTBM-NEXT: # %bb.5: 7024; X86-BMI1NOTBM-NEXT: movl %edi, %esi 7025; X86-BMI1NOTBM-NEXT: movl %eax, %edx 7026; X86-BMI1NOTBM-NEXT: .LBB56_6: 7027; X86-BMI1NOTBM-NEXT: shrdl %cl, %ebx, %esi 7028; X86-BMI1NOTBM-NEXT: testb $32, %cl 7029; X86-BMI1NOTBM-NEXT: jne .LBB56_8 7030; X86-BMI1NOTBM-NEXT: # %bb.7: 7031; X86-BMI1NOTBM-NEXT: movl %esi, %eax 7032; X86-BMI1NOTBM-NEXT: .LBB56_8: 7033; X86-BMI1NOTBM-NEXT: popl %esi 7034; X86-BMI1NOTBM-NEXT: popl %edi 7035; X86-BMI1NOTBM-NEXT: popl %ebx 7036; X86-BMI1NOTBM-NEXT: retl 7037; 7038; X86-BMI1BMI2-LABEL: bextr64_d0: 7039; X86-BMI1BMI2: # %bb.0: 7040; X86-BMI1BMI2-NEXT: pushl %edi 7041; X86-BMI1BMI2-NEXT: pushl %esi 7042; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 7043; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 7044; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 7045; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 7046; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %esi 7047; X86-BMI1BMI2-NEXT: xorl %edx, %edx 7048; X86-BMI1BMI2-NEXT: testb $32, %cl 7049; X86-BMI1BMI2-NEXT: je .LBB56_2 7050; X86-BMI1BMI2-NEXT: # %bb.1: 7051; X86-BMI1BMI2-NEXT: movl %esi, %eax 7052; X86-BMI1BMI2-NEXT: xorl %esi, %esi 7053; X86-BMI1BMI2-NEXT: .LBB56_2: 7054; X86-BMI1BMI2-NEXT: movb $64, %cl 7055; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 7056; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %esi 7057; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %edi 7058; X86-BMI1BMI2-NEXT: testb $32, %cl 7059; X86-BMI1BMI2-NEXT: je .LBB56_4 7060; X86-BMI1BMI2-NEXT: # %bb.3: 7061; X86-BMI1BMI2-NEXT: movl %edi, %esi 7062; X86-BMI1BMI2-NEXT: movl $0, %edi 7063; X86-BMI1BMI2-NEXT: .LBB56_4: 7064; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax 7065; X86-BMI1BMI2-NEXT: jne .LBB56_6 7066; X86-BMI1BMI2-NEXT: # %bb.5: 7067; X86-BMI1BMI2-NEXT: movl %eax, %edx 7068; X86-BMI1BMI2-NEXT: .LBB56_6: 7069; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi 7070; X86-BMI1BMI2-NEXT: testb $32, %cl 7071; X86-BMI1BMI2-NEXT: jne .LBB56_8 7072; X86-BMI1BMI2-NEXT: # %bb.7: 7073; X86-BMI1BMI2-NEXT: movl %edi, %eax 7074; X86-BMI1BMI2-NEXT: .LBB56_8: 7075; X86-BMI1BMI2-NEXT: popl %esi 7076; X86-BMI1BMI2-NEXT: popl %edi 7077; X86-BMI1BMI2-NEXT: retl 7078; 7079; X64-NOBMI-LABEL: bextr64_d0: 7080; X64-NOBMI: # %bb.0: 7081; X64-NOBMI-NEXT: movq %rsi, %rcx 7082; X64-NOBMI-NEXT: movq %rdi, %rax 7083; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 7084; X64-NOBMI-NEXT: shrq %cl, %rax 7085; X64-NOBMI-NEXT: negb %dl 7086; X64-NOBMI-NEXT: movl %edx, %ecx 7087; X64-NOBMI-NEXT: shlq %cl, %rax 7088; X64-NOBMI-NEXT: shrq %cl, %rax 7089; X64-NOBMI-NEXT: retq 7090; 7091; X64-BMI1NOTBM-LABEL: bextr64_d0: 7092; X64-BMI1NOTBM: # %bb.0: 7093; X64-BMI1NOTBM-NEXT: shll $8, %edx 7094; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 7095; X64-BMI1NOTBM-NEXT: orl %edx, %eax 7096; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 7097; X64-BMI1NOTBM-NEXT: retq 7098; 7099; X64-BMI1BMI2-LABEL: bextr64_d0: 7100; X64-BMI1BMI2: # %bb.0: 7101; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 7102; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 7103; X64-BMI1BMI2-NEXT: retq 7104 %shifted = lshr i64 %val, %numskipbits 7105 %numhighbits = sub i64 64, %numlowbits 7106 %highbitscleared = shl i64 %shifted, %numhighbits 7107 %masked = lshr i64 %highbitscleared, %numhighbits 7108 ret i64 %masked 7109} 7110 7111define i64 @bextr64_d1_indexzext(i64 %val, i8 %numskipbits, i8 %numlowbits) nounwind { 7112; X86-NOBMI-LABEL: bextr64_d1_indexzext: 7113; X86-NOBMI: # %bb.0: 7114; X86-NOBMI-NEXT: pushl %ebx 7115; X86-NOBMI-NEXT: pushl %edi 7116; X86-NOBMI-NEXT: pushl %esi 7117; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 7118; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi 7119; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 7120; X86-NOBMI-NEXT: movl %edx, %eax 7121; X86-NOBMI-NEXT: shrl %cl, %eax 7122; X86-NOBMI-NEXT: shrdl %cl, %edx, %edi 7123; X86-NOBMI-NEXT: xorl %esi, %esi 7124; X86-NOBMI-NEXT: testb $32, %cl 7125; X86-NOBMI-NEXT: je .LBB57_2 7126; X86-NOBMI-NEXT: # %bb.1: 7127; X86-NOBMI-NEXT: movl %eax, %edi 7128; X86-NOBMI-NEXT: xorl %eax, %eax 7129; X86-NOBMI-NEXT: .LBB57_2: 7130; X86-NOBMI-NEXT: movb $64, %cl 7131; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 7132; X86-NOBMI-NEXT: shldl %cl, %edi, %eax 7133; X86-NOBMI-NEXT: shll %cl, %edi 7134; X86-NOBMI-NEXT: testb $32, %cl 7135; X86-NOBMI-NEXT: movl %edi, %ebx 7136; X86-NOBMI-NEXT: jne .LBB57_4 7137; X86-NOBMI-NEXT: # %bb.3: 7138; X86-NOBMI-NEXT: movl %eax, %ebx 7139; X86-NOBMI-NEXT: .LBB57_4: 7140; X86-NOBMI-NEXT: movl %ebx, %eax 7141; X86-NOBMI-NEXT: shrl %cl, %eax 7142; X86-NOBMI-NEXT: testb $32, %cl 7143; X86-NOBMI-NEXT: movl $0, %edx 7144; X86-NOBMI-NEXT: jne .LBB57_6 7145; X86-NOBMI-NEXT: # %bb.5: 7146; X86-NOBMI-NEXT: movl %edi, %esi 7147; X86-NOBMI-NEXT: movl %eax, %edx 7148; X86-NOBMI-NEXT: .LBB57_6: 7149; X86-NOBMI-NEXT: shrdl %cl, %ebx, %esi 7150; X86-NOBMI-NEXT: testb $32, %cl 7151; X86-NOBMI-NEXT: jne .LBB57_8 7152; X86-NOBMI-NEXT: # %bb.7: 7153; X86-NOBMI-NEXT: movl %esi, %eax 7154; X86-NOBMI-NEXT: .LBB57_8: 7155; X86-NOBMI-NEXT: popl %esi 7156; X86-NOBMI-NEXT: popl %edi 7157; X86-NOBMI-NEXT: popl %ebx 7158; X86-NOBMI-NEXT: retl 7159; 7160; X86-BMI1NOTBM-LABEL: bextr64_d1_indexzext: 7161; X86-BMI1NOTBM: # %bb.0: 7162; X86-BMI1NOTBM-NEXT: pushl %ebx 7163; X86-BMI1NOTBM-NEXT: pushl %edi 7164; X86-BMI1NOTBM-NEXT: pushl %esi 7165; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 7166; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 7167; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 7168; X86-BMI1NOTBM-NEXT: movl %edx, %eax 7169; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7170; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %edi 7171; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 7172; X86-BMI1NOTBM-NEXT: testb $32, %cl 7173; X86-BMI1NOTBM-NEXT: je .LBB57_2 7174; X86-BMI1NOTBM-NEXT: # %bb.1: 7175; X86-BMI1NOTBM-NEXT: movl %eax, %edi 7176; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 7177; X86-BMI1NOTBM-NEXT: .LBB57_2: 7178; X86-BMI1NOTBM-NEXT: movb $64, %cl 7179; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 7180; X86-BMI1NOTBM-NEXT: shldl %cl, %edi, %eax 7181; X86-BMI1NOTBM-NEXT: shll %cl, %edi 7182; X86-BMI1NOTBM-NEXT: testb $32, %cl 7183; X86-BMI1NOTBM-NEXT: movl %edi, %ebx 7184; X86-BMI1NOTBM-NEXT: jne .LBB57_4 7185; X86-BMI1NOTBM-NEXT: # %bb.3: 7186; X86-BMI1NOTBM-NEXT: movl %eax, %ebx 7187; X86-BMI1NOTBM-NEXT: .LBB57_4: 7188; X86-BMI1NOTBM-NEXT: movl %ebx, %eax 7189; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7190; X86-BMI1NOTBM-NEXT: testb $32, %cl 7191; X86-BMI1NOTBM-NEXT: movl $0, %edx 7192; X86-BMI1NOTBM-NEXT: jne .LBB57_6 7193; X86-BMI1NOTBM-NEXT: # %bb.5: 7194; X86-BMI1NOTBM-NEXT: movl %edi, %esi 7195; X86-BMI1NOTBM-NEXT: movl %eax, %edx 7196; X86-BMI1NOTBM-NEXT: .LBB57_6: 7197; X86-BMI1NOTBM-NEXT: shrdl %cl, %ebx, %esi 7198; X86-BMI1NOTBM-NEXT: testb $32, %cl 7199; X86-BMI1NOTBM-NEXT: jne .LBB57_8 7200; X86-BMI1NOTBM-NEXT: # %bb.7: 7201; X86-BMI1NOTBM-NEXT: movl %esi, %eax 7202; X86-BMI1NOTBM-NEXT: .LBB57_8: 7203; X86-BMI1NOTBM-NEXT: popl %esi 7204; X86-BMI1NOTBM-NEXT: popl %edi 7205; X86-BMI1NOTBM-NEXT: popl %ebx 7206; X86-BMI1NOTBM-NEXT: retl 7207; 7208; X86-BMI1BMI2-LABEL: bextr64_d1_indexzext: 7209; X86-BMI1BMI2: # %bb.0: 7210; X86-BMI1BMI2-NEXT: pushl %edi 7211; X86-BMI1BMI2-NEXT: pushl %esi 7212; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 7213; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 7214; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 7215; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 7216; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %esi 7217; X86-BMI1BMI2-NEXT: xorl %edx, %edx 7218; X86-BMI1BMI2-NEXT: testb $32, %cl 7219; X86-BMI1BMI2-NEXT: je .LBB57_2 7220; X86-BMI1BMI2-NEXT: # %bb.1: 7221; X86-BMI1BMI2-NEXT: movl %esi, %eax 7222; X86-BMI1BMI2-NEXT: xorl %esi, %esi 7223; X86-BMI1BMI2-NEXT: .LBB57_2: 7224; X86-BMI1BMI2-NEXT: movb $64, %cl 7225; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 7226; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %esi 7227; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %edi 7228; X86-BMI1BMI2-NEXT: testb $32, %cl 7229; X86-BMI1BMI2-NEXT: je .LBB57_4 7230; X86-BMI1BMI2-NEXT: # %bb.3: 7231; X86-BMI1BMI2-NEXT: movl %edi, %esi 7232; X86-BMI1BMI2-NEXT: movl $0, %edi 7233; X86-BMI1BMI2-NEXT: .LBB57_4: 7234; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax 7235; X86-BMI1BMI2-NEXT: jne .LBB57_6 7236; X86-BMI1BMI2-NEXT: # %bb.5: 7237; X86-BMI1BMI2-NEXT: movl %eax, %edx 7238; X86-BMI1BMI2-NEXT: .LBB57_6: 7239; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi 7240; X86-BMI1BMI2-NEXT: testb $32, %cl 7241; X86-BMI1BMI2-NEXT: jne .LBB57_8 7242; X86-BMI1BMI2-NEXT: # %bb.7: 7243; X86-BMI1BMI2-NEXT: movl %edi, %eax 7244; X86-BMI1BMI2-NEXT: .LBB57_8: 7245; X86-BMI1BMI2-NEXT: popl %esi 7246; X86-BMI1BMI2-NEXT: popl %edi 7247; X86-BMI1BMI2-NEXT: retl 7248; 7249; X64-NOBMI-LABEL: bextr64_d1_indexzext: 7250; X64-NOBMI: # %bb.0: 7251; X64-NOBMI-NEXT: movl %esi, %ecx 7252; X64-NOBMI-NEXT: movq %rdi, %rax 7253; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 7254; X64-NOBMI-NEXT: shrq %cl, %rax 7255; X64-NOBMI-NEXT: negb %dl 7256; X64-NOBMI-NEXT: movl %edx, %ecx 7257; X64-NOBMI-NEXT: shlq %cl, %rax 7258; X64-NOBMI-NEXT: shrq %cl, %rax 7259; X64-NOBMI-NEXT: retq 7260; 7261; X64-BMI1NOTBM-LABEL: bextr64_d1_indexzext: 7262; X64-BMI1NOTBM: # %bb.0: 7263; X64-BMI1NOTBM-NEXT: shll $8, %edx 7264; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 7265; X64-BMI1NOTBM-NEXT: orl %edx, %eax 7266; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 7267; X64-BMI1NOTBM-NEXT: retq 7268; 7269; X64-BMI1BMI2-LABEL: bextr64_d1_indexzext: 7270; X64-BMI1BMI2: # %bb.0: 7271; X64-BMI1BMI2-NEXT: # kill: def $edx killed $edx def $rdx 7272; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 7273; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 7274; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 7275; X64-BMI1BMI2-NEXT: retq 7276 %skip = zext i8 %numskipbits to i64 7277 %shifted = lshr i64 %val, %skip 7278 %numhighbits = sub i8 64, %numlowbits 7279 %sh_prom = zext i8 %numhighbits to i64 7280 %highbitscleared = shl i64 %shifted, %sh_prom 7281 %masked = lshr i64 %highbitscleared, %sh_prom 7282 ret i64 %masked 7283} 7284 7285define i64 @bextr64_d2_load(i64* %w, i64 %numskipbits, i64 %numlowbits) nounwind { 7286; X86-NOBMI-LABEL: bextr64_d2_load: 7287; X86-NOBMI: # %bb.0: 7288; X86-NOBMI-NEXT: pushl %ebx 7289; X86-NOBMI-NEXT: pushl %edi 7290; X86-NOBMI-NEXT: pushl %esi 7291; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 7292; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 7293; X86-NOBMI-NEXT: movl (%eax), %edi 7294; X86-NOBMI-NEXT: movl 4(%eax), %edx 7295; X86-NOBMI-NEXT: movl %edx, %eax 7296; X86-NOBMI-NEXT: shrl %cl, %eax 7297; X86-NOBMI-NEXT: shrdl %cl, %edx, %edi 7298; X86-NOBMI-NEXT: xorl %esi, %esi 7299; X86-NOBMI-NEXT: testb $32, %cl 7300; X86-NOBMI-NEXT: je .LBB58_2 7301; X86-NOBMI-NEXT: # %bb.1: 7302; X86-NOBMI-NEXT: movl %eax, %edi 7303; X86-NOBMI-NEXT: xorl %eax, %eax 7304; X86-NOBMI-NEXT: .LBB58_2: 7305; X86-NOBMI-NEXT: movb $64, %cl 7306; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 7307; X86-NOBMI-NEXT: shldl %cl, %edi, %eax 7308; X86-NOBMI-NEXT: shll %cl, %edi 7309; X86-NOBMI-NEXT: testb $32, %cl 7310; X86-NOBMI-NEXT: movl %edi, %ebx 7311; X86-NOBMI-NEXT: jne .LBB58_4 7312; X86-NOBMI-NEXT: # %bb.3: 7313; X86-NOBMI-NEXT: movl %eax, %ebx 7314; X86-NOBMI-NEXT: .LBB58_4: 7315; X86-NOBMI-NEXT: movl %ebx, %eax 7316; X86-NOBMI-NEXT: shrl %cl, %eax 7317; X86-NOBMI-NEXT: testb $32, %cl 7318; X86-NOBMI-NEXT: movl $0, %edx 7319; X86-NOBMI-NEXT: jne .LBB58_6 7320; X86-NOBMI-NEXT: # %bb.5: 7321; X86-NOBMI-NEXT: movl %edi, %esi 7322; X86-NOBMI-NEXT: movl %eax, %edx 7323; X86-NOBMI-NEXT: .LBB58_6: 7324; X86-NOBMI-NEXT: shrdl %cl, %ebx, %esi 7325; X86-NOBMI-NEXT: testb $32, %cl 7326; X86-NOBMI-NEXT: jne .LBB58_8 7327; X86-NOBMI-NEXT: # %bb.7: 7328; X86-NOBMI-NEXT: movl %esi, %eax 7329; X86-NOBMI-NEXT: .LBB58_8: 7330; X86-NOBMI-NEXT: popl %esi 7331; X86-NOBMI-NEXT: popl %edi 7332; X86-NOBMI-NEXT: popl %ebx 7333; X86-NOBMI-NEXT: retl 7334; 7335; X86-BMI1NOTBM-LABEL: bextr64_d2_load: 7336; X86-BMI1NOTBM: # %bb.0: 7337; X86-BMI1NOTBM-NEXT: pushl %ebx 7338; X86-BMI1NOTBM-NEXT: pushl %edi 7339; X86-BMI1NOTBM-NEXT: pushl %esi 7340; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 7341; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 7342; X86-BMI1NOTBM-NEXT: movl (%eax), %edi 7343; X86-BMI1NOTBM-NEXT: movl 4(%eax), %edx 7344; X86-BMI1NOTBM-NEXT: movl %edx, %eax 7345; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7346; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %edi 7347; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 7348; X86-BMI1NOTBM-NEXT: testb $32, %cl 7349; X86-BMI1NOTBM-NEXT: je .LBB58_2 7350; X86-BMI1NOTBM-NEXT: # %bb.1: 7351; X86-BMI1NOTBM-NEXT: movl %eax, %edi 7352; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 7353; X86-BMI1NOTBM-NEXT: .LBB58_2: 7354; X86-BMI1NOTBM-NEXT: movb $64, %cl 7355; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 7356; X86-BMI1NOTBM-NEXT: shldl %cl, %edi, %eax 7357; X86-BMI1NOTBM-NEXT: shll %cl, %edi 7358; X86-BMI1NOTBM-NEXT: testb $32, %cl 7359; X86-BMI1NOTBM-NEXT: movl %edi, %ebx 7360; X86-BMI1NOTBM-NEXT: jne .LBB58_4 7361; X86-BMI1NOTBM-NEXT: # %bb.3: 7362; X86-BMI1NOTBM-NEXT: movl %eax, %ebx 7363; X86-BMI1NOTBM-NEXT: .LBB58_4: 7364; X86-BMI1NOTBM-NEXT: movl %ebx, %eax 7365; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7366; X86-BMI1NOTBM-NEXT: testb $32, %cl 7367; X86-BMI1NOTBM-NEXT: movl $0, %edx 7368; X86-BMI1NOTBM-NEXT: jne .LBB58_6 7369; X86-BMI1NOTBM-NEXT: # %bb.5: 7370; X86-BMI1NOTBM-NEXT: movl %edi, %esi 7371; X86-BMI1NOTBM-NEXT: movl %eax, %edx 7372; X86-BMI1NOTBM-NEXT: .LBB58_6: 7373; X86-BMI1NOTBM-NEXT: shrdl %cl, %ebx, %esi 7374; X86-BMI1NOTBM-NEXT: testb $32, %cl 7375; X86-BMI1NOTBM-NEXT: jne .LBB58_8 7376; X86-BMI1NOTBM-NEXT: # %bb.7: 7377; X86-BMI1NOTBM-NEXT: movl %esi, %eax 7378; X86-BMI1NOTBM-NEXT: .LBB58_8: 7379; X86-BMI1NOTBM-NEXT: popl %esi 7380; X86-BMI1NOTBM-NEXT: popl %edi 7381; X86-BMI1NOTBM-NEXT: popl %ebx 7382; X86-BMI1NOTBM-NEXT: retl 7383; 7384; X86-BMI1BMI2-LABEL: bextr64_d2_load: 7385; X86-BMI1BMI2: # %bb.0: 7386; X86-BMI1BMI2-NEXT: pushl %edi 7387; X86-BMI1BMI2-NEXT: pushl %esi 7388; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 7389; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 7390; X86-BMI1BMI2-NEXT: movl (%edx), %eax 7391; X86-BMI1BMI2-NEXT: movl 4(%edx), %edx 7392; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %esi 7393; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 7394; X86-BMI1BMI2-NEXT: xorl %edx, %edx 7395; X86-BMI1BMI2-NEXT: testb $32, %cl 7396; X86-BMI1BMI2-NEXT: je .LBB58_2 7397; X86-BMI1BMI2-NEXT: # %bb.1: 7398; X86-BMI1BMI2-NEXT: movl %esi, %eax 7399; X86-BMI1BMI2-NEXT: xorl %esi, %esi 7400; X86-BMI1BMI2-NEXT: .LBB58_2: 7401; X86-BMI1BMI2-NEXT: movb $64, %cl 7402; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 7403; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %esi 7404; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %edi 7405; X86-BMI1BMI2-NEXT: testb $32, %cl 7406; X86-BMI1BMI2-NEXT: je .LBB58_4 7407; X86-BMI1BMI2-NEXT: # %bb.3: 7408; X86-BMI1BMI2-NEXT: movl %edi, %esi 7409; X86-BMI1BMI2-NEXT: movl $0, %edi 7410; X86-BMI1BMI2-NEXT: .LBB58_4: 7411; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax 7412; X86-BMI1BMI2-NEXT: jne .LBB58_6 7413; X86-BMI1BMI2-NEXT: # %bb.5: 7414; X86-BMI1BMI2-NEXT: movl %eax, %edx 7415; X86-BMI1BMI2-NEXT: .LBB58_6: 7416; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi 7417; X86-BMI1BMI2-NEXT: testb $32, %cl 7418; X86-BMI1BMI2-NEXT: jne .LBB58_8 7419; X86-BMI1BMI2-NEXT: # %bb.7: 7420; X86-BMI1BMI2-NEXT: movl %edi, %eax 7421; X86-BMI1BMI2-NEXT: .LBB58_8: 7422; X86-BMI1BMI2-NEXT: popl %esi 7423; X86-BMI1BMI2-NEXT: popl %edi 7424; X86-BMI1BMI2-NEXT: retl 7425; 7426; X64-NOBMI-LABEL: bextr64_d2_load: 7427; X64-NOBMI: # %bb.0: 7428; X64-NOBMI-NEXT: movq %rsi, %rcx 7429; X64-NOBMI-NEXT: movq (%rdi), %rax 7430; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 7431; X64-NOBMI-NEXT: shrq %cl, %rax 7432; X64-NOBMI-NEXT: negb %dl 7433; X64-NOBMI-NEXT: movl %edx, %ecx 7434; X64-NOBMI-NEXT: shlq %cl, %rax 7435; X64-NOBMI-NEXT: shrq %cl, %rax 7436; X64-NOBMI-NEXT: retq 7437; 7438; X64-BMI1NOTBM-LABEL: bextr64_d2_load: 7439; X64-BMI1NOTBM: # %bb.0: 7440; X64-BMI1NOTBM-NEXT: shll $8, %edx 7441; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 7442; X64-BMI1NOTBM-NEXT: orl %edx, %eax 7443; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax 7444; X64-BMI1NOTBM-NEXT: retq 7445; 7446; X64-BMI1BMI2-LABEL: bextr64_d2_load: 7447; X64-BMI1BMI2: # %bb.0: 7448; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %rax 7449; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 7450; X64-BMI1BMI2-NEXT: retq 7451 %val = load i64, i64* %w 7452 %shifted = lshr i64 %val, %numskipbits 7453 %numhighbits = sub i64 64, %numlowbits 7454 %highbitscleared = shl i64 %shifted, %numhighbits 7455 %masked = lshr i64 %highbitscleared, %numhighbits 7456 ret i64 %masked 7457} 7458 7459define i64 @bextr64_d3_load_indexzext(i64* %w, i8 %numskipbits, i8 %numlowbits) nounwind { 7460; X86-NOBMI-LABEL: bextr64_d3_load_indexzext: 7461; X86-NOBMI: # %bb.0: 7462; X86-NOBMI-NEXT: pushl %ebx 7463; X86-NOBMI-NEXT: pushl %edi 7464; X86-NOBMI-NEXT: pushl %esi 7465; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 7466; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 7467; X86-NOBMI-NEXT: movl (%eax), %edi 7468; X86-NOBMI-NEXT: movl 4(%eax), %edx 7469; X86-NOBMI-NEXT: movl %edx, %eax 7470; X86-NOBMI-NEXT: shrl %cl, %eax 7471; X86-NOBMI-NEXT: shrdl %cl, %edx, %edi 7472; X86-NOBMI-NEXT: xorl %esi, %esi 7473; X86-NOBMI-NEXT: testb $32, %cl 7474; X86-NOBMI-NEXT: je .LBB59_2 7475; X86-NOBMI-NEXT: # %bb.1: 7476; X86-NOBMI-NEXT: movl %eax, %edi 7477; X86-NOBMI-NEXT: xorl %eax, %eax 7478; X86-NOBMI-NEXT: .LBB59_2: 7479; X86-NOBMI-NEXT: movb $64, %cl 7480; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 7481; X86-NOBMI-NEXT: shldl %cl, %edi, %eax 7482; X86-NOBMI-NEXT: shll %cl, %edi 7483; X86-NOBMI-NEXT: testb $32, %cl 7484; X86-NOBMI-NEXT: movl %edi, %ebx 7485; X86-NOBMI-NEXT: jne .LBB59_4 7486; X86-NOBMI-NEXT: # %bb.3: 7487; X86-NOBMI-NEXT: movl %eax, %ebx 7488; X86-NOBMI-NEXT: .LBB59_4: 7489; X86-NOBMI-NEXT: movl %ebx, %eax 7490; X86-NOBMI-NEXT: shrl %cl, %eax 7491; X86-NOBMI-NEXT: testb $32, %cl 7492; X86-NOBMI-NEXT: movl $0, %edx 7493; X86-NOBMI-NEXT: jne .LBB59_6 7494; X86-NOBMI-NEXT: # %bb.5: 7495; X86-NOBMI-NEXT: movl %edi, %esi 7496; X86-NOBMI-NEXT: movl %eax, %edx 7497; X86-NOBMI-NEXT: .LBB59_6: 7498; X86-NOBMI-NEXT: shrdl %cl, %ebx, %esi 7499; X86-NOBMI-NEXT: testb $32, %cl 7500; X86-NOBMI-NEXT: jne .LBB59_8 7501; X86-NOBMI-NEXT: # %bb.7: 7502; X86-NOBMI-NEXT: movl %esi, %eax 7503; X86-NOBMI-NEXT: .LBB59_8: 7504; X86-NOBMI-NEXT: popl %esi 7505; X86-NOBMI-NEXT: popl %edi 7506; X86-NOBMI-NEXT: popl %ebx 7507; X86-NOBMI-NEXT: retl 7508; 7509; X86-BMI1NOTBM-LABEL: bextr64_d3_load_indexzext: 7510; X86-BMI1NOTBM: # %bb.0: 7511; X86-BMI1NOTBM-NEXT: pushl %ebx 7512; X86-BMI1NOTBM-NEXT: pushl %edi 7513; X86-BMI1NOTBM-NEXT: pushl %esi 7514; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 7515; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 7516; X86-BMI1NOTBM-NEXT: movl (%eax), %edi 7517; X86-BMI1NOTBM-NEXT: movl 4(%eax), %edx 7518; X86-BMI1NOTBM-NEXT: movl %edx, %eax 7519; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7520; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %edi 7521; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 7522; X86-BMI1NOTBM-NEXT: testb $32, %cl 7523; X86-BMI1NOTBM-NEXT: je .LBB59_2 7524; X86-BMI1NOTBM-NEXT: # %bb.1: 7525; X86-BMI1NOTBM-NEXT: movl %eax, %edi 7526; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 7527; X86-BMI1NOTBM-NEXT: .LBB59_2: 7528; X86-BMI1NOTBM-NEXT: movb $64, %cl 7529; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 7530; X86-BMI1NOTBM-NEXT: shldl %cl, %edi, %eax 7531; X86-BMI1NOTBM-NEXT: shll %cl, %edi 7532; X86-BMI1NOTBM-NEXT: testb $32, %cl 7533; X86-BMI1NOTBM-NEXT: movl %edi, %ebx 7534; X86-BMI1NOTBM-NEXT: jne .LBB59_4 7535; X86-BMI1NOTBM-NEXT: # %bb.3: 7536; X86-BMI1NOTBM-NEXT: movl %eax, %ebx 7537; X86-BMI1NOTBM-NEXT: .LBB59_4: 7538; X86-BMI1NOTBM-NEXT: movl %ebx, %eax 7539; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7540; X86-BMI1NOTBM-NEXT: testb $32, %cl 7541; X86-BMI1NOTBM-NEXT: movl $0, %edx 7542; X86-BMI1NOTBM-NEXT: jne .LBB59_6 7543; X86-BMI1NOTBM-NEXT: # %bb.5: 7544; X86-BMI1NOTBM-NEXT: movl %edi, %esi 7545; X86-BMI1NOTBM-NEXT: movl %eax, %edx 7546; X86-BMI1NOTBM-NEXT: .LBB59_6: 7547; X86-BMI1NOTBM-NEXT: shrdl %cl, %ebx, %esi 7548; X86-BMI1NOTBM-NEXT: testb $32, %cl 7549; X86-BMI1NOTBM-NEXT: jne .LBB59_8 7550; X86-BMI1NOTBM-NEXT: # %bb.7: 7551; X86-BMI1NOTBM-NEXT: movl %esi, %eax 7552; X86-BMI1NOTBM-NEXT: .LBB59_8: 7553; X86-BMI1NOTBM-NEXT: popl %esi 7554; X86-BMI1NOTBM-NEXT: popl %edi 7555; X86-BMI1NOTBM-NEXT: popl %ebx 7556; X86-BMI1NOTBM-NEXT: retl 7557; 7558; X86-BMI1BMI2-LABEL: bextr64_d3_load_indexzext: 7559; X86-BMI1BMI2: # %bb.0: 7560; X86-BMI1BMI2-NEXT: pushl %edi 7561; X86-BMI1BMI2-NEXT: pushl %esi 7562; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 7563; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 7564; X86-BMI1BMI2-NEXT: movl (%edx), %eax 7565; X86-BMI1BMI2-NEXT: movl 4(%edx), %edx 7566; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %esi 7567; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 7568; X86-BMI1BMI2-NEXT: xorl %edx, %edx 7569; X86-BMI1BMI2-NEXT: testb $32, %cl 7570; X86-BMI1BMI2-NEXT: je .LBB59_2 7571; X86-BMI1BMI2-NEXT: # %bb.1: 7572; X86-BMI1BMI2-NEXT: movl %esi, %eax 7573; X86-BMI1BMI2-NEXT: xorl %esi, %esi 7574; X86-BMI1BMI2-NEXT: .LBB59_2: 7575; X86-BMI1BMI2-NEXT: movb $64, %cl 7576; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 7577; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %esi 7578; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %edi 7579; X86-BMI1BMI2-NEXT: testb $32, %cl 7580; X86-BMI1BMI2-NEXT: je .LBB59_4 7581; X86-BMI1BMI2-NEXT: # %bb.3: 7582; X86-BMI1BMI2-NEXT: movl %edi, %esi 7583; X86-BMI1BMI2-NEXT: movl $0, %edi 7584; X86-BMI1BMI2-NEXT: .LBB59_4: 7585; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax 7586; X86-BMI1BMI2-NEXT: jne .LBB59_6 7587; X86-BMI1BMI2-NEXT: # %bb.5: 7588; X86-BMI1BMI2-NEXT: movl %eax, %edx 7589; X86-BMI1BMI2-NEXT: .LBB59_6: 7590; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi 7591; X86-BMI1BMI2-NEXT: testb $32, %cl 7592; X86-BMI1BMI2-NEXT: jne .LBB59_8 7593; X86-BMI1BMI2-NEXT: # %bb.7: 7594; X86-BMI1BMI2-NEXT: movl %edi, %eax 7595; X86-BMI1BMI2-NEXT: .LBB59_8: 7596; X86-BMI1BMI2-NEXT: popl %esi 7597; X86-BMI1BMI2-NEXT: popl %edi 7598; X86-BMI1BMI2-NEXT: retl 7599; 7600; X64-NOBMI-LABEL: bextr64_d3_load_indexzext: 7601; X64-NOBMI: # %bb.0: 7602; X64-NOBMI-NEXT: movl %esi, %ecx 7603; X64-NOBMI-NEXT: movq (%rdi), %rax 7604; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 7605; X64-NOBMI-NEXT: shrq %cl, %rax 7606; X64-NOBMI-NEXT: negb %dl 7607; X64-NOBMI-NEXT: movl %edx, %ecx 7608; X64-NOBMI-NEXT: shlq %cl, %rax 7609; X64-NOBMI-NEXT: shrq %cl, %rax 7610; X64-NOBMI-NEXT: retq 7611; 7612; X64-BMI1NOTBM-LABEL: bextr64_d3_load_indexzext: 7613; X64-BMI1NOTBM: # %bb.0: 7614; X64-BMI1NOTBM-NEXT: shll $8, %edx 7615; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 7616; X64-BMI1NOTBM-NEXT: orl %edx, %eax 7617; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax 7618; X64-BMI1NOTBM-NEXT: retq 7619; 7620; X64-BMI1BMI2-LABEL: bextr64_d3_load_indexzext: 7621; X64-BMI1BMI2: # %bb.0: 7622; X64-BMI1BMI2-NEXT: # kill: def $edx killed $edx def $rdx 7623; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi 7624; X64-BMI1BMI2-NEXT: shrxq %rsi, (%rdi), %rax 7625; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 7626; X64-BMI1BMI2-NEXT: retq 7627 %val = load i64, i64* %w 7628 %skip = zext i8 %numskipbits to i64 7629 %shifted = lshr i64 %val, %skip 7630 %numhighbits = sub i8 64, %numlowbits 7631 %sh_prom = zext i8 %numhighbits to i64 7632 %highbitscleared = shl i64 %shifted, %sh_prom 7633 %masked = lshr i64 %highbitscleared, %sh_prom 7634 ret i64 %masked 7635} 7636 7637define i64 @bextr64_d5_skipextrauses(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 7638; X86-NOBMI-LABEL: bextr64_d5_skipextrauses: 7639; X86-NOBMI: # %bb.0: 7640; X86-NOBMI-NEXT: pushl %ebp 7641; X86-NOBMI-NEXT: pushl %ebx 7642; X86-NOBMI-NEXT: pushl %edi 7643; X86-NOBMI-NEXT: pushl %esi 7644; X86-NOBMI-NEXT: subl $12, %esp 7645; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ebx 7646; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 7647; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 7648; X86-NOBMI-NEXT: movl %edx, %esi 7649; X86-NOBMI-NEXT: movl %eax, %ecx 7650; X86-NOBMI-NEXT: shrl %cl, %esi 7651; X86-NOBMI-NEXT: shrdl %cl, %edx, %ebx 7652; X86-NOBMI-NEXT: xorl %edx, %edx 7653; X86-NOBMI-NEXT: testb $32, %al 7654; X86-NOBMI-NEXT: je .LBB60_2 7655; X86-NOBMI-NEXT: # %bb.1: 7656; X86-NOBMI-NEXT: movl %esi, %ebx 7657; X86-NOBMI-NEXT: xorl %esi, %esi 7658; X86-NOBMI-NEXT: .LBB60_2: 7659; X86-NOBMI-NEXT: movb $64, %cl 7660; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 7661; X86-NOBMI-NEXT: shldl %cl, %ebx, %esi 7662; X86-NOBMI-NEXT: shll %cl, %ebx 7663; X86-NOBMI-NEXT: testb $32, %cl 7664; X86-NOBMI-NEXT: movl %ebx, %ebp 7665; X86-NOBMI-NEXT: jne .LBB60_4 7666; X86-NOBMI-NEXT: # %bb.3: 7667; X86-NOBMI-NEXT: movl %esi, %ebp 7668; X86-NOBMI-NEXT: .LBB60_4: 7669; X86-NOBMI-NEXT: movl %ebp, %esi 7670; X86-NOBMI-NEXT: shrl %cl, %esi 7671; X86-NOBMI-NEXT: testb $32, %cl 7672; X86-NOBMI-NEXT: movl $0, %edi 7673; X86-NOBMI-NEXT: jne .LBB60_6 7674; X86-NOBMI-NEXT: # %bb.5: 7675; X86-NOBMI-NEXT: movl %ebx, %edx 7676; X86-NOBMI-NEXT: movl %esi, %edi 7677; X86-NOBMI-NEXT: .LBB60_6: 7678; X86-NOBMI-NEXT: shrdl %cl, %ebp, %edx 7679; X86-NOBMI-NEXT: testb $32, %cl 7680; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 7681; X86-NOBMI-NEXT: jne .LBB60_8 7682; X86-NOBMI-NEXT: # %bb.7: 7683; X86-NOBMI-NEXT: movl %edx, %esi 7684; X86-NOBMI-NEXT: .LBB60_8: 7685; X86-NOBMI-NEXT: subl $8, %esp 7686; X86-NOBMI-NEXT: pushl %ecx 7687; X86-NOBMI-NEXT: pushl %eax 7688; X86-NOBMI-NEXT: calll use64 7689; X86-NOBMI-NEXT: addl $16, %esp 7690; X86-NOBMI-NEXT: movl %esi, %eax 7691; X86-NOBMI-NEXT: movl %edi, %edx 7692; X86-NOBMI-NEXT: addl $12, %esp 7693; X86-NOBMI-NEXT: popl %esi 7694; X86-NOBMI-NEXT: popl %edi 7695; X86-NOBMI-NEXT: popl %ebx 7696; X86-NOBMI-NEXT: popl %ebp 7697; X86-NOBMI-NEXT: retl 7698; 7699; X86-BMI1NOTBM-LABEL: bextr64_d5_skipextrauses: 7700; X86-BMI1NOTBM: # %bb.0: 7701; X86-BMI1NOTBM-NEXT: pushl %ebp 7702; X86-BMI1NOTBM-NEXT: pushl %ebx 7703; X86-BMI1NOTBM-NEXT: pushl %edi 7704; X86-BMI1NOTBM-NEXT: pushl %esi 7705; X86-BMI1NOTBM-NEXT: subl $12, %esp 7706; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ebx 7707; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 7708; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 7709; X86-BMI1NOTBM-NEXT: movl %edx, %esi 7710; X86-BMI1NOTBM-NEXT: movl %eax, %ecx 7711; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 7712; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %ebx 7713; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 7714; X86-BMI1NOTBM-NEXT: testb $32, %al 7715; X86-BMI1NOTBM-NEXT: je .LBB60_2 7716; X86-BMI1NOTBM-NEXT: # %bb.1: 7717; X86-BMI1NOTBM-NEXT: movl %esi, %ebx 7718; X86-BMI1NOTBM-NEXT: xorl %esi, %esi 7719; X86-BMI1NOTBM-NEXT: .LBB60_2: 7720; X86-BMI1NOTBM-NEXT: movb $64, %cl 7721; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 7722; X86-BMI1NOTBM-NEXT: shldl %cl, %ebx, %esi 7723; X86-BMI1NOTBM-NEXT: shll %cl, %ebx 7724; X86-BMI1NOTBM-NEXT: testb $32, %cl 7725; X86-BMI1NOTBM-NEXT: movl %ebx, %ebp 7726; X86-BMI1NOTBM-NEXT: jne .LBB60_4 7727; X86-BMI1NOTBM-NEXT: # %bb.3: 7728; X86-BMI1NOTBM-NEXT: movl %esi, %ebp 7729; X86-BMI1NOTBM-NEXT: .LBB60_4: 7730; X86-BMI1NOTBM-NEXT: movl %ebp, %esi 7731; X86-BMI1NOTBM-NEXT: shrl %cl, %esi 7732; X86-BMI1NOTBM-NEXT: testb $32, %cl 7733; X86-BMI1NOTBM-NEXT: movl $0, %edi 7734; X86-BMI1NOTBM-NEXT: jne .LBB60_6 7735; X86-BMI1NOTBM-NEXT: # %bb.5: 7736; X86-BMI1NOTBM-NEXT: movl %ebx, %edx 7737; X86-BMI1NOTBM-NEXT: movl %esi, %edi 7738; X86-BMI1NOTBM-NEXT: .LBB60_6: 7739; X86-BMI1NOTBM-NEXT: shrdl %cl, %ebp, %edx 7740; X86-BMI1NOTBM-NEXT: testb $32, %cl 7741; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ecx 7742; X86-BMI1NOTBM-NEXT: jne .LBB60_8 7743; X86-BMI1NOTBM-NEXT: # %bb.7: 7744; X86-BMI1NOTBM-NEXT: movl %edx, %esi 7745; X86-BMI1NOTBM-NEXT: .LBB60_8: 7746; X86-BMI1NOTBM-NEXT: subl $8, %esp 7747; X86-BMI1NOTBM-NEXT: pushl %ecx 7748; X86-BMI1NOTBM-NEXT: pushl %eax 7749; X86-BMI1NOTBM-NEXT: calll use64 7750; X86-BMI1NOTBM-NEXT: addl $16, %esp 7751; X86-BMI1NOTBM-NEXT: movl %esi, %eax 7752; X86-BMI1NOTBM-NEXT: movl %edi, %edx 7753; X86-BMI1NOTBM-NEXT: addl $12, %esp 7754; X86-BMI1NOTBM-NEXT: popl %esi 7755; X86-BMI1NOTBM-NEXT: popl %edi 7756; X86-BMI1NOTBM-NEXT: popl %ebx 7757; X86-BMI1NOTBM-NEXT: popl %ebp 7758; X86-BMI1NOTBM-NEXT: retl 7759; 7760; X86-BMI1BMI2-LABEL: bextr64_d5_skipextrauses: 7761; X86-BMI1BMI2: # %bb.0: 7762; X86-BMI1BMI2-NEXT: pushl %ebx 7763; X86-BMI1BMI2-NEXT: pushl %edi 7764; X86-BMI1BMI2-NEXT: pushl %esi 7765; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edi 7766; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 7767; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 7768; X86-BMI1BMI2-NEXT: movl %eax, %ecx 7769; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %edi 7770; X86-BMI1BMI2-NEXT: shrxl %eax, %edx, %edx 7771; X86-BMI1BMI2-NEXT: xorl %esi, %esi 7772; X86-BMI1BMI2-NEXT: testb $32, %al 7773; X86-BMI1BMI2-NEXT: je .LBB60_2 7774; X86-BMI1BMI2-NEXT: # %bb.1: 7775; X86-BMI1BMI2-NEXT: movl %edx, %edi 7776; X86-BMI1BMI2-NEXT: xorl %edx, %edx 7777; X86-BMI1BMI2-NEXT: .LBB60_2: 7778; X86-BMI1BMI2-NEXT: movb $64, %cl 7779; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 7780; X86-BMI1BMI2-NEXT: shldl %cl, %edi, %edx 7781; X86-BMI1BMI2-NEXT: shlxl %ecx, %edi, %ebx 7782; X86-BMI1BMI2-NEXT: testb $32, %cl 7783; X86-BMI1BMI2-NEXT: je .LBB60_4 7784; X86-BMI1BMI2-NEXT: # %bb.3: 7785; X86-BMI1BMI2-NEXT: movl %ebx, %edx 7786; X86-BMI1BMI2-NEXT: movl $0, %ebx 7787; X86-BMI1BMI2-NEXT: .LBB60_4: 7788; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edi 7789; X86-BMI1BMI2-NEXT: jne .LBB60_6 7790; X86-BMI1BMI2-NEXT: # %bb.5: 7791; X86-BMI1BMI2-NEXT: movl %edi, %esi 7792; X86-BMI1BMI2-NEXT: .LBB60_6: 7793; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %ebx 7794; X86-BMI1BMI2-NEXT: testb $32, %cl 7795; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 7796; X86-BMI1BMI2-NEXT: jne .LBB60_8 7797; X86-BMI1BMI2-NEXT: # %bb.7: 7798; X86-BMI1BMI2-NEXT: movl %ebx, %edi 7799; X86-BMI1BMI2-NEXT: .LBB60_8: 7800; X86-BMI1BMI2-NEXT: subl $8, %esp 7801; X86-BMI1BMI2-NEXT: pushl %ecx 7802; X86-BMI1BMI2-NEXT: pushl %eax 7803; X86-BMI1BMI2-NEXT: calll use64 7804; X86-BMI1BMI2-NEXT: addl $16, %esp 7805; X86-BMI1BMI2-NEXT: movl %edi, %eax 7806; X86-BMI1BMI2-NEXT: movl %esi, %edx 7807; X86-BMI1BMI2-NEXT: popl %esi 7808; X86-BMI1BMI2-NEXT: popl %edi 7809; X86-BMI1BMI2-NEXT: popl %ebx 7810; X86-BMI1BMI2-NEXT: retl 7811; 7812; X64-NOBMI-LABEL: bextr64_d5_skipextrauses: 7813; X64-NOBMI: # %bb.0: 7814; X64-NOBMI-NEXT: pushq %rbx 7815; X64-NOBMI-NEXT: movq %rdi, %rbx 7816; X64-NOBMI-NEXT: movl %esi, %ecx 7817; X64-NOBMI-NEXT: shrq %cl, %rbx 7818; X64-NOBMI-NEXT: negb %dl 7819; X64-NOBMI-NEXT: movl %edx, %ecx 7820; X64-NOBMI-NEXT: shlq %cl, %rbx 7821; X64-NOBMI-NEXT: shrq %cl, %rbx 7822; X64-NOBMI-NEXT: movq %rsi, %rdi 7823; X64-NOBMI-NEXT: callq use64 7824; X64-NOBMI-NEXT: movq %rbx, %rax 7825; X64-NOBMI-NEXT: popq %rbx 7826; X64-NOBMI-NEXT: retq 7827; 7828; X64-BMI1NOTBM-LABEL: bextr64_d5_skipextrauses: 7829; X64-BMI1NOTBM: # %bb.0: 7830; X64-BMI1NOTBM-NEXT: pushq %rbx 7831; X64-BMI1NOTBM-NEXT: shll $8, %edx 7832; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 7833; X64-BMI1NOTBM-NEXT: orl %edx, %eax 7834; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rbx 7835; X64-BMI1NOTBM-NEXT: movq %rsi, %rdi 7836; X64-BMI1NOTBM-NEXT: callq use64 7837; X64-BMI1NOTBM-NEXT: movq %rbx, %rax 7838; X64-BMI1NOTBM-NEXT: popq %rbx 7839; X64-BMI1NOTBM-NEXT: retq 7840; 7841; X64-BMI1BMI2-LABEL: bextr64_d5_skipextrauses: 7842; X64-BMI1BMI2: # %bb.0: 7843; X64-BMI1BMI2-NEXT: pushq %rbx 7844; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 7845; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rbx 7846; X64-BMI1BMI2-NEXT: movq %rsi, %rdi 7847; X64-BMI1BMI2-NEXT: callq use64 7848; X64-BMI1BMI2-NEXT: movq %rbx, %rax 7849; X64-BMI1BMI2-NEXT: popq %rbx 7850; X64-BMI1BMI2-NEXT: retq 7851 %shifted = lshr i64 %val, %numskipbits 7852 %numhighbits = sub i64 64, %numlowbits 7853 %highbitscleared = shl i64 %shifted, %numhighbits 7854 %masked = lshr i64 %highbitscleared, %numhighbits 7855 call void @use64(i64 %numskipbits) 7856 ret i64 %masked 7857} 7858 7859; 64-bit, but with 32-bit output 7860 7861; Everything done in 64-bit, truncation happens last. 7862define i32 @bextr64_32_d0(i64 %val, i64 %numskipbits, i64 %numlowbits) nounwind { 7863; X86-NOBMI-LABEL: bextr64_32_d0: 7864; X86-NOBMI: # %bb.0: 7865; X86-NOBMI-NEXT: pushl %esi 7866; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 7867; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 7868; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 7869; X86-NOBMI-NEXT: movl %esi, %eax 7870; X86-NOBMI-NEXT: shrl %cl, %eax 7871; X86-NOBMI-NEXT: shrdl %cl, %esi, %edx 7872; X86-NOBMI-NEXT: testb $32, %cl 7873; X86-NOBMI-NEXT: je .LBB61_2 7874; X86-NOBMI-NEXT: # %bb.1: 7875; X86-NOBMI-NEXT: movl %eax, %edx 7876; X86-NOBMI-NEXT: xorl %eax, %eax 7877; X86-NOBMI-NEXT: .LBB61_2: 7878; X86-NOBMI-NEXT: movb $64, %cl 7879; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 7880; X86-NOBMI-NEXT: shldl %cl, %edx, %eax 7881; X86-NOBMI-NEXT: shll %cl, %edx 7882; X86-NOBMI-NEXT: testb $32, %cl 7883; X86-NOBMI-NEXT: je .LBB61_4 7884; X86-NOBMI-NEXT: # %bb.3: 7885; X86-NOBMI-NEXT: movl %edx, %eax 7886; X86-NOBMI-NEXT: xorl %edx, %edx 7887; X86-NOBMI-NEXT: .LBB61_4: 7888; X86-NOBMI-NEXT: shrdl %cl, %eax, %edx 7889; X86-NOBMI-NEXT: shrl %cl, %eax 7890; X86-NOBMI-NEXT: testb $32, %cl 7891; X86-NOBMI-NEXT: jne .LBB61_6 7892; X86-NOBMI-NEXT: # %bb.5: 7893; X86-NOBMI-NEXT: movl %edx, %eax 7894; X86-NOBMI-NEXT: .LBB61_6: 7895; X86-NOBMI-NEXT: popl %esi 7896; X86-NOBMI-NEXT: retl 7897; 7898; X86-BMI1NOTBM-LABEL: bextr64_32_d0: 7899; X86-BMI1NOTBM: # %bb.0: 7900; X86-BMI1NOTBM-NEXT: pushl %esi 7901; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 7902; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx 7903; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 7904; X86-BMI1NOTBM-NEXT: movl %esi, %eax 7905; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7906; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %edx 7907; X86-BMI1NOTBM-NEXT: testb $32, %cl 7908; X86-BMI1NOTBM-NEXT: je .LBB61_2 7909; X86-BMI1NOTBM-NEXT: # %bb.1: 7910; X86-BMI1NOTBM-NEXT: movl %eax, %edx 7911; X86-BMI1NOTBM-NEXT: xorl %eax, %eax 7912; X86-BMI1NOTBM-NEXT: .LBB61_2: 7913; X86-BMI1NOTBM-NEXT: movb $64, %cl 7914; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl 7915; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %eax 7916; X86-BMI1NOTBM-NEXT: shll %cl, %edx 7917; X86-BMI1NOTBM-NEXT: testb $32, %cl 7918; X86-BMI1NOTBM-NEXT: je .LBB61_4 7919; X86-BMI1NOTBM-NEXT: # %bb.3: 7920; X86-BMI1NOTBM-NEXT: movl %edx, %eax 7921; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 7922; X86-BMI1NOTBM-NEXT: .LBB61_4: 7923; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %edx 7924; X86-BMI1NOTBM-NEXT: shrl %cl, %eax 7925; X86-BMI1NOTBM-NEXT: testb $32, %cl 7926; X86-BMI1NOTBM-NEXT: jne .LBB61_6 7927; X86-BMI1NOTBM-NEXT: # %bb.5: 7928; X86-BMI1NOTBM-NEXT: movl %edx, %eax 7929; X86-BMI1NOTBM-NEXT: .LBB61_6: 7930; X86-BMI1NOTBM-NEXT: popl %esi 7931; X86-BMI1NOTBM-NEXT: retl 7932; 7933; X86-BMI1BMI2-LABEL: bextr64_32_d0: 7934; X86-BMI1BMI2: # %bb.0: 7935; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 7936; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 7937; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 7938; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 7939; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %edx 7940; X86-BMI1BMI2-NEXT: testb $32, %cl 7941; X86-BMI1BMI2-NEXT: je .LBB61_2 7942; X86-BMI1BMI2-NEXT: # %bb.1: 7943; X86-BMI1BMI2-NEXT: movl %edx, %eax 7944; X86-BMI1BMI2-NEXT: xorl %edx, %edx 7945; X86-BMI1BMI2-NEXT: .LBB61_2: 7946; X86-BMI1BMI2-NEXT: movb $64, %cl 7947; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl 7948; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx 7949; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax 7950; X86-BMI1BMI2-NEXT: testb $32, %cl 7951; X86-BMI1BMI2-NEXT: je .LBB61_4 7952; X86-BMI1BMI2-NEXT: # %bb.3: 7953; X86-BMI1BMI2-NEXT: movl %eax, %edx 7954; X86-BMI1BMI2-NEXT: xorl %eax, %eax 7955; X86-BMI1BMI2-NEXT: .LBB61_4: 7956; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax 7957; X86-BMI1BMI2-NEXT: testb $32, %cl 7958; X86-BMI1BMI2-NEXT: je .LBB61_6 7959; X86-BMI1BMI2-NEXT: # %bb.5: 7960; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %eax 7961; X86-BMI1BMI2-NEXT: .LBB61_6: 7962; X86-BMI1BMI2-NEXT: retl 7963; 7964; X64-NOBMI-LABEL: bextr64_32_d0: 7965; X64-NOBMI: # %bb.0: 7966; X64-NOBMI-NEXT: movq %rsi, %rcx 7967; X64-NOBMI-NEXT: movq %rdi, %rax 7968; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 7969; X64-NOBMI-NEXT: shrq %cl, %rax 7970; X64-NOBMI-NEXT: negb %dl 7971; X64-NOBMI-NEXT: movl %edx, %ecx 7972; X64-NOBMI-NEXT: shlq %cl, %rax 7973; X64-NOBMI-NEXT: shrq %cl, %rax 7974; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 7975; X64-NOBMI-NEXT: retq 7976; 7977; X64-BMI1NOTBM-LABEL: bextr64_32_d0: 7978; X64-BMI1NOTBM: # %bb.0: 7979; X64-BMI1NOTBM-NEXT: shll $8, %edx 7980; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 7981; X64-BMI1NOTBM-NEXT: orl %edx, %eax 7982; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 7983; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 7984; X64-BMI1NOTBM-NEXT: retq 7985; 7986; X64-BMI1BMI2-LABEL: bextr64_32_d0: 7987; X64-BMI1BMI2: # %bb.0: 7988; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 7989; X64-BMI1BMI2-NEXT: bzhiq %rdx, %rax, %rax 7990; X64-BMI1BMI2-NEXT: # kill: def $eax killed $eax killed $rax 7991; X64-BMI1BMI2-NEXT: retq 7992 %shifted = lshr i64 %val, %numskipbits 7993 %numhighbits = sub i64 64, %numlowbits 7994 %highbitscleared = shl i64 %shifted, %numhighbits 7995 %masked = lshr i64 %highbitscleared, %numhighbits 7996 %res = trunc i64 %masked to i32 7997 ret i32 %res 7998} 7999 8000; Shifting happens in 64-bit, then truncation. Masking is 32-bit. 8001define i32 @bextr64_32_d1(i64 %val, i64 %numskipbits, i32 %numlowbits) nounwind { 8002; X86-NOBMI-LABEL: bextr64_32_d1: 8003; X86-NOBMI: # %bb.0: 8004; X86-NOBMI-NEXT: pushl %esi 8005; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl 8006; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx 8007; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi 8008; X86-NOBMI-NEXT: movl %esi, %eax 8009; X86-NOBMI-NEXT: shrl %cl, %eax 8010; X86-NOBMI-NEXT: shrdl %cl, %esi, %edx 8011; X86-NOBMI-NEXT: testb $32, %cl 8012; X86-NOBMI-NEXT: jne .LBB62_2 8013; X86-NOBMI-NEXT: # %bb.1: 8014; X86-NOBMI-NEXT: movl %edx, %eax 8015; X86-NOBMI-NEXT: .LBB62_2: 8016; X86-NOBMI-NEXT: xorl %ecx, %ecx 8017; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl 8018; X86-NOBMI-NEXT: shll %cl, %eax 8019; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx 8020; X86-NOBMI-NEXT: shrl %cl, %eax 8021; X86-NOBMI-NEXT: popl %esi 8022; X86-NOBMI-NEXT: retl 8023; 8024; X86-BMI1NOTBM-LABEL: bextr64_32_d1: 8025; X86-BMI1NOTBM: # %bb.0: 8026; X86-BMI1NOTBM-NEXT: pushl %edi 8027; X86-BMI1NOTBM-NEXT: pushl %esi 8028; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al 8029; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl 8030; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi 8031; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edi 8032; X86-BMI1NOTBM-NEXT: movl %edi, %edx 8033; X86-BMI1NOTBM-NEXT: shrl %cl, %edx 8034; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %esi 8035; X86-BMI1NOTBM-NEXT: testb $32, %cl 8036; X86-BMI1NOTBM-NEXT: jne .LBB62_2 8037; X86-BMI1NOTBM-NEXT: # %bb.1: 8038; X86-BMI1NOTBM-NEXT: movl %esi, %edx 8039; X86-BMI1NOTBM-NEXT: .LBB62_2: 8040; X86-BMI1NOTBM-NEXT: shll $8, %eax 8041; X86-BMI1NOTBM-NEXT: bextrl %eax, %edx, %eax 8042; X86-BMI1NOTBM-NEXT: popl %esi 8043; X86-BMI1NOTBM-NEXT: popl %edi 8044; X86-BMI1NOTBM-NEXT: retl 8045; 8046; X86-BMI1BMI2-LABEL: bextr64_32_d1: 8047; X86-BMI1BMI2: # %bb.0: 8048; X86-BMI1BMI2-NEXT: pushl %esi 8049; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al 8050; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl 8051; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx 8052; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi 8053; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edx 8054; X86-BMI1BMI2-NEXT: testb $32, %cl 8055; X86-BMI1BMI2-NEXT: je .LBB62_2 8056; X86-BMI1BMI2-NEXT: # %bb.1: 8057; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edx 8058; X86-BMI1BMI2-NEXT: .LBB62_2: 8059; X86-BMI1BMI2-NEXT: bzhil %eax, %edx, %eax 8060; X86-BMI1BMI2-NEXT: popl %esi 8061; X86-BMI1BMI2-NEXT: retl 8062; 8063; X64-NOBMI-LABEL: bextr64_32_d1: 8064; X64-NOBMI: # %bb.0: 8065; X64-NOBMI-NEXT: movq %rsi, %rcx 8066; X64-NOBMI-NEXT: movq %rdi, %rax 8067; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx 8068; X64-NOBMI-NEXT: shrq %cl, %rax 8069; X64-NOBMI-NEXT: negb %dl 8070; X64-NOBMI-NEXT: movl %edx, %ecx 8071; X64-NOBMI-NEXT: shll %cl, %eax 8072; X64-NOBMI-NEXT: shrl %cl, %eax 8073; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax 8074; X64-NOBMI-NEXT: retq 8075; 8076; X64-BMI1NOTBM-LABEL: bextr64_32_d1: 8077; X64-BMI1NOTBM: # %bb.0: 8078; X64-BMI1NOTBM-NEXT: shll $8, %edx 8079; X64-BMI1NOTBM-NEXT: movzbl %sil, %eax 8080; X64-BMI1NOTBM-NEXT: orl %edx, %eax 8081; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 8082; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax 8083; X64-BMI1NOTBM-NEXT: retq 8084; 8085; X64-BMI1BMI2-LABEL: bextr64_32_d1: 8086; X64-BMI1BMI2: # %bb.0: 8087; X64-BMI1BMI2-NEXT: shrxq %rsi, %rdi, %rax 8088; X64-BMI1BMI2-NEXT: bzhil %edx, %eax, %eax 8089; X64-BMI1BMI2-NEXT: retq 8090 %shifted = lshr i64 %val, %numskipbits 8091 %truncshifted = trunc i64 %shifted to i32 8092 %numhighbits = sub i32 32, %numlowbits 8093 %highbitscleared = shl i32 %truncshifted, %numhighbits 8094 %masked = lshr i32 %highbitscleared, %numhighbits 8095 ret i32 %masked 8096} 8097 8098; ---------------------------------------------------------------------------- ; 8099; Constant 8100; ---------------------------------------------------------------------------- ; 8101 8102; https://bugs.llvm.org/show_bug.cgi?id=38938 8103define void @pr38938(i32* %a0, i64* %a1) nounwind { 8104; X86-NOBMI-LABEL: pr38938: 8105; X86-NOBMI: # %bb.0: 8106; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8107; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 8108; X86-NOBMI-NEXT: movl (%ecx), %ecx 8109; X86-NOBMI-NEXT: shrl $19, %ecx 8110; X86-NOBMI-NEXT: andl $4092, %ecx # imm = 0xFFC 8111; X86-NOBMI-NEXT: incl (%eax,%ecx) 8112; X86-NOBMI-NEXT: retl 8113; 8114; X86-BMI1NOTBM-LABEL: pr38938: 8115; X86-BMI1NOTBM: # %bb.0: 8116; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8117; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %ecx 8118; X86-BMI1NOTBM-NEXT: movl $2581, %edx # imm = 0xA15 8119; X86-BMI1NOTBM-NEXT: bextrl %edx, (%ecx), %ecx 8120; X86-BMI1NOTBM-NEXT: incl (%eax,%ecx,4) 8121; X86-BMI1NOTBM-NEXT: retl 8122; 8123; X86-BMI1TBM-LABEL: pr38938: 8124; X86-BMI1TBM: # %bb.0: 8125; X86-BMI1TBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8126; X86-BMI1TBM-NEXT: movl {{[0-9]+}}(%esp), %ecx 8127; X86-BMI1TBM-NEXT: bextrl $2581, (%ecx), %ecx # imm = 0xA15 8128; X86-BMI1TBM-NEXT: incl (%eax,%ecx,4) 8129; X86-BMI1TBM-NEXT: retl 8130; 8131; X86-BMI1NOTBMBMI2-LABEL: pr38938: 8132; X86-BMI1NOTBMBMI2: # %bb.0: 8133; X86-BMI1NOTBMBMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 8134; X86-BMI1NOTBMBMI2-NEXT: movl {{[0-9]+}}(%esp), %ecx 8135; X86-BMI1NOTBMBMI2-NEXT: movl $2581, %edx # imm = 0xA15 8136; X86-BMI1NOTBMBMI2-NEXT: bextrl %edx, (%ecx), %ecx 8137; X86-BMI1NOTBMBMI2-NEXT: incl (%eax,%ecx,4) 8138; X86-BMI1NOTBMBMI2-NEXT: retl 8139; 8140; X64-NOBMI-LABEL: pr38938: 8141; X64-NOBMI: # %bb.0: 8142; X64-NOBMI-NEXT: movq (%rsi), %rax 8143; X64-NOBMI-NEXT: shrq $19, %rax 8144; X64-NOBMI-NEXT: andl $4092, %eax # imm = 0xFFC 8145; X64-NOBMI-NEXT: incl (%rdi,%rax) 8146; X64-NOBMI-NEXT: retq 8147; 8148; X64-BMI1NOTBM-LABEL: pr38938: 8149; X64-BMI1NOTBM: # %bb.0: 8150; X64-BMI1NOTBM-NEXT: movl $2581, %eax # imm = 0xA15 8151; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rsi), %rax 8152; X64-BMI1NOTBM-NEXT: incl (%rdi,%rax,4) 8153; X64-BMI1NOTBM-NEXT: retq 8154; 8155; X64-BMI1TBM-LABEL: pr38938: 8156; X64-BMI1TBM: # %bb.0: 8157; X64-BMI1TBM-NEXT: bextrq $2581, (%rsi), %rax # imm = 0xA15 8158; X64-BMI1TBM-NEXT: incl (%rdi,%rax,4) 8159; X64-BMI1TBM-NEXT: retq 8160; 8161; X64-BMI1NOTBMBMI2-LABEL: pr38938: 8162; X64-BMI1NOTBMBMI2: # %bb.0: 8163; X64-BMI1NOTBMBMI2-NEXT: movl $2581, %eax # imm = 0xA15 8164; X64-BMI1NOTBMBMI2-NEXT: bextrq %rax, (%rsi), %rax 8165; X64-BMI1NOTBMBMI2-NEXT: incl (%rdi,%rax,4) 8166; X64-BMI1NOTBMBMI2-NEXT: retq 8167 %tmp = load i64, i64* %a1, align 8 8168 %tmp1 = lshr i64 %tmp, 21 8169 %tmp2 = and i64 %tmp1, 1023 8170 %tmp3 = getelementptr inbounds i32, i32* %a0, i64 %tmp2 8171 %tmp4 = load i32, i32* %tmp3, align 4 8172 %tmp5 = add nsw i32 %tmp4, 1 8173 store i32 %tmp5, i32* %tmp3, align 4 8174 ret void 8175} 8176 8177; The most canonical variant 8178define i32 @c0_i32(i32 %arg) nounwind { 8179; X86-NOBMI-LABEL: c0_i32: 8180; X86-NOBMI: # %bb.0: 8181; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8182; X86-NOBMI-NEXT: shrl $19, %eax 8183; X86-NOBMI-NEXT: andl $1023, %eax # imm = 0x3FF 8184; X86-NOBMI-NEXT: retl 8185; 8186; X86-BMI1NOTBM-LABEL: c0_i32: 8187; X86-BMI1NOTBM: # %bb.0: 8188; X86-BMI1NOTBM-NEXT: movl $2579, %eax # imm = 0xA13 8189; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax 8190; X86-BMI1NOTBM-NEXT: retl 8191; 8192; X86-BMI1TBM-LABEL: c0_i32: 8193; X86-BMI1TBM: # %bb.0: 8194; X86-BMI1TBM-NEXT: bextrl $2579, {{[0-9]+}}(%esp), %eax # imm = 0xA13 8195; X86-BMI1TBM-NEXT: retl 8196; 8197; X86-BMI1NOTBMBMI2-LABEL: c0_i32: 8198; X86-BMI1NOTBMBMI2: # %bb.0: 8199; X86-BMI1NOTBMBMI2-NEXT: movl $2579, %eax # imm = 0xA13 8200; X86-BMI1NOTBMBMI2-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax 8201; X86-BMI1NOTBMBMI2-NEXT: retl 8202; 8203; X64-NOBMI-LABEL: c0_i32: 8204; X64-NOBMI: # %bb.0: 8205; X64-NOBMI-NEXT: movl %edi, %eax 8206; X64-NOBMI-NEXT: shrl $19, %eax 8207; X64-NOBMI-NEXT: andl $1023, %eax # imm = 0x3FF 8208; X64-NOBMI-NEXT: retq 8209; 8210; X64-BMI1NOTBM-LABEL: c0_i32: 8211; X64-BMI1NOTBM: # %bb.0: 8212; X64-BMI1NOTBM-NEXT: movl $2579, %eax # imm = 0xA13 8213; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 8214; X64-BMI1NOTBM-NEXT: retq 8215; 8216; X64-BMI1TBM-LABEL: c0_i32: 8217; X64-BMI1TBM: # %bb.0: 8218; X64-BMI1TBM-NEXT: bextrl $2579, %edi, %eax # imm = 0xA13 8219; X64-BMI1TBM-NEXT: retq 8220; 8221; X64-BMI1NOTBMBMI2-LABEL: c0_i32: 8222; X64-BMI1NOTBMBMI2: # %bb.0: 8223; X64-BMI1NOTBMBMI2-NEXT: movl $2579, %eax # imm = 0xA13 8224; X64-BMI1NOTBMBMI2-NEXT: bextrl %eax, %edi, %eax 8225; X64-BMI1NOTBMBMI2-NEXT: retq 8226 %tmp0 = lshr i32 %arg, 19 8227 %tmp1 = and i32 %tmp0, 1023 8228 ret i32 %tmp1 8229} 8230 8231; Should be still fine, but the mask is shifted 8232define i32 @c1_i32(i32 %arg) nounwind { 8233; X86-LABEL: c1_i32: 8234; X86: # %bb.0: 8235; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8236; X86-NEXT: shrl $19, %eax 8237; X86-NEXT: andl $4092, %eax # imm = 0xFFC 8238; X86-NEXT: retl 8239; 8240; X64-LABEL: c1_i32: 8241; X64: # %bb.0: 8242; X64-NEXT: movl %edi, %eax 8243; X64-NEXT: shrl $19, %eax 8244; X64-NEXT: andl $4092, %eax # imm = 0xFFC 8245; X64-NEXT: retq 8246 %tmp0 = lshr i32 %arg, 19 8247 %tmp1 = and i32 %tmp0, 4092 8248 ret i32 %tmp1 8249} 8250 8251; Should be still fine, but the result is shifted left afterwards 8252define i32 @c2_i32(i32 %arg) nounwind { 8253; X86-LABEL: c2_i32: 8254; X86: # %bb.0: 8255; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8256; X86-NEXT: shrl $17, %eax 8257; X86-NEXT: andl $4092, %eax # imm = 0xFFC 8258; X86-NEXT: retl 8259; 8260; X64-LABEL: c2_i32: 8261; X64: # %bb.0: 8262; X64-NEXT: movl %edi, %eax 8263; X64-NEXT: shrl $17, %eax 8264; X64-NEXT: andl $4092, %eax # imm = 0xFFC 8265; X64-NEXT: retq 8266 %tmp0 = lshr i32 %arg, 19 8267 %tmp1 = and i32 %tmp0, 1023 8268 %tmp2 = shl i32 %tmp1, 2 8269 ret i32 %tmp2 8270} 8271 8272; The mask covers newly shifted-in bit 8273define i32 @c4_i32_bad(i32 %arg) nounwind { 8274; X86-LABEL: c4_i32_bad: 8275; X86: # %bb.0: 8276; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8277; X86-NEXT: shrl $19, %eax 8278; X86-NEXT: andl $-2, %eax 8279; X86-NEXT: retl 8280; 8281; X64-LABEL: c4_i32_bad: 8282; X64: # %bb.0: 8283; X64-NEXT: movl %edi, %eax 8284; X64-NEXT: shrl $19, %eax 8285; X64-NEXT: andl $-2, %eax 8286; X64-NEXT: retq 8287 %tmp0 = lshr i32 %arg, 19 8288 %tmp1 = and i32 %tmp0, 16382 8289 ret i32 %tmp1 8290} 8291 8292; i64 8293 8294; The most canonical variant 8295define i64 @c0_i64(i64 %arg) nounwind { 8296; X86-NOBMI-LABEL: c0_i64: 8297; X86-NOBMI: # %bb.0: 8298; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8299; X86-NOBMI-NEXT: shrl $19, %eax 8300; X86-NOBMI-NEXT: andl $1023, %eax # imm = 0x3FF 8301; X86-NOBMI-NEXT: xorl %edx, %edx 8302; X86-NOBMI-NEXT: retl 8303; 8304; X86-BMI1NOTBM-LABEL: c0_i64: 8305; X86-BMI1NOTBM: # %bb.0: 8306; X86-BMI1NOTBM-NEXT: movl $2579, %eax # imm = 0xA13 8307; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax 8308; X86-BMI1NOTBM-NEXT: xorl %edx, %edx 8309; X86-BMI1NOTBM-NEXT: retl 8310; 8311; X86-BMI1TBM-LABEL: c0_i64: 8312; X86-BMI1TBM: # %bb.0: 8313; X86-BMI1TBM-NEXT: bextrl $2579, {{[0-9]+}}(%esp), %eax # imm = 0xA13 8314; X86-BMI1TBM-NEXT: xorl %edx, %edx 8315; X86-BMI1TBM-NEXT: retl 8316; 8317; X86-BMI1NOTBMBMI2-LABEL: c0_i64: 8318; X86-BMI1NOTBMBMI2: # %bb.0: 8319; X86-BMI1NOTBMBMI2-NEXT: movl $2579, %eax # imm = 0xA13 8320; X86-BMI1NOTBMBMI2-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax 8321; X86-BMI1NOTBMBMI2-NEXT: xorl %edx, %edx 8322; X86-BMI1NOTBMBMI2-NEXT: retl 8323; 8324; X64-NOBMI-LABEL: c0_i64: 8325; X64-NOBMI: # %bb.0: 8326; X64-NOBMI-NEXT: movq %rdi, %rax 8327; X64-NOBMI-NEXT: shrq $51, %rax 8328; X64-NOBMI-NEXT: andl $1023, %eax # imm = 0x3FF 8329; X64-NOBMI-NEXT: retq 8330; 8331; X64-BMI1NOTBM-LABEL: c0_i64: 8332; X64-BMI1NOTBM: # %bb.0: 8333; X64-BMI1NOTBM-NEXT: movl $2611, %eax # imm = 0xA33 8334; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 8335; X64-BMI1NOTBM-NEXT: retq 8336; 8337; X64-BMI1TBM-LABEL: c0_i64: 8338; X64-BMI1TBM: # %bb.0: 8339; X64-BMI1TBM-NEXT: bextrq $2611, %rdi, %rax # imm = 0xA33 8340; X64-BMI1TBM-NEXT: retq 8341; 8342; X64-BMI1NOTBMBMI2-LABEL: c0_i64: 8343; X64-BMI1NOTBMBMI2: # %bb.0: 8344; X64-BMI1NOTBMBMI2-NEXT: movl $2611, %eax # imm = 0xA33 8345; X64-BMI1NOTBMBMI2-NEXT: bextrq %rax, %rdi, %rax 8346; X64-BMI1NOTBMBMI2-NEXT: retq 8347 %tmp0 = lshr i64 %arg, 51 8348 %tmp1 = and i64 %tmp0, 1023 8349 ret i64 %tmp1 8350} 8351 8352; Should be still fine, but the mask is shifted 8353define i64 @c1_i64(i64 %arg) nounwind { 8354; X86-LABEL: c1_i64: 8355; X86: # %bb.0: 8356; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8357; X86-NEXT: shrl $19, %eax 8358; X86-NEXT: andl $4092, %eax # imm = 0xFFC 8359; X86-NEXT: xorl %edx, %edx 8360; X86-NEXT: retl 8361; 8362; X64-LABEL: c1_i64: 8363; X64: # %bb.0: 8364; X64-NEXT: movq %rdi, %rax 8365; X64-NEXT: shrq $51, %rax 8366; X64-NEXT: andl $4092, %eax # imm = 0xFFC 8367; X64-NEXT: retq 8368 %tmp0 = lshr i64 %arg, 51 8369 %tmp1 = and i64 %tmp0, 4092 8370 ret i64 %tmp1 8371} 8372 8373; Should be still fine, but the result is shifted left afterwards 8374define i64 @c2_i64(i64 %arg) nounwind { 8375; X86-LABEL: c2_i64: 8376; X86: # %bb.0: 8377; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8378; X86-NEXT: shrl $17, %eax 8379; X86-NEXT: andl $4092, %eax # imm = 0xFFC 8380; X86-NEXT: xorl %edx, %edx 8381; X86-NEXT: retl 8382; 8383; X64-LABEL: c2_i64: 8384; X64: # %bb.0: 8385; X64-NEXT: movq %rdi, %rax 8386; X64-NEXT: shrq $49, %rax 8387; X64-NEXT: andl $4092, %eax # imm = 0xFFC 8388; X64-NEXT: retq 8389 %tmp0 = lshr i64 %arg, 51 8390 %tmp1 = and i64 %tmp0, 1023 8391 %tmp2 = shl i64 %tmp1, 2 8392 ret i64 %tmp2 8393} 8394 8395; The mask covers newly shifted-in bit 8396define i64 @c4_i64_bad(i64 %arg) nounwind { 8397; X86-LABEL: c4_i64_bad: 8398; X86: # %bb.0: 8399; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8400; X86-NEXT: shrl $19, %eax 8401; X86-NEXT: andl $-2, %eax 8402; X86-NEXT: xorl %edx, %edx 8403; X86-NEXT: retl 8404; 8405; X64-LABEL: c4_i64_bad: 8406; X64: # %bb.0: 8407; X64-NEXT: movq %rdi, %rax 8408; X64-NEXT: shrq $51, %rax 8409; X64-NEXT: andl $-2, %eax 8410; X64-NEXT: retq 8411 %tmp0 = lshr i64 %arg, 51 8412 %tmp1 = and i64 %tmp0, 16382 8413 ret i64 %tmp1 8414} 8415 8416; ---------------------------------------------------------------------------- ; 8417; Constant, storing the result afterwards. 8418; ---------------------------------------------------------------------------- ; 8419 8420; i32 8421 8422; The most canonical variant 8423define void @c5_i32(i32 %arg, i32* %ptr) nounwind { 8424; X86-NOBMI-LABEL: c5_i32: 8425; X86-NOBMI: # %bb.0: 8426; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8427; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 8428; X86-NOBMI-NEXT: shrl $19, %ecx 8429; X86-NOBMI-NEXT: andl $1023, %ecx # imm = 0x3FF 8430; X86-NOBMI-NEXT: movl %ecx, (%eax) 8431; X86-NOBMI-NEXT: retl 8432; 8433; X86-BMI1NOTBM-LABEL: c5_i32: 8434; X86-BMI1NOTBM: # %bb.0: 8435; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8436; X86-BMI1NOTBM-NEXT: movl $2579, %ecx # imm = 0xA13 8437; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8438; X86-BMI1NOTBM-NEXT: movl %ecx, (%eax) 8439; X86-BMI1NOTBM-NEXT: retl 8440; 8441; X86-BMI1TBM-LABEL: c5_i32: 8442; X86-BMI1TBM: # %bb.0: 8443; X86-BMI1TBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8444; X86-BMI1TBM-NEXT: bextrl $2579, {{[0-9]+}}(%esp), %ecx # imm = 0xA13 8445; X86-BMI1TBM-NEXT: movl %ecx, (%eax) 8446; X86-BMI1TBM-NEXT: retl 8447; 8448; X86-BMI1NOTBMBMI2-LABEL: c5_i32: 8449; X86-BMI1NOTBMBMI2: # %bb.0: 8450; X86-BMI1NOTBMBMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 8451; X86-BMI1NOTBMBMI2-NEXT: movl $2579, %ecx # imm = 0xA13 8452; X86-BMI1NOTBMBMI2-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8453; X86-BMI1NOTBMBMI2-NEXT: movl %ecx, (%eax) 8454; X86-BMI1NOTBMBMI2-NEXT: retl 8455; 8456; X64-NOBMI-LABEL: c5_i32: 8457; X64-NOBMI: # %bb.0: 8458; X64-NOBMI-NEXT: shrl $19, %edi 8459; X64-NOBMI-NEXT: andl $1023, %edi # imm = 0x3FF 8460; X64-NOBMI-NEXT: movl %edi, (%rsi) 8461; X64-NOBMI-NEXT: retq 8462; 8463; X64-BMI1NOTBM-LABEL: c5_i32: 8464; X64-BMI1NOTBM: # %bb.0: 8465; X64-BMI1NOTBM-NEXT: movl $2579, %eax # imm = 0xA13 8466; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 8467; X64-BMI1NOTBM-NEXT: movl %eax, (%rsi) 8468; X64-BMI1NOTBM-NEXT: retq 8469; 8470; X64-BMI1TBM-LABEL: c5_i32: 8471; X64-BMI1TBM: # %bb.0: 8472; X64-BMI1TBM-NEXT: bextrl $2579, %edi, %eax # imm = 0xA13 8473; X64-BMI1TBM-NEXT: movl %eax, (%rsi) 8474; X64-BMI1TBM-NEXT: retq 8475; 8476; X64-BMI1NOTBMBMI2-LABEL: c5_i32: 8477; X64-BMI1NOTBMBMI2: # %bb.0: 8478; X64-BMI1NOTBMBMI2-NEXT: movl $2579, %eax # imm = 0xA13 8479; X64-BMI1NOTBMBMI2-NEXT: bextrl %eax, %edi, %eax 8480; X64-BMI1NOTBMBMI2-NEXT: movl %eax, (%rsi) 8481; X64-BMI1NOTBMBMI2-NEXT: retq 8482 %tmp0 = lshr i32 %arg, 19 8483 %tmp1 = and i32 %tmp0, 1023 8484 store i32 %tmp1, i32* %ptr 8485 ret void 8486} 8487 8488; Should be still fine, but the mask is shifted 8489define void @c6_i32(i32 %arg, i32* %ptr) nounwind { 8490; X86-NOBMI-LABEL: c6_i32: 8491; X86-NOBMI: # %bb.0: 8492; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8493; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 8494; X86-NOBMI-NEXT: shrl $19, %ecx 8495; X86-NOBMI-NEXT: andl $4095, %ecx # imm = 0xFFF 8496; X86-NOBMI-NEXT: movl %ecx, (%eax) 8497; X86-NOBMI-NEXT: retl 8498; 8499; X86-BMI1NOTBM-LABEL: c6_i32: 8500; X86-BMI1NOTBM: # %bb.0: 8501; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8502; X86-BMI1NOTBM-NEXT: movl $3091, %ecx # imm = 0xC13 8503; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8504; X86-BMI1NOTBM-NEXT: movl %ecx, (%eax) 8505; X86-BMI1NOTBM-NEXT: retl 8506; 8507; X86-BMI1TBM-LABEL: c6_i32: 8508; X86-BMI1TBM: # %bb.0: 8509; X86-BMI1TBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8510; X86-BMI1TBM-NEXT: bextrl $3091, {{[0-9]+}}(%esp), %ecx # imm = 0xC13 8511; X86-BMI1TBM-NEXT: movl %ecx, (%eax) 8512; X86-BMI1TBM-NEXT: retl 8513; 8514; X86-BMI1NOTBMBMI2-LABEL: c6_i32: 8515; X86-BMI1NOTBMBMI2: # %bb.0: 8516; X86-BMI1NOTBMBMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 8517; X86-BMI1NOTBMBMI2-NEXT: movl $3091, %ecx # imm = 0xC13 8518; X86-BMI1NOTBMBMI2-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8519; X86-BMI1NOTBMBMI2-NEXT: movl %ecx, (%eax) 8520; X86-BMI1NOTBMBMI2-NEXT: retl 8521; 8522; X64-NOBMI-LABEL: c6_i32: 8523; X64-NOBMI: # %bb.0: 8524; X64-NOBMI-NEXT: shrl $19, %edi 8525; X64-NOBMI-NEXT: andl $4095, %edi # imm = 0xFFF 8526; X64-NOBMI-NEXT: movl %edi, (%rsi) 8527; X64-NOBMI-NEXT: retq 8528; 8529; X64-BMI1NOTBM-LABEL: c6_i32: 8530; X64-BMI1NOTBM: # %bb.0: 8531; X64-BMI1NOTBM-NEXT: movl $3091, %eax # imm = 0xC13 8532; X64-BMI1NOTBM-NEXT: bextrl %eax, %edi, %eax 8533; X64-BMI1NOTBM-NEXT: movl %eax, (%rsi) 8534; X64-BMI1NOTBM-NEXT: retq 8535; 8536; X64-BMI1TBM-LABEL: c6_i32: 8537; X64-BMI1TBM: # %bb.0: 8538; X64-BMI1TBM-NEXT: bextrl $3091, %edi, %eax # imm = 0xC13 8539; X64-BMI1TBM-NEXT: movl %eax, (%rsi) 8540; X64-BMI1TBM-NEXT: retq 8541; 8542; X64-BMI1NOTBMBMI2-LABEL: c6_i32: 8543; X64-BMI1NOTBMBMI2: # %bb.0: 8544; X64-BMI1NOTBMBMI2-NEXT: movl $3091, %eax # imm = 0xC13 8545; X64-BMI1NOTBMBMI2-NEXT: bextrl %eax, %edi, %eax 8546; X64-BMI1NOTBMBMI2-NEXT: movl %eax, (%rsi) 8547; X64-BMI1NOTBMBMI2-NEXT: retq 8548 %tmp0 = lshr i32 %arg, 19 8549 %tmp1 = and i32 %tmp0, 4095 8550 store i32 %tmp1, i32* %ptr 8551 ret void 8552} 8553 8554; Should be still fine, but the result is shifted left afterwards 8555define void @c7_i32(i32 %arg, i32* %ptr) nounwind { 8556; X86-LABEL: c7_i32: 8557; X86: # %bb.0: 8558; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8559; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 8560; X86-NEXT: shrl $17, %ecx 8561; X86-NEXT: andl $4092, %ecx # imm = 0xFFC 8562; X86-NEXT: movl %ecx, (%eax) 8563; X86-NEXT: retl 8564; 8565; X64-LABEL: c7_i32: 8566; X64: # %bb.0: 8567; X64-NEXT: shrl $17, %edi 8568; X64-NEXT: andl $4092, %edi # imm = 0xFFC 8569; X64-NEXT: movl %edi, (%rsi) 8570; X64-NEXT: retq 8571 %tmp0 = lshr i32 %arg, 19 8572 %tmp1 = and i32 %tmp0, 1023 8573 %tmp2 = shl i32 %tmp1, 2 8574 store i32 %tmp2, i32* %ptr 8575 ret void 8576} 8577 8578; i64 8579 8580; The most canonical variant 8581define void @c5_i64(i64 %arg, i64* %ptr) nounwind { 8582; X86-NOBMI-LABEL: c5_i64: 8583; X86-NOBMI: # %bb.0: 8584; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8585; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 8586; X86-NOBMI-NEXT: shrl $19, %ecx 8587; X86-NOBMI-NEXT: andl $1023, %ecx # imm = 0x3FF 8588; X86-NOBMI-NEXT: movl %ecx, (%eax) 8589; X86-NOBMI-NEXT: movl $0, 4(%eax) 8590; X86-NOBMI-NEXT: retl 8591; 8592; X86-BMI1NOTBM-LABEL: c5_i64: 8593; X86-BMI1NOTBM: # %bb.0: 8594; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8595; X86-BMI1NOTBM-NEXT: movl $2579, %ecx # imm = 0xA13 8596; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8597; X86-BMI1NOTBM-NEXT: movl %ecx, (%eax) 8598; X86-BMI1NOTBM-NEXT: movl $0, 4(%eax) 8599; X86-BMI1NOTBM-NEXT: retl 8600; 8601; X86-BMI1TBM-LABEL: c5_i64: 8602; X86-BMI1TBM: # %bb.0: 8603; X86-BMI1TBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8604; X86-BMI1TBM-NEXT: bextrl $2579, {{[0-9]+}}(%esp), %ecx # imm = 0xA13 8605; X86-BMI1TBM-NEXT: movl %ecx, (%eax) 8606; X86-BMI1TBM-NEXT: movl $0, 4(%eax) 8607; X86-BMI1TBM-NEXT: retl 8608; 8609; X86-BMI1NOTBMBMI2-LABEL: c5_i64: 8610; X86-BMI1NOTBMBMI2: # %bb.0: 8611; X86-BMI1NOTBMBMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 8612; X86-BMI1NOTBMBMI2-NEXT: movl $2579, %ecx # imm = 0xA13 8613; X86-BMI1NOTBMBMI2-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8614; X86-BMI1NOTBMBMI2-NEXT: movl %ecx, (%eax) 8615; X86-BMI1NOTBMBMI2-NEXT: movl $0, 4(%eax) 8616; X86-BMI1NOTBMBMI2-NEXT: retl 8617; 8618; X64-NOBMI-LABEL: c5_i64: 8619; X64-NOBMI: # %bb.0: 8620; X64-NOBMI-NEXT: shrq $51, %rdi 8621; X64-NOBMI-NEXT: andl $1023, %edi # imm = 0x3FF 8622; X64-NOBMI-NEXT: movq %rdi, (%rsi) 8623; X64-NOBMI-NEXT: retq 8624; 8625; X64-BMI1NOTBM-LABEL: c5_i64: 8626; X64-BMI1NOTBM: # %bb.0: 8627; X64-BMI1NOTBM-NEXT: movl $2611, %eax # imm = 0xA33 8628; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 8629; X64-BMI1NOTBM-NEXT: movq %rax, (%rsi) 8630; X64-BMI1NOTBM-NEXT: retq 8631; 8632; X64-BMI1TBM-LABEL: c5_i64: 8633; X64-BMI1TBM: # %bb.0: 8634; X64-BMI1TBM-NEXT: bextrq $2611, %rdi, %rax # imm = 0xA33 8635; X64-BMI1TBM-NEXT: movq %rax, (%rsi) 8636; X64-BMI1TBM-NEXT: retq 8637; 8638; X64-BMI1NOTBMBMI2-LABEL: c5_i64: 8639; X64-BMI1NOTBMBMI2: # %bb.0: 8640; X64-BMI1NOTBMBMI2-NEXT: movl $2611, %eax # imm = 0xA33 8641; X64-BMI1NOTBMBMI2-NEXT: bextrq %rax, %rdi, %rax 8642; X64-BMI1NOTBMBMI2-NEXT: movq %rax, (%rsi) 8643; X64-BMI1NOTBMBMI2-NEXT: retq 8644 %tmp0 = lshr i64 %arg, 51 8645 %tmp1 = and i64 %tmp0, 1023 8646 store i64 %tmp1, i64* %ptr 8647 ret void 8648} 8649 8650; Should be still fine, but the mask is shifted 8651define void @c6_i64(i64 %arg, i64* %ptr) nounwind { 8652; X86-NOBMI-LABEL: c6_i64: 8653; X86-NOBMI: # %bb.0: 8654; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax 8655; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx 8656; X86-NOBMI-NEXT: shrl $19, %ecx 8657; X86-NOBMI-NEXT: andl $4095, %ecx # imm = 0xFFF 8658; X86-NOBMI-NEXT: movl %ecx, (%eax) 8659; X86-NOBMI-NEXT: movl $0, 4(%eax) 8660; X86-NOBMI-NEXT: retl 8661; 8662; X86-BMI1NOTBM-LABEL: c6_i64: 8663; X86-BMI1NOTBM: # %bb.0: 8664; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8665; X86-BMI1NOTBM-NEXT: movl $3091, %ecx # imm = 0xC13 8666; X86-BMI1NOTBM-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8667; X86-BMI1NOTBM-NEXT: movl %ecx, (%eax) 8668; X86-BMI1NOTBM-NEXT: movl $0, 4(%eax) 8669; X86-BMI1NOTBM-NEXT: retl 8670; 8671; X86-BMI1TBM-LABEL: c6_i64: 8672; X86-BMI1TBM: # %bb.0: 8673; X86-BMI1TBM-NEXT: movl {{[0-9]+}}(%esp), %eax 8674; X86-BMI1TBM-NEXT: bextrl $3091, {{[0-9]+}}(%esp), %ecx # imm = 0xC13 8675; X86-BMI1TBM-NEXT: movl %ecx, (%eax) 8676; X86-BMI1TBM-NEXT: movl $0, 4(%eax) 8677; X86-BMI1TBM-NEXT: retl 8678; 8679; X86-BMI1NOTBMBMI2-LABEL: c6_i64: 8680; X86-BMI1NOTBMBMI2: # %bb.0: 8681; X86-BMI1NOTBMBMI2-NEXT: movl {{[0-9]+}}(%esp), %eax 8682; X86-BMI1NOTBMBMI2-NEXT: movl $3091, %ecx # imm = 0xC13 8683; X86-BMI1NOTBMBMI2-NEXT: bextrl %ecx, {{[0-9]+}}(%esp), %ecx 8684; X86-BMI1NOTBMBMI2-NEXT: movl %ecx, (%eax) 8685; X86-BMI1NOTBMBMI2-NEXT: movl $0, 4(%eax) 8686; X86-BMI1NOTBMBMI2-NEXT: retl 8687; 8688; X64-NOBMI-LABEL: c6_i64: 8689; X64-NOBMI: # %bb.0: 8690; X64-NOBMI-NEXT: shrq $51, %rdi 8691; X64-NOBMI-NEXT: andl $4095, %edi # imm = 0xFFF 8692; X64-NOBMI-NEXT: movq %rdi, (%rsi) 8693; X64-NOBMI-NEXT: retq 8694; 8695; X64-BMI1NOTBM-LABEL: c6_i64: 8696; X64-BMI1NOTBM: # %bb.0: 8697; X64-BMI1NOTBM-NEXT: movl $3123, %eax # imm = 0xC33 8698; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax 8699; X64-BMI1NOTBM-NEXT: movq %rax, (%rsi) 8700; X64-BMI1NOTBM-NEXT: retq 8701; 8702; X64-BMI1TBM-LABEL: c6_i64: 8703; X64-BMI1TBM: # %bb.0: 8704; X64-BMI1TBM-NEXT: bextrq $3123, %rdi, %rax # imm = 0xC33 8705; X64-BMI1TBM-NEXT: movq %rax, (%rsi) 8706; X64-BMI1TBM-NEXT: retq 8707; 8708; X64-BMI1NOTBMBMI2-LABEL: c6_i64: 8709; X64-BMI1NOTBMBMI2: # %bb.0: 8710; X64-BMI1NOTBMBMI2-NEXT: movl $3123, %eax # imm = 0xC33 8711; X64-BMI1NOTBMBMI2-NEXT: bextrq %rax, %rdi, %rax 8712; X64-BMI1NOTBMBMI2-NEXT: movq %rax, (%rsi) 8713; X64-BMI1NOTBMBMI2-NEXT: retq 8714 %tmp0 = lshr i64 %arg, 51 8715 %tmp1 = and i64 %tmp0, 4095 8716 store i64 %tmp1, i64* %ptr 8717 ret void 8718} 8719 8720; Should be still fine, but the result is shifted left afterwards 8721define void @c7_i64(i64 %arg, i64* %ptr) nounwind { 8722; X86-LABEL: c7_i64: 8723; X86: # %bb.0: 8724; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 8725; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 8726; X86-NEXT: shrl $17, %ecx 8727; X86-NEXT: andl $4092, %ecx # imm = 0xFFC 8728; X86-NEXT: movl %ecx, (%eax) 8729; X86-NEXT: movl $0, 4(%eax) 8730; X86-NEXT: retl 8731; 8732; X64-LABEL: c7_i64: 8733; X64: # %bb.0: 8734; X64-NEXT: shrq $49, %rdi 8735; X64-NEXT: andl $4092, %edi # imm = 0xFFC 8736; X64-NEXT: movq %rdi, (%rsi) 8737; X64-NEXT: retq 8738 %tmp0 = lshr i64 %arg, 51 8739 %tmp1 = and i64 %tmp0, 1023 8740 %tmp2 = shl i64 %tmp1, 2 8741 store i64 %tmp2, i64* %ptr 8742 ret void 8743} 8744