brintos

brintos / llvm-project-archived public Read only

0
0
Text · 149.9 KiB · 077e777 Raw
4615 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=X86,X86-NOBMI3; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=X86,X86-BMI14; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=X86,X86-BMI15; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=X86,X86-BMI26; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=X86,X86-BMI27; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=X64,X64-NOBMI8; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=X64,X64-BMI1,X64-BMI1NOTBM9; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=X64,X64-BMI1,X64-BMI1TBM10; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=X64,X64-BMI2,X64-BMI2TBM11; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=X64,X64-BMI2,X64-BMI2NOTBM12 13; *Please* keep in sync with test/CodeGen/AArch64/extract-lowbits.ll14 15; https://bugs.llvm.org/show_bug.cgi?id=3641916; https://bugs.llvm.org/show_bug.cgi?id=3760317; https://bugs.llvm.org/show_bug.cgi?id=3761018 19; Patterns:20;   a) x &  (1 << nbits) - 121;   b) x & ~(-1 << nbits)22;   c) x &  (-1 >> (32 - y))23;   d) x << (32 - y) >> (32 - y)24; are equivalent.25 26; ---------------------------------------------------------------------------- ;27; Pattern a. 32-bit28; ---------------------------------------------------------------------------- ;29 30define i32 @bzhi32_a0(i32 %val, i32 %numlowbits) nounwind {31; X86-NOBMI-LABEL: bzhi32_a0:32; X86-NOBMI:       # %bb.0:33; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx34; X86-NOBMI-NEXT:    movl $1, %eax35; X86-NOBMI-NEXT:    shll %cl, %eax36; X86-NOBMI-NEXT:    decl %eax37; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax38; X86-NOBMI-NEXT:    retl39;40; X86-BMI1-LABEL: bzhi32_a0:41; X86-BMI1:       # %bb.0:42; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax43; X86-BMI1-NEXT:    shll $8, %eax44; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax45; X86-BMI1-NEXT:    retl46;47; X86-BMI2-LABEL: bzhi32_a0:48; X86-BMI2:       # %bb.0:49; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax50; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax51; X86-BMI2-NEXT:    retl52;53; X64-NOBMI-LABEL: bzhi32_a0:54; X64-NOBMI:       # %bb.0:55; X64-NOBMI-NEXT:    movl %esi, %ecx56; X64-NOBMI-NEXT:    movl $1, %eax57; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx58; X64-NOBMI-NEXT:    shll %cl, %eax59; X64-NOBMI-NEXT:    decl %eax60; X64-NOBMI-NEXT:    andl %edi, %eax61; X64-NOBMI-NEXT:    retq62;63; X64-BMI1-LABEL: bzhi32_a0:64; X64-BMI1:       # %bb.0:65; X64-BMI1-NEXT:    shll $8, %esi66; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax67; X64-BMI1-NEXT:    retq68;69; X64-BMI2-LABEL: bzhi32_a0:70; X64-BMI2:       # %bb.0:71; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax72; X64-BMI2-NEXT:    retq73  %onebit = shl i32 1, %numlowbits74  %mask = add nsw i32 %onebit, -175  %masked = and i32 %mask, %val76  ret i32 %masked77}78 79define i32 @bzhi32_a1_indexzext(i32 %val, i8 zeroext %numlowbits) nounwind {80; X86-NOBMI-LABEL: bzhi32_a1_indexzext:81; X86-NOBMI:       # %bb.0:82; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx83; X86-NOBMI-NEXT:    movl $1, %eax84; X86-NOBMI-NEXT:    shll %cl, %eax85; X86-NOBMI-NEXT:    decl %eax86; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax87; X86-NOBMI-NEXT:    retl88;89; X86-BMI1-LABEL: bzhi32_a1_indexzext:90; X86-BMI1:       # %bb.0:91; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax92; X86-BMI1-NEXT:    shll $8, %eax93; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax94; X86-BMI1-NEXT:    retl95;96; X86-BMI2-LABEL: bzhi32_a1_indexzext:97; X86-BMI2:       # %bb.0:98; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax99; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax100; X86-BMI2-NEXT:    retl101;102; X64-NOBMI-LABEL: bzhi32_a1_indexzext:103; X64-NOBMI:       # %bb.0:104; X64-NOBMI-NEXT:    movl %esi, %ecx105; X64-NOBMI-NEXT:    movl $1, %eax106; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx107; X64-NOBMI-NEXT:    shll %cl, %eax108; X64-NOBMI-NEXT:    decl %eax109; X64-NOBMI-NEXT:    andl %edi, %eax110; X64-NOBMI-NEXT:    retq111;112; X64-BMI1-LABEL: bzhi32_a1_indexzext:113; X64-BMI1:       # %bb.0:114; X64-BMI1-NEXT:    shll $8, %esi115; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax116; X64-BMI1-NEXT:    retq117;118; X64-BMI2-LABEL: bzhi32_a1_indexzext:119; X64-BMI2:       # %bb.0:120; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax121; X64-BMI2-NEXT:    retq122  %conv = zext i8 %numlowbits to i32123  %onebit = shl i32 1, %conv124  %mask = add nsw i32 %onebit, -1125  %masked = and i32 %mask, %val126  ret i32 %masked127}128 129define i32 @bzhi32_a2_load(ptr %w, i32 %numlowbits) nounwind {130; X86-NOBMI-LABEL: bzhi32_a2_load:131; X86-NOBMI:       # %bb.0:132; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx133; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx134; X86-NOBMI-NEXT:    movl $1, %eax135; X86-NOBMI-NEXT:    shll %cl, %eax136; X86-NOBMI-NEXT:    decl %eax137; X86-NOBMI-NEXT:    andl (%edx), %eax138; X86-NOBMI-NEXT:    retl139;140; X86-BMI1-LABEL: bzhi32_a2_load:141; X86-BMI1:       # %bb.0:142; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax143; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx144; X86-BMI1-NEXT:    shll $8, %ecx145; X86-BMI1-NEXT:    bextrl %ecx, (%eax), %eax146; X86-BMI1-NEXT:    retl147;148; X86-BMI2-LABEL: bzhi32_a2_load:149; X86-BMI2:       # %bb.0:150; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax151; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx152; X86-BMI2-NEXT:    bzhil %ecx, (%eax), %eax153; X86-BMI2-NEXT:    retl154;155; X64-NOBMI-LABEL: bzhi32_a2_load:156; X64-NOBMI:       # %bb.0:157; X64-NOBMI-NEXT:    movl %esi, %ecx158; X64-NOBMI-NEXT:    movl $1, %eax159; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx160; X64-NOBMI-NEXT:    shll %cl, %eax161; X64-NOBMI-NEXT:    decl %eax162; X64-NOBMI-NEXT:    andl (%rdi), %eax163; X64-NOBMI-NEXT:    retq164;165; X64-BMI1-LABEL: bzhi32_a2_load:166; X64-BMI1:       # %bb.0:167; X64-BMI1-NEXT:    shll $8, %esi168; X64-BMI1-NEXT:    bextrl %esi, (%rdi), %eax169; X64-BMI1-NEXT:    retq170;171; X64-BMI2-LABEL: bzhi32_a2_load:172; X64-BMI2:       # %bb.0:173; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax174; X64-BMI2-NEXT:    retq175  %val = load i32, ptr %w176  %onebit = shl i32 1, %numlowbits177  %mask = add nsw i32 %onebit, -1178  %masked = and i32 %mask, %val179  ret i32 %masked180}181 182define i32 @bzhi32_a3_load_indexzext(ptr %w, i8 zeroext %numlowbits) nounwind {183; X86-NOBMI-LABEL: bzhi32_a3_load_indexzext:184; X86-NOBMI:       # %bb.0:185; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx186; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx187; X86-NOBMI-NEXT:    movl $1, %eax188; X86-NOBMI-NEXT:    shll %cl, %eax189; X86-NOBMI-NEXT:    decl %eax190; X86-NOBMI-NEXT:    andl (%edx), %eax191; X86-NOBMI-NEXT:    retl192;193; X86-BMI1-LABEL: bzhi32_a3_load_indexzext:194; X86-BMI1:       # %bb.0:195; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax196; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx197; X86-BMI1-NEXT:    shll $8, %ecx198; X86-BMI1-NEXT:    bextrl %ecx, (%eax), %eax199; X86-BMI1-NEXT:    retl200;201; X86-BMI2-LABEL: bzhi32_a3_load_indexzext:202; X86-BMI2:       # %bb.0:203; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax204; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx205; X86-BMI2-NEXT:    bzhil %ecx, (%eax), %eax206; X86-BMI2-NEXT:    retl207;208; X64-NOBMI-LABEL: bzhi32_a3_load_indexzext:209; X64-NOBMI:       # %bb.0:210; X64-NOBMI-NEXT:    movl %esi, %ecx211; X64-NOBMI-NEXT:    movl $1, %eax212; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx213; X64-NOBMI-NEXT:    shll %cl, %eax214; X64-NOBMI-NEXT:    decl %eax215; X64-NOBMI-NEXT:    andl (%rdi), %eax216; X64-NOBMI-NEXT:    retq217;218; X64-BMI1-LABEL: bzhi32_a3_load_indexzext:219; X64-BMI1:       # %bb.0:220; X64-BMI1-NEXT:    shll $8, %esi221; X64-BMI1-NEXT:    bextrl %esi, (%rdi), %eax222; X64-BMI1-NEXT:    retq223;224; X64-BMI2-LABEL: bzhi32_a3_load_indexzext:225; X64-BMI2:       # %bb.0:226; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax227; X64-BMI2-NEXT:    retq228  %val = load i32, ptr %w229  %conv = zext i8 %numlowbits to i32230  %onebit = shl i32 1, %conv231  %mask = add nsw i32 %onebit, -1232  %masked = and i32 %mask, %val233  ret i32 %masked234}235 236define i32 @bzhi32_a4_commutative(i32 %val, i32 %numlowbits) nounwind {237; X86-NOBMI-LABEL: bzhi32_a4_commutative:238; X86-NOBMI:       # %bb.0:239; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx240; X86-NOBMI-NEXT:    movl $1, %eax241; X86-NOBMI-NEXT:    shll %cl, %eax242; X86-NOBMI-NEXT:    decl %eax243; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax244; X86-NOBMI-NEXT:    retl245;246; X86-BMI1-LABEL: bzhi32_a4_commutative:247; X86-BMI1:       # %bb.0:248; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax249; X86-BMI1-NEXT:    shll $8, %eax250; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax251; X86-BMI1-NEXT:    retl252;253; X86-BMI2-LABEL: bzhi32_a4_commutative:254; X86-BMI2:       # %bb.0:255; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax256; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax257; X86-BMI2-NEXT:    retl258;259; X64-NOBMI-LABEL: bzhi32_a4_commutative:260; X64-NOBMI:       # %bb.0:261; X64-NOBMI-NEXT:    movl %esi, %ecx262; X64-NOBMI-NEXT:    movl $1, %eax263; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx264; X64-NOBMI-NEXT:    shll %cl, %eax265; X64-NOBMI-NEXT:    decl %eax266; X64-NOBMI-NEXT:    andl %edi, %eax267; X64-NOBMI-NEXT:    retq268;269; X64-BMI1-LABEL: bzhi32_a4_commutative:270; X64-BMI1:       # %bb.0:271; X64-BMI1-NEXT:    shll $8, %esi272; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax273; X64-BMI1-NEXT:    retq274;275; X64-BMI2-LABEL: bzhi32_a4_commutative:276; X64-BMI2:       # %bb.0:277; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax278; X64-BMI2-NEXT:    retq279  %onebit = shl i32 1, %numlowbits280  %mask = add nsw i32 %onebit, -1281  %masked = and i32 %val, %mask ; swapped order282  ret i32 %masked283}284 285; 64-bit286 287define i64 @bzhi64_a0(i64 %val, i64 %numlowbits) nounwind {288; X86-NOBMI-LABEL: bzhi64_a0:289; X86-NOBMI:       # %bb.0:290; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx291; X86-NOBMI-NEXT:    movl $1, %eax292; X86-NOBMI-NEXT:    xorl %edx, %edx293; X86-NOBMI-NEXT:    shldl %cl, %eax, %edx294; X86-NOBMI-NEXT:    shll %cl, %eax295; X86-NOBMI-NEXT:    testb $32, %cl296; X86-NOBMI-NEXT:    je .LBB5_2297; X86-NOBMI-NEXT:  # %bb.1:298; X86-NOBMI-NEXT:    movl %eax, %edx299; X86-NOBMI-NEXT:    xorl %eax, %eax300; X86-NOBMI-NEXT:  .LBB5_2:301; X86-NOBMI-NEXT:    addl $-1, %eax302; X86-NOBMI-NEXT:    adcl $-1, %edx303; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx304; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax305; X86-NOBMI-NEXT:    retl306;307; X86-BMI1-LABEL: bzhi64_a0:308; X86-BMI1:       # %bb.0:309; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx310; X86-BMI1-NEXT:    movl $1, %eax311; X86-BMI1-NEXT:    xorl %edx, %edx312; X86-BMI1-NEXT:    shldl %cl, %eax, %edx313; X86-BMI1-NEXT:    shll %cl, %eax314; X86-BMI1-NEXT:    testb $32, %cl315; X86-BMI1-NEXT:    je .LBB5_2316; X86-BMI1-NEXT:  # %bb.1:317; X86-BMI1-NEXT:    movl %eax, %edx318; X86-BMI1-NEXT:    xorl %eax, %eax319; X86-BMI1-NEXT:  .LBB5_2:320; X86-BMI1-NEXT:    addl $-1, %eax321; X86-BMI1-NEXT:    adcl $-1, %edx322; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx323; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax324; X86-BMI1-NEXT:    retl325;326; X86-BMI2-LABEL: bzhi64_a0:327; X86-BMI2:       # %bb.0:328; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx329; X86-BMI2-NEXT:    movl $1, %eax330; X86-BMI2-NEXT:    xorl %edx, %edx331; X86-BMI2-NEXT:    shldl %cl, %eax, %edx332; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax333; X86-BMI2-NEXT:    testb $32, %cl334; X86-BMI2-NEXT:    je .LBB5_2335; X86-BMI2-NEXT:  # %bb.1:336; X86-BMI2-NEXT:    movl %eax, %edx337; X86-BMI2-NEXT:    xorl %eax, %eax338; X86-BMI2-NEXT:  .LBB5_2:339; X86-BMI2-NEXT:    addl $-1, %eax340; X86-BMI2-NEXT:    adcl $-1, %edx341; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx342; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax343; X86-BMI2-NEXT:    retl344;345; X64-NOBMI-LABEL: bzhi64_a0:346; X64-NOBMI:       # %bb.0:347; X64-NOBMI-NEXT:    movq %rsi, %rcx348; X64-NOBMI-NEXT:    movl $1, %eax349; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx350; X64-NOBMI-NEXT:    shlq %cl, %rax351; X64-NOBMI-NEXT:    decq %rax352; X64-NOBMI-NEXT:    andq %rdi, %rax353; X64-NOBMI-NEXT:    retq354;355; X64-BMI1-LABEL: bzhi64_a0:356; X64-BMI1:       # %bb.0:357; X64-BMI1-NEXT:    shll $8, %esi358; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax359; X64-BMI1-NEXT:    retq360;361; X64-BMI2-LABEL: bzhi64_a0:362; X64-BMI2:       # %bb.0:363; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax364; X64-BMI2-NEXT:    retq365  %onebit = shl i64 1, %numlowbits366  %mask = add nsw i64 %onebit, -1367  %masked = and i64 %mask, %val368  ret i64 %masked369}370 371; Check that we don't throw away the vreg_width-1 mask if not using shifts372define i64 @bzhi64_a0_masked(i64 %val, i64 %numlowbits) nounwind {373; X86-NOBMI-LABEL: bzhi64_a0_masked:374; X86-NOBMI:       # %bb.0:375; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx376; X86-NOBMI-NEXT:    movl $1, %eax377; X86-NOBMI-NEXT:    xorl %edx, %edx378; X86-NOBMI-NEXT:    shldl %cl, %eax, %edx379; X86-NOBMI-NEXT:    shll %cl, %eax380; X86-NOBMI-NEXT:    testb $32, %cl381; X86-NOBMI-NEXT:    je .LBB6_2382; X86-NOBMI-NEXT:  # %bb.1:383; X86-NOBMI-NEXT:    movl %eax, %edx384; X86-NOBMI-NEXT:    xorl %eax, %eax385; X86-NOBMI-NEXT:  .LBB6_2:386; X86-NOBMI-NEXT:    addl $-1, %eax387; X86-NOBMI-NEXT:    adcl $-1, %edx388; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx389; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax390; X86-NOBMI-NEXT:    retl391;392; X86-BMI1-LABEL: bzhi64_a0_masked:393; X86-BMI1:       # %bb.0:394; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx395; X86-BMI1-NEXT:    movl $1, %eax396; X86-BMI1-NEXT:    xorl %edx, %edx397; X86-BMI1-NEXT:    shldl %cl, %eax, %edx398; X86-BMI1-NEXT:    shll %cl, %eax399; X86-BMI1-NEXT:    testb $32, %cl400; X86-BMI1-NEXT:    je .LBB6_2401; X86-BMI1-NEXT:  # %bb.1:402; X86-BMI1-NEXT:    movl %eax, %edx403; X86-BMI1-NEXT:    xorl %eax, %eax404; X86-BMI1-NEXT:  .LBB6_2:405; X86-BMI1-NEXT:    addl $-1, %eax406; X86-BMI1-NEXT:    adcl $-1, %edx407; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx408; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax409; X86-BMI1-NEXT:    retl410;411; X86-BMI2-LABEL: bzhi64_a0_masked:412; X86-BMI2:       # %bb.0:413; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx414; X86-BMI2-NEXT:    movl $1, %eax415; X86-BMI2-NEXT:    xorl %edx, %edx416; X86-BMI2-NEXT:    shldl %cl, %eax, %edx417; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax418; X86-BMI2-NEXT:    testb $32, %cl419; X86-BMI2-NEXT:    je .LBB6_2420; X86-BMI2-NEXT:  # %bb.1:421; X86-BMI2-NEXT:    movl %eax, %edx422; X86-BMI2-NEXT:    xorl %eax, %eax423; X86-BMI2-NEXT:  .LBB6_2:424; X86-BMI2-NEXT:    addl $-1, %eax425; X86-BMI2-NEXT:    adcl $-1, %edx426; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx427; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax428; X86-BMI2-NEXT:    retl429;430; X64-NOBMI-LABEL: bzhi64_a0_masked:431; X64-NOBMI:       # %bb.0:432; X64-NOBMI-NEXT:    movq %rsi, %rcx433; X64-NOBMI-NEXT:    movl $1, %eax434; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx435; X64-NOBMI-NEXT:    shlq %cl, %rax436; X64-NOBMI-NEXT:    decq %rax437; X64-NOBMI-NEXT:    andq %rdi, %rax438; X64-NOBMI-NEXT:    retq439;440; X64-BMI1-LABEL: bzhi64_a0_masked:441; X64-BMI1:       # %bb.0:442; X64-BMI1-NEXT:    andb $63, %sil443; X64-BMI1-NEXT:    shll $8, %esi444; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax445; X64-BMI1-NEXT:    retq446;447; X64-BMI2-LABEL: bzhi64_a0_masked:448; X64-BMI2:       # %bb.0:449; X64-BMI2-NEXT:    andb $63, %sil450; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax451; X64-BMI2-NEXT:    retq452  %numlowbits.masked = and i64 %numlowbits, 63453  %onebit = shl i64 1, %numlowbits.masked454  %mask = add nsw i64 %onebit, -1455  %masked = and i64 %mask, %val456  ret i64 %masked457}458 459define i64 @bzhi64_a1_indexzext(i64 %val, i8 zeroext %numlowbits) nounwind {460; X86-NOBMI-LABEL: bzhi64_a1_indexzext:461; X86-NOBMI:       # %bb.0:462; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx463; X86-NOBMI-NEXT:    movl $1, %eax464; X86-NOBMI-NEXT:    xorl %edx, %edx465; X86-NOBMI-NEXT:    shldl %cl, %eax, %edx466; X86-NOBMI-NEXT:    shll %cl, %eax467; X86-NOBMI-NEXT:    testb $32, %cl468; X86-NOBMI-NEXT:    je .LBB7_2469; X86-NOBMI-NEXT:  # %bb.1:470; X86-NOBMI-NEXT:    movl %eax, %edx471; X86-NOBMI-NEXT:    xorl %eax, %eax472; X86-NOBMI-NEXT:  .LBB7_2:473; X86-NOBMI-NEXT:    addl $-1, %eax474; X86-NOBMI-NEXT:    adcl $-1, %edx475; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx476; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax477; X86-NOBMI-NEXT:    retl478;479; X86-BMI1-LABEL: bzhi64_a1_indexzext:480; X86-BMI1:       # %bb.0:481; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx482; X86-BMI1-NEXT:    movl $1, %eax483; X86-BMI1-NEXT:    xorl %edx, %edx484; X86-BMI1-NEXT:    shldl %cl, %eax, %edx485; X86-BMI1-NEXT:    shll %cl, %eax486; X86-BMI1-NEXT:    testb $32, %cl487; X86-BMI1-NEXT:    je .LBB7_2488; X86-BMI1-NEXT:  # %bb.1:489; X86-BMI1-NEXT:    movl %eax, %edx490; X86-BMI1-NEXT:    xorl %eax, %eax491; X86-BMI1-NEXT:  .LBB7_2:492; X86-BMI1-NEXT:    addl $-1, %eax493; X86-BMI1-NEXT:    adcl $-1, %edx494; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx495; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax496; X86-BMI1-NEXT:    retl497;498; X86-BMI2-LABEL: bzhi64_a1_indexzext:499; X86-BMI2:       # %bb.0:500; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx501; X86-BMI2-NEXT:    movl $1, %eax502; X86-BMI2-NEXT:    xorl %edx, %edx503; X86-BMI2-NEXT:    shldl %cl, %eax, %edx504; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax505; X86-BMI2-NEXT:    testb $32, %cl506; X86-BMI2-NEXT:    je .LBB7_2507; X86-BMI2-NEXT:  # %bb.1:508; X86-BMI2-NEXT:    movl %eax, %edx509; X86-BMI2-NEXT:    xorl %eax, %eax510; X86-BMI2-NEXT:  .LBB7_2:511; X86-BMI2-NEXT:    addl $-1, %eax512; X86-BMI2-NEXT:    adcl $-1, %edx513; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx514; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax515; X86-BMI2-NEXT:    retl516;517; X64-NOBMI-LABEL: bzhi64_a1_indexzext:518; X64-NOBMI:       # %bb.0:519; X64-NOBMI-NEXT:    movl %esi, %ecx520; X64-NOBMI-NEXT:    movl $1, %eax521; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx522; X64-NOBMI-NEXT:    shlq %cl, %rax523; X64-NOBMI-NEXT:    decq %rax524; X64-NOBMI-NEXT:    andq %rdi, %rax525; X64-NOBMI-NEXT:    retq526;527; X64-BMI1-LABEL: bzhi64_a1_indexzext:528; X64-BMI1:       # %bb.0:529; X64-BMI1-NEXT:    # kill: def $esi killed $esi def $rsi530; X64-BMI1-NEXT:    shll $8, %esi531; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax532; X64-BMI1-NEXT:    retq533;534; X64-BMI2-LABEL: bzhi64_a1_indexzext:535; X64-BMI2:       # %bb.0:536; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi537; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax538; X64-BMI2-NEXT:    retq539  %conv = zext i8 %numlowbits to i64540  %onebit = shl i64 1, %conv541  %mask = add nsw i64 %onebit, -1542  %masked = and i64 %mask, %val543  ret i64 %masked544}545 546define i64 @bzhi64_a2_load(ptr %w, i64 %numlowbits) nounwind {547; X86-NOBMI-LABEL: bzhi64_a2_load:548; X86-NOBMI:       # %bb.0:549; X86-NOBMI-NEXT:    pushl %esi550; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi551; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx552; X86-NOBMI-NEXT:    movl $1, %eax553; X86-NOBMI-NEXT:    xorl %edx, %edx554; X86-NOBMI-NEXT:    shldl %cl, %eax, %edx555; X86-NOBMI-NEXT:    shll %cl, %eax556; X86-NOBMI-NEXT:    testb $32, %cl557; X86-NOBMI-NEXT:    je .LBB8_2558; X86-NOBMI-NEXT:  # %bb.1:559; X86-NOBMI-NEXT:    movl %eax, %edx560; X86-NOBMI-NEXT:    xorl %eax, %eax561; X86-NOBMI-NEXT:  .LBB8_2:562; X86-NOBMI-NEXT:    addl $-1, %eax563; X86-NOBMI-NEXT:    adcl $-1, %edx564; X86-NOBMI-NEXT:    andl 4(%esi), %edx565; X86-NOBMI-NEXT:    andl (%esi), %eax566; X86-NOBMI-NEXT:    popl %esi567; X86-NOBMI-NEXT:    retl568;569; X86-BMI1-LABEL: bzhi64_a2_load:570; X86-BMI1:       # %bb.0:571; X86-BMI1-NEXT:    pushl %esi572; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi573; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx574; X86-BMI1-NEXT:    movl $1, %eax575; X86-BMI1-NEXT:    xorl %edx, %edx576; X86-BMI1-NEXT:    shldl %cl, %eax, %edx577; X86-BMI1-NEXT:    shll %cl, %eax578; X86-BMI1-NEXT:    testb $32, %cl579; X86-BMI1-NEXT:    je .LBB8_2580; X86-BMI1-NEXT:  # %bb.1:581; X86-BMI1-NEXT:    movl %eax, %edx582; X86-BMI1-NEXT:    xorl %eax, %eax583; X86-BMI1-NEXT:  .LBB8_2:584; X86-BMI1-NEXT:    addl $-1, %eax585; X86-BMI1-NEXT:    adcl $-1, %edx586; X86-BMI1-NEXT:    andl 4(%esi), %edx587; X86-BMI1-NEXT:    andl (%esi), %eax588; X86-BMI1-NEXT:    popl %esi589; X86-BMI1-NEXT:    retl590;591; X86-BMI2-LABEL: bzhi64_a2_load:592; X86-BMI2:       # %bb.0:593; X86-BMI2-NEXT:    pushl %esi594; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %esi595; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx596; X86-BMI2-NEXT:    movl $1, %eax597; X86-BMI2-NEXT:    xorl %edx, %edx598; X86-BMI2-NEXT:    shldl %cl, %eax, %edx599; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax600; X86-BMI2-NEXT:    testb $32, %cl601; X86-BMI2-NEXT:    je .LBB8_2602; X86-BMI2-NEXT:  # %bb.1:603; X86-BMI2-NEXT:    movl %eax, %edx604; X86-BMI2-NEXT:    xorl %eax, %eax605; X86-BMI2-NEXT:  .LBB8_2:606; X86-BMI2-NEXT:    addl $-1, %eax607; X86-BMI2-NEXT:    adcl $-1, %edx608; X86-BMI2-NEXT:    andl 4(%esi), %edx609; X86-BMI2-NEXT:    andl (%esi), %eax610; X86-BMI2-NEXT:    popl %esi611; X86-BMI2-NEXT:    retl612;613; X64-NOBMI-LABEL: bzhi64_a2_load:614; X64-NOBMI:       # %bb.0:615; X64-NOBMI-NEXT:    movq %rsi, %rcx616; X64-NOBMI-NEXT:    movl $1, %eax617; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx618; X64-NOBMI-NEXT:    shlq %cl, %rax619; X64-NOBMI-NEXT:    decq %rax620; X64-NOBMI-NEXT:    andq (%rdi), %rax621; X64-NOBMI-NEXT:    retq622;623; X64-BMI1-LABEL: bzhi64_a2_load:624; X64-BMI1:       # %bb.0:625; X64-BMI1-NEXT:    shll $8, %esi626; X64-BMI1-NEXT:    bextrq %rsi, (%rdi), %rax627; X64-BMI1-NEXT:    retq628;629; X64-BMI2-LABEL: bzhi64_a2_load:630; X64-BMI2:       # %bb.0:631; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax632; X64-BMI2-NEXT:    retq633  %val = load i64, ptr %w634  %onebit = shl i64 1, %numlowbits635  %mask = add nsw i64 %onebit, -1636  %masked = and i64 %mask, %val637  ret i64 %masked638}639 640define i64 @bzhi64_a3_load_indexzext(ptr %w, i8 zeroext %numlowbits) nounwind {641; X86-NOBMI-LABEL: bzhi64_a3_load_indexzext:642; X86-NOBMI:       # %bb.0:643; X86-NOBMI-NEXT:    pushl %esi644; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi645; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx646; X86-NOBMI-NEXT:    movl $1, %eax647; X86-NOBMI-NEXT:    xorl %edx, %edx648; X86-NOBMI-NEXT:    shldl %cl, %eax, %edx649; X86-NOBMI-NEXT:    shll %cl, %eax650; X86-NOBMI-NEXT:    testb $32, %cl651; X86-NOBMI-NEXT:    je .LBB9_2652; X86-NOBMI-NEXT:  # %bb.1:653; X86-NOBMI-NEXT:    movl %eax, %edx654; X86-NOBMI-NEXT:    xorl %eax, %eax655; X86-NOBMI-NEXT:  .LBB9_2:656; X86-NOBMI-NEXT:    addl $-1, %eax657; X86-NOBMI-NEXT:    adcl $-1, %edx658; X86-NOBMI-NEXT:    andl 4(%esi), %edx659; X86-NOBMI-NEXT:    andl (%esi), %eax660; X86-NOBMI-NEXT:    popl %esi661; X86-NOBMI-NEXT:    retl662;663; X86-BMI1-LABEL: bzhi64_a3_load_indexzext:664; X86-BMI1:       # %bb.0:665; X86-BMI1-NEXT:    pushl %esi666; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi667; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx668; X86-BMI1-NEXT:    movl $1, %eax669; X86-BMI1-NEXT:    xorl %edx, %edx670; X86-BMI1-NEXT:    shldl %cl, %eax, %edx671; X86-BMI1-NEXT:    shll %cl, %eax672; X86-BMI1-NEXT:    testb $32, %cl673; X86-BMI1-NEXT:    je .LBB9_2674; X86-BMI1-NEXT:  # %bb.1:675; X86-BMI1-NEXT:    movl %eax, %edx676; X86-BMI1-NEXT:    xorl %eax, %eax677; X86-BMI1-NEXT:  .LBB9_2:678; X86-BMI1-NEXT:    addl $-1, %eax679; X86-BMI1-NEXT:    adcl $-1, %edx680; X86-BMI1-NEXT:    andl 4(%esi), %edx681; X86-BMI1-NEXT:    andl (%esi), %eax682; X86-BMI1-NEXT:    popl %esi683; X86-BMI1-NEXT:    retl684;685; X86-BMI2-LABEL: bzhi64_a3_load_indexzext:686; X86-BMI2:       # %bb.0:687; X86-BMI2-NEXT:    pushl %esi688; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %esi689; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx690; X86-BMI2-NEXT:    movl $1, %eax691; X86-BMI2-NEXT:    xorl %edx, %edx692; X86-BMI2-NEXT:    shldl %cl, %eax, %edx693; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax694; X86-BMI2-NEXT:    testb $32, %cl695; X86-BMI2-NEXT:    je .LBB9_2696; X86-BMI2-NEXT:  # %bb.1:697; X86-BMI2-NEXT:    movl %eax, %edx698; X86-BMI2-NEXT:    xorl %eax, %eax699; X86-BMI2-NEXT:  .LBB9_2:700; X86-BMI2-NEXT:    addl $-1, %eax701; X86-BMI2-NEXT:    adcl $-1, %edx702; X86-BMI2-NEXT:    andl 4(%esi), %edx703; X86-BMI2-NEXT:    andl (%esi), %eax704; X86-BMI2-NEXT:    popl %esi705; X86-BMI2-NEXT:    retl706;707; X64-NOBMI-LABEL: bzhi64_a3_load_indexzext:708; X64-NOBMI:       # %bb.0:709; X64-NOBMI-NEXT:    movl %esi, %ecx710; X64-NOBMI-NEXT:    movl $1, %eax711; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx712; X64-NOBMI-NEXT:    shlq %cl, %rax713; X64-NOBMI-NEXT:    decq %rax714; X64-NOBMI-NEXT:    andq (%rdi), %rax715; X64-NOBMI-NEXT:    retq716;717; X64-BMI1-LABEL: bzhi64_a3_load_indexzext:718; X64-BMI1:       # %bb.0:719; X64-BMI1-NEXT:    # kill: def $esi killed $esi def $rsi720; X64-BMI1-NEXT:    shll $8, %esi721; X64-BMI1-NEXT:    bextrq %rsi, (%rdi), %rax722; X64-BMI1-NEXT:    retq723;724; X64-BMI2-LABEL: bzhi64_a3_load_indexzext:725; X64-BMI2:       # %bb.0:726; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi727; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax728; X64-BMI2-NEXT:    retq729  %val = load i64, ptr %w730  %conv = zext i8 %numlowbits to i64731  %onebit = shl i64 1, %conv732  %mask = add nsw i64 %onebit, -1733  %masked = and i64 %mask, %val734  ret i64 %masked735}736 737define i64 @bzhi64_a4_commutative(i64 %val, i64 %numlowbits) nounwind {738; X86-NOBMI-LABEL: bzhi64_a4_commutative:739; X86-NOBMI:       # %bb.0:740; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx741; X86-NOBMI-NEXT:    movl $1, %eax742; X86-NOBMI-NEXT:    xorl %edx, %edx743; X86-NOBMI-NEXT:    shldl %cl, %eax, %edx744; X86-NOBMI-NEXT:    shll %cl, %eax745; X86-NOBMI-NEXT:    testb $32, %cl746; X86-NOBMI-NEXT:    je .LBB10_2747; X86-NOBMI-NEXT:  # %bb.1:748; X86-NOBMI-NEXT:    movl %eax, %edx749; X86-NOBMI-NEXT:    xorl %eax, %eax750; X86-NOBMI-NEXT:  .LBB10_2:751; X86-NOBMI-NEXT:    addl $-1, %eax752; X86-NOBMI-NEXT:    adcl $-1, %edx753; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx754; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax755; X86-NOBMI-NEXT:    retl756;757; X86-BMI1-LABEL: bzhi64_a4_commutative:758; X86-BMI1:       # %bb.0:759; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx760; X86-BMI1-NEXT:    movl $1, %eax761; X86-BMI1-NEXT:    xorl %edx, %edx762; X86-BMI1-NEXT:    shldl %cl, %eax, %edx763; X86-BMI1-NEXT:    shll %cl, %eax764; X86-BMI1-NEXT:    testb $32, %cl765; X86-BMI1-NEXT:    je .LBB10_2766; X86-BMI1-NEXT:  # %bb.1:767; X86-BMI1-NEXT:    movl %eax, %edx768; X86-BMI1-NEXT:    xorl %eax, %eax769; X86-BMI1-NEXT:  .LBB10_2:770; X86-BMI1-NEXT:    addl $-1, %eax771; X86-BMI1-NEXT:    adcl $-1, %edx772; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx773; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax774; X86-BMI1-NEXT:    retl775;776; X86-BMI2-LABEL: bzhi64_a4_commutative:777; X86-BMI2:       # %bb.0:778; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx779; X86-BMI2-NEXT:    movl $1, %eax780; X86-BMI2-NEXT:    xorl %edx, %edx781; X86-BMI2-NEXT:    shldl %cl, %eax, %edx782; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax783; X86-BMI2-NEXT:    testb $32, %cl784; X86-BMI2-NEXT:    je .LBB10_2785; X86-BMI2-NEXT:  # %bb.1:786; X86-BMI2-NEXT:    movl %eax, %edx787; X86-BMI2-NEXT:    xorl %eax, %eax788; X86-BMI2-NEXT:  .LBB10_2:789; X86-BMI2-NEXT:    addl $-1, %eax790; X86-BMI2-NEXT:    adcl $-1, %edx791; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx792; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax793; X86-BMI2-NEXT:    retl794;795; X64-NOBMI-LABEL: bzhi64_a4_commutative:796; X64-NOBMI:       # %bb.0:797; X64-NOBMI-NEXT:    movq %rsi, %rcx798; X64-NOBMI-NEXT:    movl $1, %eax799; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx800; X64-NOBMI-NEXT:    shlq %cl, %rax801; X64-NOBMI-NEXT:    decq %rax802; X64-NOBMI-NEXT:    andq %rdi, %rax803; X64-NOBMI-NEXT:    retq804;805; X64-BMI1-LABEL: bzhi64_a4_commutative:806; X64-BMI1:       # %bb.0:807; X64-BMI1-NEXT:    shll $8, %esi808; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax809; X64-BMI1-NEXT:    retq810;811; X64-BMI2-LABEL: bzhi64_a4_commutative:812; X64-BMI2:       # %bb.0:813; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax814; X64-BMI2-NEXT:    retq815  %onebit = shl i64 1, %numlowbits816  %mask = add nsw i64 %onebit, -1817  %masked = and i64 %val, %mask ; swapped order818  ret i64 %masked819}820 821; 64-bit, but with 32-bit output822 823; Everything done in 64-bit, truncation happens last.824define i32 @bzhi64_32_a0(i64 %val, i64 %numlowbits) nounwind {825; X86-NOBMI-LABEL: bzhi64_32_a0:826; X86-NOBMI:       # %bb.0:827; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx828; X86-NOBMI-NEXT:    movl $1, %edx829; X86-NOBMI-NEXT:    shll %cl, %edx830; X86-NOBMI-NEXT:    xorl %eax, %eax831; X86-NOBMI-NEXT:    testb $32, %cl832; X86-NOBMI-NEXT:    jne .LBB11_2833; X86-NOBMI-NEXT:  # %bb.1:834; X86-NOBMI-NEXT:    movl %edx, %eax835; X86-NOBMI-NEXT:  .LBB11_2:836; X86-NOBMI-NEXT:    decl %eax837; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax838; X86-NOBMI-NEXT:    retl839;840; X86-BMI1-LABEL: bzhi64_32_a0:841; X86-BMI1:       # %bb.0:842; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx843; X86-BMI1-NEXT:    movl $1, %edx844; X86-BMI1-NEXT:    shll %cl, %edx845; X86-BMI1-NEXT:    xorl %eax, %eax846; X86-BMI1-NEXT:    testb $32, %cl847; X86-BMI1-NEXT:    jne .LBB11_2848; X86-BMI1-NEXT:  # %bb.1:849; X86-BMI1-NEXT:    movl %edx, %eax850; X86-BMI1-NEXT:  .LBB11_2:851; X86-BMI1-NEXT:    decl %eax852; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax853; X86-BMI1-NEXT:    retl854;855; X86-BMI2-LABEL: bzhi64_32_a0:856; X86-BMI2:       # %bb.0:857; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx858; X86-BMI2-NEXT:    xorl %eax, %eax859; X86-BMI2-NEXT:    testb $32, %cl860; X86-BMI2-NEXT:    jne .LBB11_2861; X86-BMI2-NEXT:  # %bb.1:862; X86-BMI2-NEXT:    movl $1, %eax863; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax864; X86-BMI2-NEXT:  .LBB11_2:865; X86-BMI2-NEXT:    decl %eax866; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax867; X86-BMI2-NEXT:    retl868;869; X64-NOBMI-LABEL: bzhi64_32_a0:870; X64-NOBMI:       # %bb.0:871; X64-NOBMI-NEXT:    movq %rsi, %rcx872; X64-NOBMI-NEXT:    movl $1, %eax873; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx874; X64-NOBMI-NEXT:    shlq %cl, %rax875; X64-NOBMI-NEXT:    decl %eax876; X64-NOBMI-NEXT:    andl %edi, %eax877; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax878; X64-NOBMI-NEXT:    retq879;880; X64-BMI1-LABEL: bzhi64_32_a0:881; X64-BMI1:       # %bb.0:882; X64-BMI1-NEXT:    shll $8, %esi883; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax884; X64-BMI1-NEXT:    retq885;886; X64-BMI2-LABEL: bzhi64_32_a0:887; X64-BMI2:       # %bb.0:888; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax889; X64-BMI2-NEXT:    retq890  %onebit = shl i64 1, %numlowbits891  %mask = add nsw i64 %onebit, -1892  %masked = and i64 %mask, %val893  %res = trunc i64 %masked to i32894  ret i32 %res895}896 897; Shifting happens in 64-bit, then truncation. Masking is 32-bit.898define i32 @bzhi64_32_a1(i64 %val, i32 %numlowbits) nounwind {899; X86-NOBMI-LABEL: bzhi64_32_a1:900; X86-NOBMI:       # %bb.0:901; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx902; X86-NOBMI-NEXT:    movl $1, %eax903; X86-NOBMI-NEXT:    shll %cl, %eax904; X86-NOBMI-NEXT:    decl %eax905; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax906; X86-NOBMI-NEXT:    retl907;908; X86-BMI1-LABEL: bzhi64_32_a1:909; X86-BMI1:       # %bb.0:910; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax911; X86-BMI1-NEXT:    shll $8, %eax912; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax913; X86-BMI1-NEXT:    retl914;915; X86-BMI2-LABEL: bzhi64_32_a1:916; X86-BMI2:       # %bb.0:917; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax918; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax919; X86-BMI2-NEXT:    retl920;921; X64-NOBMI-LABEL: bzhi64_32_a1:922; X64-NOBMI:       # %bb.0:923; X64-NOBMI-NEXT:    movl %esi, %ecx924; X64-NOBMI-NEXT:    movl $1, %eax925; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx926; X64-NOBMI-NEXT:    shll %cl, %eax927; X64-NOBMI-NEXT:    decl %eax928; X64-NOBMI-NEXT:    andl %edi, %eax929; X64-NOBMI-NEXT:    retq930;931; X64-BMI1-LABEL: bzhi64_32_a1:932; X64-BMI1:       # %bb.0:933; X64-BMI1-NEXT:    shll $8, %esi934; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax935; X64-BMI1-NEXT:    retq936;937; X64-BMI2-LABEL: bzhi64_32_a1:938; X64-BMI2:       # %bb.0:939; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax940; X64-BMI2-NEXT:    retq941  %truncval = trunc i64 %val to i32942  %onebit = shl i32 1, %numlowbits943  %mask = add nsw i32 %onebit, -1944  %masked = and i32 %mask, %truncval945  ret i32 %masked946}947 948; Shifting happens in 64-bit, then truncation (with extra use).949; Masking is 32-bit.950define i32 @bzhi64_32_a1_trunc_extrause(i64 %val, i32 %numlowbits, ptr %escape) nounwind {951; X86-NOBMI-LABEL: bzhi64_32_a1_trunc_extrause:952; X86-NOBMI:       # %bb.0:953; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx954; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx955; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax956; X86-NOBMI-NEXT:    movl %edx, (%eax)957; X86-NOBMI-NEXT:    movl $1, %eax958; X86-NOBMI-NEXT:    shll %cl, %eax959; X86-NOBMI-NEXT:    decl %eax960; X86-NOBMI-NEXT:    andl %edx, %eax961; X86-NOBMI-NEXT:    retl962;963; X86-BMI1-LABEL: bzhi64_32_a1_trunc_extrause:964; X86-BMI1:       # %bb.0:965; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax966; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %ecx967; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx968; X86-BMI1-NEXT:    movl %ecx, (%edx)969; X86-BMI1-NEXT:    shll $8, %eax970; X86-BMI1-NEXT:    bextrl %eax, %ecx, %eax971; X86-BMI1-NEXT:    retl972;973; X86-BMI2-LABEL: bzhi64_32_a1_trunc_extrause:974; X86-BMI2:       # %bb.0:975; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax976; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx977; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx978; X86-BMI2-NEXT:    movl %ecx, (%edx)979; X86-BMI2-NEXT:    bzhil %eax, %ecx, %eax980; X86-BMI2-NEXT:    retl981;982; X64-NOBMI-LABEL: bzhi64_32_a1_trunc_extrause:983; X64-NOBMI:       # %bb.0:984; X64-NOBMI-NEXT:    movl %esi, %ecx985; X64-NOBMI-NEXT:    movl %edi, (%rdx)986; X64-NOBMI-NEXT:    movl $1, %eax987; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx988; X64-NOBMI-NEXT:    shll %cl, %eax989; X64-NOBMI-NEXT:    decl %eax990; X64-NOBMI-NEXT:    andl %edi, %eax991; X64-NOBMI-NEXT:    retq992;993; X64-BMI1-LABEL: bzhi64_32_a1_trunc_extrause:994; X64-BMI1:       # %bb.0:995; X64-BMI1-NEXT:    movl %edi, (%rdx)996; X64-BMI1-NEXT:    shll $8, %esi997; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax998; X64-BMI1-NEXT:    retq999;1000; X64-BMI2-LABEL: bzhi64_32_a1_trunc_extrause:1001; X64-BMI2:       # %bb.0:1002; X64-BMI2-NEXT:    movl %edi, (%rdx)1003; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1004; X64-BMI2-NEXT:    retq1005  %truncval = trunc i64 %val to i321006  store i32 %truncval, ptr %escape1007  %onebit = shl i32 1, %numlowbits1008  %mask = add nsw i32 %onebit, -11009  %masked = and i32 %mask, %truncval1010  ret i32 %masked1011}1012 1013; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit.1014; Masking is 64-bit. Then truncation.1015define i32 @bzhi64_32_a2(i64 %val, i32 %numlowbits) nounwind {1016; X86-NOBMI-LABEL: bzhi64_32_a2:1017; X86-NOBMI:       # %bb.0:1018; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1019; X86-NOBMI-NEXT:    movl $1, %eax1020; X86-NOBMI-NEXT:    shll %cl, %eax1021; X86-NOBMI-NEXT:    decl %eax1022; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1023; X86-NOBMI-NEXT:    retl1024;1025; X86-BMI1-LABEL: bzhi64_32_a2:1026; X86-BMI1:       # %bb.0:1027; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1028; X86-BMI1-NEXT:    shll $8, %eax1029; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax1030; X86-BMI1-NEXT:    retl1031;1032; X86-BMI2-LABEL: bzhi64_32_a2:1033; X86-BMI2:       # %bb.0:1034; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1035; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax1036; X86-BMI2-NEXT:    retl1037;1038; X64-NOBMI-LABEL: bzhi64_32_a2:1039; X64-NOBMI:       # %bb.0:1040; X64-NOBMI-NEXT:    movl %esi, %ecx1041; X64-NOBMI-NEXT:    movl $1, %eax1042; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1043; X64-NOBMI-NEXT:    shll %cl, %eax1044; X64-NOBMI-NEXT:    decl %eax1045; X64-NOBMI-NEXT:    andl %edi, %eax1046; X64-NOBMI-NEXT:    retq1047;1048; X64-BMI1-LABEL: bzhi64_32_a2:1049; X64-BMI1:       # %bb.0:1050; X64-BMI1-NEXT:    shll $8, %esi1051; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1052; X64-BMI1-NEXT:    retq1053;1054; X64-BMI2-LABEL: bzhi64_32_a2:1055; X64-BMI2:       # %bb.0:1056; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1057; X64-BMI2-NEXT:    retq1058  %onebit = shl i32 1, %numlowbits1059  %mask = add nsw i32 %onebit, -11060  %zextmask = zext i32 %mask to i641061  %masked = and i64 %zextmask, %val1062  %truncmasked = trunc i64 %masked to i321063  ret i32 %truncmasked1064}1065 1066; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit.1067; Masking is 64-bit. Then truncation.1068define i32 @bzhi64_32_a3(i64 %val, i64 %numlowbits) nounwind {1069; X86-NOBMI-LABEL: bzhi64_32_a3:1070; X86-NOBMI:       # %bb.0:1071; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1072; X86-NOBMI-NEXT:    movl $1, %edx1073; X86-NOBMI-NEXT:    shll %cl, %edx1074; X86-NOBMI-NEXT:    xorl %eax, %eax1075; X86-NOBMI-NEXT:    testb $32, %cl1076; X86-NOBMI-NEXT:    jne .LBB15_21077; X86-NOBMI-NEXT:  # %bb.1:1078; X86-NOBMI-NEXT:    movl %edx, %eax1079; X86-NOBMI-NEXT:  .LBB15_2:1080; X86-NOBMI-NEXT:    decl %eax1081; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1082; X86-NOBMI-NEXT:    retl1083;1084; X86-BMI1-LABEL: bzhi64_32_a3:1085; X86-BMI1:       # %bb.0:1086; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1087; X86-BMI1-NEXT:    movl $1, %edx1088; X86-BMI1-NEXT:    shll %cl, %edx1089; X86-BMI1-NEXT:    xorl %eax, %eax1090; X86-BMI1-NEXT:    testb $32, %cl1091; X86-BMI1-NEXT:    jne .LBB15_21092; X86-BMI1-NEXT:  # %bb.1:1093; X86-BMI1-NEXT:    movl %edx, %eax1094; X86-BMI1-NEXT:  .LBB15_2:1095; X86-BMI1-NEXT:    decl %eax1096; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax1097; X86-BMI1-NEXT:    retl1098;1099; X86-BMI2-LABEL: bzhi64_32_a3:1100; X86-BMI2:       # %bb.0:1101; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1102; X86-BMI2-NEXT:    xorl %eax, %eax1103; X86-BMI2-NEXT:    testb $32, %cl1104; X86-BMI2-NEXT:    jne .LBB15_21105; X86-BMI2-NEXT:  # %bb.1:1106; X86-BMI2-NEXT:    movl $1, %eax1107; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax1108; X86-BMI2-NEXT:  .LBB15_2:1109; X86-BMI2-NEXT:    decl %eax1110; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax1111; X86-BMI2-NEXT:    retl1112;1113; X64-NOBMI-LABEL: bzhi64_32_a3:1114; X64-NOBMI:       # %bb.0:1115; X64-NOBMI-NEXT:    movq %rsi, %rcx1116; X64-NOBMI-NEXT:    movl $1, %eax1117; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx1118; X64-NOBMI-NEXT:    shlq %cl, %rax1119; X64-NOBMI-NEXT:    decl %eax1120; X64-NOBMI-NEXT:    andl %edi, %eax1121; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax1122; X64-NOBMI-NEXT:    retq1123;1124; X64-BMI1-LABEL: bzhi64_32_a3:1125; X64-BMI1:       # %bb.0:1126; X64-BMI1-NEXT:    shll $8, %esi1127; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1128; X64-BMI1-NEXT:    retq1129;1130; X64-BMI2-LABEL: bzhi64_32_a3:1131; X64-BMI2:       # %bb.0:1132; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1133; X64-BMI2-NEXT:    retq1134  %onebit = shl i64 1, %numlowbits1135  %mask = add nsw i64 %onebit, 42949672951136  %masked = and i64 %mask, %val1137  %truncmasked = trunc i64 %masked to i321138  ret i32 %truncmasked1139}1140 1141; ---------------------------------------------------------------------------- ;1142; Pattern b. 32-bit1143; ---------------------------------------------------------------------------- ;1144 1145define i32 @bzhi32_b0(i32 %val, i32 %numlowbits) nounwind {1146; X86-NOBMI-LABEL: bzhi32_b0:1147; X86-NOBMI:       # %bb.0:1148; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1149; X86-NOBMI-NEXT:    movl $-1, %eax1150; X86-NOBMI-NEXT:    shll %cl, %eax1151; X86-NOBMI-NEXT:    notl %eax1152; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1153; X86-NOBMI-NEXT:    retl1154;1155; X86-BMI1-LABEL: bzhi32_b0:1156; X86-BMI1:       # %bb.0:1157; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1158; X86-BMI1-NEXT:    shll $8, %eax1159; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax1160; X86-BMI1-NEXT:    retl1161;1162; X86-BMI2-LABEL: bzhi32_b0:1163; X86-BMI2:       # %bb.0:1164; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1165; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax1166; X86-BMI2-NEXT:    retl1167;1168; X64-NOBMI-LABEL: bzhi32_b0:1169; X64-NOBMI:       # %bb.0:1170; X64-NOBMI-NEXT:    movl %esi, %ecx1171; X64-NOBMI-NEXT:    movl $-1, %eax1172; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1173; X64-NOBMI-NEXT:    shll %cl, %eax1174; X64-NOBMI-NEXT:    notl %eax1175; X64-NOBMI-NEXT:    andl %edi, %eax1176; X64-NOBMI-NEXT:    retq1177;1178; X64-BMI1-LABEL: bzhi32_b0:1179; X64-BMI1:       # %bb.0:1180; X64-BMI1-NEXT:    shll $8, %esi1181; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1182; X64-BMI1-NEXT:    retq1183;1184; X64-BMI2-LABEL: bzhi32_b0:1185; X64-BMI2:       # %bb.0:1186; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1187; X64-BMI2-NEXT:    retq1188  %notmask = shl i32 -1, %numlowbits1189  %mask = xor i32 %notmask, -11190  %masked = and i32 %mask, %val1191  ret i32 %masked1192}1193 1194define i32 @bzhi32_b1_indexzext(i32 %val, i8 zeroext %numlowbits) nounwind {1195; X86-NOBMI-LABEL: bzhi32_b1_indexzext:1196; X86-NOBMI:       # %bb.0:1197; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1198; X86-NOBMI-NEXT:    movl $-1, %eax1199; X86-NOBMI-NEXT:    shll %cl, %eax1200; X86-NOBMI-NEXT:    notl %eax1201; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1202; X86-NOBMI-NEXT:    retl1203;1204; X86-BMI1-LABEL: bzhi32_b1_indexzext:1205; X86-BMI1:       # %bb.0:1206; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1207; X86-BMI1-NEXT:    shll $8, %eax1208; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax1209; X86-BMI1-NEXT:    retl1210;1211; X86-BMI2-LABEL: bzhi32_b1_indexzext:1212; X86-BMI2:       # %bb.0:1213; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1214; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax1215; X86-BMI2-NEXT:    retl1216;1217; X64-NOBMI-LABEL: bzhi32_b1_indexzext:1218; X64-NOBMI:       # %bb.0:1219; X64-NOBMI-NEXT:    movl %esi, %ecx1220; X64-NOBMI-NEXT:    movl $-1, %eax1221; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1222; X64-NOBMI-NEXT:    shll %cl, %eax1223; X64-NOBMI-NEXT:    notl %eax1224; X64-NOBMI-NEXT:    andl %edi, %eax1225; X64-NOBMI-NEXT:    retq1226;1227; X64-BMI1-LABEL: bzhi32_b1_indexzext:1228; X64-BMI1:       # %bb.0:1229; X64-BMI1-NEXT:    shll $8, %esi1230; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1231; X64-BMI1-NEXT:    retq1232;1233; X64-BMI2-LABEL: bzhi32_b1_indexzext:1234; X64-BMI2:       # %bb.0:1235; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1236; X64-BMI2-NEXT:    retq1237  %conv = zext i8 %numlowbits to i321238  %notmask = shl i32 -1, %conv1239  %mask = xor i32 %notmask, -11240  %masked = and i32 %mask, %val1241  ret i32 %masked1242}1243 1244define i32 @bzhi32_b2_load(ptr %w, i32 %numlowbits) nounwind {1245; X86-NOBMI-LABEL: bzhi32_b2_load:1246; X86-NOBMI:       # %bb.0:1247; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx1248; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1249; X86-NOBMI-NEXT:    movl $-1, %eax1250; X86-NOBMI-NEXT:    shll %cl, %eax1251; X86-NOBMI-NEXT:    notl %eax1252; X86-NOBMI-NEXT:    andl (%edx), %eax1253; X86-NOBMI-NEXT:    retl1254;1255; X86-BMI1-LABEL: bzhi32_b2_load:1256; X86-BMI1:       # %bb.0:1257; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax1258; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1259; X86-BMI1-NEXT:    shll $8, %ecx1260; X86-BMI1-NEXT:    bextrl %ecx, (%eax), %eax1261; X86-BMI1-NEXT:    retl1262;1263; X86-BMI2-LABEL: bzhi32_b2_load:1264; X86-BMI2:       # %bb.0:1265; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax1266; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1267; X86-BMI2-NEXT:    bzhil %ecx, (%eax), %eax1268; X86-BMI2-NEXT:    retl1269;1270; X64-NOBMI-LABEL: bzhi32_b2_load:1271; X64-NOBMI:       # %bb.0:1272; X64-NOBMI-NEXT:    movl %esi, %ecx1273; X64-NOBMI-NEXT:    movl $-1, %eax1274; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1275; X64-NOBMI-NEXT:    shll %cl, %eax1276; X64-NOBMI-NEXT:    notl %eax1277; X64-NOBMI-NEXT:    andl (%rdi), %eax1278; X64-NOBMI-NEXT:    retq1279;1280; X64-BMI1-LABEL: bzhi32_b2_load:1281; X64-BMI1:       # %bb.0:1282; X64-BMI1-NEXT:    shll $8, %esi1283; X64-BMI1-NEXT:    bextrl %esi, (%rdi), %eax1284; X64-BMI1-NEXT:    retq1285;1286; X64-BMI2-LABEL: bzhi32_b2_load:1287; X64-BMI2:       # %bb.0:1288; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax1289; X64-BMI2-NEXT:    retq1290  %val = load i32, ptr %w1291  %notmask = shl i32 -1, %numlowbits1292  %mask = xor i32 %notmask, -11293  %masked = and i32 %mask, %val1294  ret i32 %masked1295}1296 1297define i32 @bzhi32_b3_load_indexzext(ptr %w, i8 zeroext %numlowbits) nounwind {1298; X86-NOBMI-LABEL: bzhi32_b3_load_indexzext:1299; X86-NOBMI:       # %bb.0:1300; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx1301; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1302; X86-NOBMI-NEXT:    movl $-1, %eax1303; X86-NOBMI-NEXT:    shll %cl, %eax1304; X86-NOBMI-NEXT:    notl %eax1305; X86-NOBMI-NEXT:    andl (%edx), %eax1306; X86-NOBMI-NEXT:    retl1307;1308; X86-BMI1-LABEL: bzhi32_b3_load_indexzext:1309; X86-BMI1:       # %bb.0:1310; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax1311; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1312; X86-BMI1-NEXT:    shll $8, %ecx1313; X86-BMI1-NEXT:    bextrl %ecx, (%eax), %eax1314; X86-BMI1-NEXT:    retl1315;1316; X86-BMI2-LABEL: bzhi32_b3_load_indexzext:1317; X86-BMI2:       # %bb.0:1318; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax1319; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1320; X86-BMI2-NEXT:    bzhil %ecx, (%eax), %eax1321; X86-BMI2-NEXT:    retl1322;1323; X64-NOBMI-LABEL: bzhi32_b3_load_indexzext:1324; X64-NOBMI:       # %bb.0:1325; X64-NOBMI-NEXT:    movl %esi, %ecx1326; X64-NOBMI-NEXT:    movl $-1, %eax1327; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1328; X64-NOBMI-NEXT:    shll %cl, %eax1329; X64-NOBMI-NEXT:    notl %eax1330; X64-NOBMI-NEXT:    andl (%rdi), %eax1331; X64-NOBMI-NEXT:    retq1332;1333; X64-BMI1-LABEL: bzhi32_b3_load_indexzext:1334; X64-BMI1:       # %bb.0:1335; X64-BMI1-NEXT:    shll $8, %esi1336; X64-BMI1-NEXT:    bextrl %esi, (%rdi), %eax1337; X64-BMI1-NEXT:    retq1338;1339; X64-BMI2-LABEL: bzhi32_b3_load_indexzext:1340; X64-BMI2:       # %bb.0:1341; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax1342; X64-BMI2-NEXT:    retq1343  %val = load i32, ptr %w1344  %conv = zext i8 %numlowbits to i321345  %notmask = shl i32 -1, %conv1346  %mask = xor i32 %notmask, -11347  %masked = and i32 %mask, %val1348  ret i32 %masked1349}1350 1351define i32 @bzhi32_b4_commutative(i32 %val, i32 %numlowbits) nounwind {1352; X86-NOBMI-LABEL: bzhi32_b4_commutative:1353; X86-NOBMI:       # %bb.0:1354; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1355; X86-NOBMI-NEXT:    movl $-1, %eax1356; X86-NOBMI-NEXT:    shll %cl, %eax1357; X86-NOBMI-NEXT:    notl %eax1358; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1359; X86-NOBMI-NEXT:    retl1360;1361; X86-BMI1-LABEL: bzhi32_b4_commutative:1362; X86-BMI1:       # %bb.0:1363; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1364; X86-BMI1-NEXT:    shll $8, %eax1365; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax1366; X86-BMI1-NEXT:    retl1367;1368; X86-BMI2-LABEL: bzhi32_b4_commutative:1369; X86-BMI2:       # %bb.0:1370; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1371; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax1372; X86-BMI2-NEXT:    retl1373;1374; X64-NOBMI-LABEL: bzhi32_b4_commutative:1375; X64-NOBMI:       # %bb.0:1376; X64-NOBMI-NEXT:    movl %esi, %ecx1377; X64-NOBMI-NEXT:    movl $-1, %eax1378; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1379; X64-NOBMI-NEXT:    shll %cl, %eax1380; X64-NOBMI-NEXT:    notl %eax1381; X64-NOBMI-NEXT:    andl %edi, %eax1382; X64-NOBMI-NEXT:    retq1383;1384; X64-BMI1-LABEL: bzhi32_b4_commutative:1385; X64-BMI1:       # %bb.0:1386; X64-BMI1-NEXT:    shll $8, %esi1387; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1388; X64-BMI1-NEXT:    retq1389;1390; X64-BMI2-LABEL: bzhi32_b4_commutative:1391; X64-BMI2:       # %bb.0:1392; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1393; X64-BMI2-NEXT:    retq1394  %notmask = shl i32 -1, %numlowbits1395  %mask = xor i32 %notmask, -11396  %masked = and i32 %val, %mask ; swapped order1397  ret i32 %masked1398}1399 1400; 64-bit1401 1402define i64 @bzhi64_b0(i64 %val, i64 %numlowbits) nounwind {1403; X86-NOBMI-LABEL: bzhi64_b0:1404; X86-NOBMI:       # %bb.0:1405; X86-NOBMI-NEXT:    pushl %esi1406; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1407; X86-NOBMI-NEXT:    movl $-1, %edx1408; X86-NOBMI-NEXT:    movl $-1, %esi1409; X86-NOBMI-NEXT:    shll %cl, %esi1410; X86-NOBMI-NEXT:    xorl %eax, %eax1411; X86-NOBMI-NEXT:    testb $32, %cl1412; X86-NOBMI-NEXT:    jne .LBB21_11413; X86-NOBMI-NEXT:  # %bb.2:1414; X86-NOBMI-NEXT:    movl %esi, %eax1415; X86-NOBMI-NEXT:    jmp .LBB21_31416; X86-NOBMI-NEXT:  .LBB21_1:1417; X86-NOBMI-NEXT:    movl %esi, %edx1418; X86-NOBMI-NEXT:  .LBB21_3:1419; X86-NOBMI-NEXT:    notl %edx1420; X86-NOBMI-NEXT:    notl %eax1421; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1422; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx1423; X86-NOBMI-NEXT:    popl %esi1424; X86-NOBMI-NEXT:    retl1425;1426; X86-BMI1-LABEL: bzhi64_b0:1427; X86-BMI1:       # %bb.0:1428; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1429; X86-BMI1-NEXT:    movl $-1, %edx1430; X86-BMI1-NEXT:    movl $-1, %eax1431; X86-BMI1-NEXT:    shll %cl, %eax1432; X86-BMI1-NEXT:    testb $32, %cl1433; X86-BMI1-NEXT:    je .LBB21_21434; X86-BMI1-NEXT:  # %bb.1:1435; X86-BMI1-NEXT:    movl %eax, %edx1436; X86-BMI1-NEXT:    xorl %eax, %eax1437; X86-BMI1-NEXT:  .LBB21_2:1438; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax1439; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %edx, %edx1440; X86-BMI1-NEXT:    retl1441;1442; X86-BMI2-LABEL: bzhi64_b0:1443; X86-BMI2:       # %bb.0:1444; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %edx1445; X86-BMI2-NEXT:    movl $-1, %ecx1446; X86-BMI2-NEXT:    shlxl %edx, %ecx, %eax1447; X86-BMI2-NEXT:    testb $32, %dl1448; X86-BMI2-NEXT:    je .LBB21_21449; X86-BMI2-NEXT:  # %bb.1:1450; X86-BMI2-NEXT:    movl %eax, %ecx1451; X86-BMI2-NEXT:    xorl %eax, %eax1452; X86-BMI2-NEXT:  .LBB21_2:1453; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax1454; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %ecx, %edx1455; X86-BMI2-NEXT:    retl1456;1457; X64-NOBMI-LABEL: bzhi64_b0:1458; X64-NOBMI:       # %bb.0:1459; X64-NOBMI-NEXT:    movq %rsi, %rcx1460; X64-NOBMI-NEXT:    movq $-1, %rax1461; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx1462; X64-NOBMI-NEXT:    shlq %cl, %rax1463; X64-NOBMI-NEXT:    notq %rax1464; X64-NOBMI-NEXT:    andq %rdi, %rax1465; X64-NOBMI-NEXT:    retq1466;1467; X64-BMI1-LABEL: bzhi64_b0:1468; X64-BMI1:       # %bb.0:1469; X64-BMI1-NEXT:    shll $8, %esi1470; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax1471; X64-BMI1-NEXT:    retq1472;1473; X64-BMI2-LABEL: bzhi64_b0:1474; X64-BMI2:       # %bb.0:1475; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax1476; X64-BMI2-NEXT:    retq1477  %notmask = shl i64 -1, %numlowbits1478  %mask = xor i64 %notmask, -11479  %masked = and i64 %mask, %val1480  ret i64 %masked1481}1482 1483define i64 @bzhi64_b1_indexzext(i64 %val, i8 zeroext %numlowbits) nounwind {1484; X86-NOBMI-LABEL: bzhi64_b1_indexzext:1485; X86-NOBMI:       # %bb.0:1486; X86-NOBMI-NEXT:    pushl %esi1487; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1488; X86-NOBMI-NEXT:    movl $-1, %edx1489; X86-NOBMI-NEXT:    movl $-1, %esi1490; X86-NOBMI-NEXT:    shll %cl, %esi1491; X86-NOBMI-NEXT:    xorl %eax, %eax1492; X86-NOBMI-NEXT:    testb $32, %cl1493; X86-NOBMI-NEXT:    jne .LBB22_11494; X86-NOBMI-NEXT:  # %bb.2:1495; X86-NOBMI-NEXT:    movl %esi, %eax1496; X86-NOBMI-NEXT:    jmp .LBB22_31497; X86-NOBMI-NEXT:  .LBB22_1:1498; X86-NOBMI-NEXT:    movl %esi, %edx1499; X86-NOBMI-NEXT:  .LBB22_3:1500; X86-NOBMI-NEXT:    notl %edx1501; X86-NOBMI-NEXT:    notl %eax1502; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1503; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx1504; X86-NOBMI-NEXT:    popl %esi1505; X86-NOBMI-NEXT:    retl1506;1507; X86-BMI1-LABEL: bzhi64_b1_indexzext:1508; X86-BMI1:       # %bb.0:1509; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1510; X86-BMI1-NEXT:    movl $-1, %edx1511; X86-BMI1-NEXT:    movl $-1, %eax1512; X86-BMI1-NEXT:    shll %cl, %eax1513; X86-BMI1-NEXT:    testb $32, %cl1514; X86-BMI1-NEXT:    je .LBB22_21515; X86-BMI1-NEXT:  # %bb.1:1516; X86-BMI1-NEXT:    movl %eax, %edx1517; X86-BMI1-NEXT:    xorl %eax, %eax1518; X86-BMI1-NEXT:  .LBB22_2:1519; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax1520; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %edx, %edx1521; X86-BMI1-NEXT:    retl1522;1523; X86-BMI2-LABEL: bzhi64_b1_indexzext:1524; X86-BMI2:       # %bb.0:1525; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %edx1526; X86-BMI2-NEXT:    movl $-1, %ecx1527; X86-BMI2-NEXT:    shlxl %edx, %ecx, %eax1528; X86-BMI2-NEXT:    testb $32, %dl1529; X86-BMI2-NEXT:    je .LBB22_21530; X86-BMI2-NEXT:  # %bb.1:1531; X86-BMI2-NEXT:    movl %eax, %ecx1532; X86-BMI2-NEXT:    xorl %eax, %eax1533; X86-BMI2-NEXT:  .LBB22_2:1534; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax1535; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %ecx, %edx1536; X86-BMI2-NEXT:    retl1537;1538; X64-NOBMI-LABEL: bzhi64_b1_indexzext:1539; X64-NOBMI:       # %bb.0:1540; X64-NOBMI-NEXT:    movl %esi, %ecx1541; X64-NOBMI-NEXT:    movq $-1, %rax1542; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1543; X64-NOBMI-NEXT:    shlq %cl, %rax1544; X64-NOBMI-NEXT:    notq %rax1545; X64-NOBMI-NEXT:    andq %rdi, %rax1546; X64-NOBMI-NEXT:    retq1547;1548; X64-BMI1-LABEL: bzhi64_b1_indexzext:1549; X64-BMI1:       # %bb.0:1550; X64-BMI1-NEXT:    # kill: def $esi killed $esi def $rsi1551; X64-BMI1-NEXT:    shll $8, %esi1552; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax1553; X64-BMI1-NEXT:    retq1554;1555; X64-BMI2-LABEL: bzhi64_b1_indexzext:1556; X64-BMI2:       # %bb.0:1557; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi1558; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax1559; X64-BMI2-NEXT:    retq1560  %conv = zext i8 %numlowbits to i641561  %notmask = shl i64 -1, %conv1562  %mask = xor i64 %notmask, -11563  %masked = and i64 %mask, %val1564  ret i64 %masked1565}1566 1567define i64 @bzhi64_b2_load(ptr %w, i64 %numlowbits) nounwind {1568; X86-NOBMI-LABEL: bzhi64_b2_load:1569; X86-NOBMI:       # %bb.0:1570; X86-NOBMI-NEXT:    pushl %edi1571; X86-NOBMI-NEXT:    pushl %esi1572; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi1573; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1574; X86-NOBMI-NEXT:    movl $-1, %edx1575; X86-NOBMI-NEXT:    movl $-1, %edi1576; X86-NOBMI-NEXT:    shll %cl, %edi1577; X86-NOBMI-NEXT:    xorl %eax, %eax1578; X86-NOBMI-NEXT:    testb $32, %cl1579; X86-NOBMI-NEXT:    jne .LBB23_11580; X86-NOBMI-NEXT:  # %bb.2:1581; X86-NOBMI-NEXT:    movl %edi, %eax1582; X86-NOBMI-NEXT:    jmp .LBB23_31583; X86-NOBMI-NEXT:  .LBB23_1:1584; X86-NOBMI-NEXT:    movl %edi, %edx1585; X86-NOBMI-NEXT:  .LBB23_3:1586; X86-NOBMI-NEXT:    notl %edx1587; X86-NOBMI-NEXT:    notl %eax1588; X86-NOBMI-NEXT:    andl (%esi), %eax1589; X86-NOBMI-NEXT:    andl 4(%esi), %edx1590; X86-NOBMI-NEXT:    popl %esi1591; X86-NOBMI-NEXT:    popl %edi1592; X86-NOBMI-NEXT:    retl1593;1594; X86-BMI1-LABEL: bzhi64_b2_load:1595; X86-BMI1:       # %bb.0:1596; X86-BMI1-NEXT:    pushl %esi1597; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx1598; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1599; X86-BMI1-NEXT:    movl $-1, %esi1600; X86-BMI1-NEXT:    movl $-1, %eax1601; X86-BMI1-NEXT:    shll %cl, %eax1602; X86-BMI1-NEXT:    testb $32, %cl1603; X86-BMI1-NEXT:    je .LBB23_21604; X86-BMI1-NEXT:  # %bb.1:1605; X86-BMI1-NEXT:    movl %eax, %esi1606; X86-BMI1-NEXT:    xorl %eax, %eax1607; X86-BMI1-NEXT:  .LBB23_2:1608; X86-BMI1-NEXT:    andnl (%edx), %eax, %eax1609; X86-BMI1-NEXT:    andnl 4(%edx), %esi, %edx1610; X86-BMI1-NEXT:    popl %esi1611; X86-BMI1-NEXT:    retl1612;1613; X86-BMI2-LABEL: bzhi64_b2_load:1614; X86-BMI2:       # %bb.0:1615; X86-BMI2-NEXT:    pushl %ebx1616; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx1617; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ebx1618; X86-BMI2-NEXT:    movl $-1, %edx1619; X86-BMI2-NEXT:    shlxl %ebx, %edx, %eax1620; X86-BMI2-NEXT:    testb $32, %bl1621; X86-BMI2-NEXT:    je .LBB23_21622; X86-BMI2-NEXT:  # %bb.1:1623; X86-BMI2-NEXT:    movl %eax, %edx1624; X86-BMI2-NEXT:    xorl %eax, %eax1625; X86-BMI2-NEXT:  .LBB23_2:1626; X86-BMI2-NEXT:    andnl (%ecx), %eax, %eax1627; X86-BMI2-NEXT:    andnl 4(%ecx), %edx, %edx1628; X86-BMI2-NEXT:    popl %ebx1629; X86-BMI2-NEXT:    retl1630;1631; X64-NOBMI-LABEL: bzhi64_b2_load:1632; X64-NOBMI:       # %bb.0:1633; X64-NOBMI-NEXT:    movq %rsi, %rcx1634; X64-NOBMI-NEXT:    movq $-1, %rax1635; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx1636; X64-NOBMI-NEXT:    shlq %cl, %rax1637; X64-NOBMI-NEXT:    notq %rax1638; X64-NOBMI-NEXT:    andq (%rdi), %rax1639; X64-NOBMI-NEXT:    retq1640;1641; X64-BMI1-LABEL: bzhi64_b2_load:1642; X64-BMI1:       # %bb.0:1643; X64-BMI1-NEXT:    shll $8, %esi1644; X64-BMI1-NEXT:    bextrq %rsi, (%rdi), %rax1645; X64-BMI1-NEXT:    retq1646;1647; X64-BMI2-LABEL: bzhi64_b2_load:1648; X64-BMI2:       # %bb.0:1649; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax1650; X64-BMI2-NEXT:    retq1651  %val = load i64, ptr %w1652  %notmask = shl i64 -1, %numlowbits1653  %mask = xor i64 %notmask, -11654  %masked = and i64 %mask, %val1655  ret i64 %masked1656}1657 1658define i64 @bzhi64_b3_load_indexzext(ptr %w, i8 zeroext %numlowbits) nounwind {1659; X86-NOBMI-LABEL: bzhi64_b3_load_indexzext:1660; X86-NOBMI:       # %bb.0:1661; X86-NOBMI-NEXT:    pushl %edi1662; X86-NOBMI-NEXT:    pushl %esi1663; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi1664; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1665; X86-NOBMI-NEXT:    movl $-1, %edx1666; X86-NOBMI-NEXT:    movl $-1, %edi1667; X86-NOBMI-NEXT:    shll %cl, %edi1668; X86-NOBMI-NEXT:    xorl %eax, %eax1669; X86-NOBMI-NEXT:    testb $32, %cl1670; X86-NOBMI-NEXT:    jne .LBB24_11671; X86-NOBMI-NEXT:  # %bb.2:1672; X86-NOBMI-NEXT:    movl %edi, %eax1673; X86-NOBMI-NEXT:    jmp .LBB24_31674; X86-NOBMI-NEXT:  .LBB24_1:1675; X86-NOBMI-NEXT:    movl %edi, %edx1676; X86-NOBMI-NEXT:  .LBB24_3:1677; X86-NOBMI-NEXT:    notl %edx1678; X86-NOBMI-NEXT:    notl %eax1679; X86-NOBMI-NEXT:    andl (%esi), %eax1680; X86-NOBMI-NEXT:    andl 4(%esi), %edx1681; X86-NOBMI-NEXT:    popl %esi1682; X86-NOBMI-NEXT:    popl %edi1683; X86-NOBMI-NEXT:    retl1684;1685; X86-BMI1-LABEL: bzhi64_b3_load_indexzext:1686; X86-BMI1:       # %bb.0:1687; X86-BMI1-NEXT:    pushl %esi1688; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx1689; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1690; X86-BMI1-NEXT:    movl $-1, %esi1691; X86-BMI1-NEXT:    movl $-1, %eax1692; X86-BMI1-NEXT:    shll %cl, %eax1693; X86-BMI1-NEXT:    testb $32, %cl1694; X86-BMI1-NEXT:    je .LBB24_21695; X86-BMI1-NEXT:  # %bb.1:1696; X86-BMI1-NEXT:    movl %eax, %esi1697; X86-BMI1-NEXT:    xorl %eax, %eax1698; X86-BMI1-NEXT:  .LBB24_2:1699; X86-BMI1-NEXT:    andnl (%edx), %eax, %eax1700; X86-BMI1-NEXT:    andnl 4(%edx), %esi, %edx1701; X86-BMI1-NEXT:    popl %esi1702; X86-BMI1-NEXT:    retl1703;1704; X86-BMI2-LABEL: bzhi64_b3_load_indexzext:1705; X86-BMI2:       # %bb.0:1706; X86-BMI2-NEXT:    pushl %ebx1707; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx1708; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ebx1709; X86-BMI2-NEXT:    movl $-1, %edx1710; X86-BMI2-NEXT:    shlxl %ebx, %edx, %eax1711; X86-BMI2-NEXT:    testb $32, %bl1712; X86-BMI2-NEXT:    je .LBB24_21713; X86-BMI2-NEXT:  # %bb.1:1714; X86-BMI2-NEXT:    movl %eax, %edx1715; X86-BMI2-NEXT:    xorl %eax, %eax1716; X86-BMI2-NEXT:  .LBB24_2:1717; X86-BMI2-NEXT:    andnl (%ecx), %eax, %eax1718; X86-BMI2-NEXT:    andnl 4(%ecx), %edx, %edx1719; X86-BMI2-NEXT:    popl %ebx1720; X86-BMI2-NEXT:    retl1721;1722; X64-NOBMI-LABEL: bzhi64_b3_load_indexzext:1723; X64-NOBMI:       # %bb.0:1724; X64-NOBMI-NEXT:    movl %esi, %ecx1725; X64-NOBMI-NEXT:    movq $-1, %rax1726; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1727; X64-NOBMI-NEXT:    shlq %cl, %rax1728; X64-NOBMI-NEXT:    notq %rax1729; X64-NOBMI-NEXT:    andq (%rdi), %rax1730; X64-NOBMI-NEXT:    retq1731;1732; X64-BMI1-LABEL: bzhi64_b3_load_indexzext:1733; X64-BMI1:       # %bb.0:1734; X64-BMI1-NEXT:    # kill: def $esi killed $esi def $rsi1735; X64-BMI1-NEXT:    shll $8, %esi1736; X64-BMI1-NEXT:    bextrq %rsi, (%rdi), %rax1737; X64-BMI1-NEXT:    retq1738;1739; X64-BMI2-LABEL: bzhi64_b3_load_indexzext:1740; X64-BMI2:       # %bb.0:1741; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi1742; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax1743; X64-BMI2-NEXT:    retq1744  %val = load i64, ptr %w1745  %conv = zext i8 %numlowbits to i641746  %notmask = shl i64 -1, %conv1747  %mask = xor i64 %notmask, -11748  %masked = and i64 %mask, %val1749  ret i64 %masked1750}1751 1752define i64 @bzhi64_b4_commutative(i64 %val, i64 %numlowbits) nounwind {1753; X86-NOBMI-LABEL: bzhi64_b4_commutative:1754; X86-NOBMI:       # %bb.0:1755; X86-NOBMI-NEXT:    pushl %esi1756; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1757; X86-NOBMI-NEXT:    movl $-1, %edx1758; X86-NOBMI-NEXT:    movl $-1, %esi1759; X86-NOBMI-NEXT:    shll %cl, %esi1760; X86-NOBMI-NEXT:    xorl %eax, %eax1761; X86-NOBMI-NEXT:    testb $32, %cl1762; X86-NOBMI-NEXT:    jne .LBB25_11763; X86-NOBMI-NEXT:  # %bb.2:1764; X86-NOBMI-NEXT:    movl %esi, %eax1765; X86-NOBMI-NEXT:    jmp .LBB25_31766; X86-NOBMI-NEXT:  .LBB25_1:1767; X86-NOBMI-NEXT:    movl %esi, %edx1768; X86-NOBMI-NEXT:  .LBB25_3:1769; X86-NOBMI-NEXT:    notl %edx1770; X86-NOBMI-NEXT:    notl %eax1771; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1772; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx1773; X86-NOBMI-NEXT:    popl %esi1774; X86-NOBMI-NEXT:    retl1775;1776; X86-BMI1-LABEL: bzhi64_b4_commutative:1777; X86-BMI1:       # %bb.0:1778; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1779; X86-BMI1-NEXT:    movl $-1, %edx1780; X86-BMI1-NEXT:    movl $-1, %eax1781; X86-BMI1-NEXT:    shll %cl, %eax1782; X86-BMI1-NEXT:    testb $32, %cl1783; X86-BMI1-NEXT:    je .LBB25_21784; X86-BMI1-NEXT:  # %bb.1:1785; X86-BMI1-NEXT:    movl %eax, %edx1786; X86-BMI1-NEXT:    xorl %eax, %eax1787; X86-BMI1-NEXT:  .LBB25_2:1788; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax1789; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %edx, %edx1790; X86-BMI1-NEXT:    retl1791;1792; X86-BMI2-LABEL: bzhi64_b4_commutative:1793; X86-BMI2:       # %bb.0:1794; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %edx1795; X86-BMI2-NEXT:    movl $-1, %ecx1796; X86-BMI2-NEXT:    shlxl %edx, %ecx, %eax1797; X86-BMI2-NEXT:    testb $32, %dl1798; X86-BMI2-NEXT:    je .LBB25_21799; X86-BMI2-NEXT:  # %bb.1:1800; X86-BMI2-NEXT:    movl %eax, %ecx1801; X86-BMI2-NEXT:    xorl %eax, %eax1802; X86-BMI2-NEXT:  .LBB25_2:1803; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax1804; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %ecx, %edx1805; X86-BMI2-NEXT:    retl1806;1807; X64-NOBMI-LABEL: bzhi64_b4_commutative:1808; X64-NOBMI:       # %bb.0:1809; X64-NOBMI-NEXT:    movq %rsi, %rcx1810; X64-NOBMI-NEXT:    movq $-1, %rax1811; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx1812; X64-NOBMI-NEXT:    shlq %cl, %rax1813; X64-NOBMI-NEXT:    notq %rax1814; X64-NOBMI-NEXT:    andq %rdi, %rax1815; X64-NOBMI-NEXT:    retq1816;1817; X64-BMI1-LABEL: bzhi64_b4_commutative:1818; X64-BMI1:       # %bb.0:1819; X64-BMI1-NEXT:    shll $8, %esi1820; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax1821; X64-BMI1-NEXT:    retq1822;1823; X64-BMI2-LABEL: bzhi64_b4_commutative:1824; X64-BMI2:       # %bb.0:1825; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax1826; X64-BMI2-NEXT:    retq1827  %notmask = shl i64 -1, %numlowbits1828  %mask = xor i64 %notmask, -11829  %masked = and i64 %val, %mask ; swapped order1830  ret i64 %masked1831}1832 1833; 64-bit, but with 32-bit output1834 1835; Everything done in 64-bit, truncation happens last.1836define i32 @bzhi64_32_b0(i64 %val, i8 %numlowbits) nounwind {1837; X86-NOBMI-LABEL: bzhi64_32_b0:1838; X86-NOBMI:       # %bb.0:1839; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1840; X86-NOBMI-NEXT:    movl $-1, %edx1841; X86-NOBMI-NEXT:    shll %cl, %edx1842; X86-NOBMI-NEXT:    xorl %eax, %eax1843; X86-NOBMI-NEXT:    testb $32, %cl1844; X86-NOBMI-NEXT:    jne .LBB26_21845; X86-NOBMI-NEXT:  # %bb.1:1846; X86-NOBMI-NEXT:    movl %edx, %eax1847; X86-NOBMI-NEXT:  .LBB26_2:1848; X86-NOBMI-NEXT:    notl %eax1849; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1850; X86-NOBMI-NEXT:    retl1851;1852; X86-BMI1-LABEL: bzhi64_32_b0:1853; X86-BMI1:       # %bb.0:1854; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1855; X86-BMI1-NEXT:    movl $-1, %eax1856; X86-BMI1-NEXT:    shll %cl, %eax1857; X86-BMI1-NEXT:    xorl %edx, %edx1858; X86-BMI1-NEXT:    testb $32, %cl1859; X86-BMI1-NEXT:    jne .LBB26_21860; X86-BMI1-NEXT:  # %bb.1:1861; X86-BMI1-NEXT:    movl %eax, %edx1862; X86-BMI1-NEXT:  .LBB26_2:1863; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %edx, %eax1864; X86-BMI1-NEXT:    retl1865;1866; X86-BMI2-LABEL: bzhi64_32_b0:1867; X86-BMI2:       # %bb.0:1868; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1869; X86-BMI2-NEXT:    xorl %ecx, %ecx1870; X86-BMI2-NEXT:    testb $32, %al1871; X86-BMI2-NEXT:    jne .LBB26_21872; X86-BMI2-NEXT:  # %bb.1:1873; X86-BMI2-NEXT:    movl $-1, %ecx1874; X86-BMI2-NEXT:    shlxl %eax, %ecx, %ecx1875; X86-BMI2-NEXT:  .LBB26_2:1876; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %ecx, %eax1877; X86-BMI2-NEXT:    retl1878;1879; X64-NOBMI-LABEL: bzhi64_32_b0:1880; X64-NOBMI:       # %bb.0:1881; X64-NOBMI-NEXT:    movl %esi, %ecx1882; X64-NOBMI-NEXT:    movq $-1, %rax1883; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1884; X64-NOBMI-NEXT:    shlq %cl, %rax1885; X64-NOBMI-NEXT:    notl %eax1886; X64-NOBMI-NEXT:    andl %edi, %eax1887; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax1888; X64-NOBMI-NEXT:    retq1889;1890; X64-BMI1-LABEL: bzhi64_32_b0:1891; X64-BMI1:       # %bb.0:1892; X64-BMI1-NEXT:    shll $8, %esi1893; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1894; X64-BMI1-NEXT:    retq1895;1896; X64-BMI2-LABEL: bzhi64_32_b0:1897; X64-BMI2:       # %bb.0:1898; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1899; X64-BMI2-NEXT:    retq1900  %widenumlowbits = zext i8 %numlowbits to i641901  %notmask = shl nsw i64 -1, %widenumlowbits1902  %mask = xor i64 %notmask, -11903  %wideres = and i64 %val, %mask1904  %res = trunc i64 %wideres to i321905  ret i32 %res1906}1907 1908; Shifting happens in 64-bit, then truncation. Masking is 32-bit.1909define i32 @bzhi64_32_b1(i64 %val, i8 %numlowbits) nounwind {1910; X86-NOBMI-LABEL: bzhi64_32_b1:1911; X86-NOBMI:       # %bb.0:1912; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1913; X86-NOBMI-NEXT:    movl $-1, %eax1914; X86-NOBMI-NEXT:    shll %cl, %eax1915; X86-NOBMI-NEXT:    notl %eax1916; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1917; X86-NOBMI-NEXT:    retl1918;1919; X86-BMI1-LABEL: bzhi64_32_b1:1920; X86-BMI1:       # %bb.0:1921; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1922; X86-BMI1-NEXT:    shll $8, %eax1923; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax1924; X86-BMI1-NEXT:    retl1925;1926; X86-BMI2-LABEL: bzhi64_32_b1:1927; X86-BMI2:       # %bb.0:1928; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1929; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax1930; X86-BMI2-NEXT:    retl1931;1932; X64-NOBMI-LABEL: bzhi64_32_b1:1933; X64-NOBMI:       # %bb.0:1934; X64-NOBMI-NEXT:    movl %esi, %ecx1935; X64-NOBMI-NEXT:    movl $-1, %eax1936; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1937; X64-NOBMI-NEXT:    shll %cl, %eax1938; X64-NOBMI-NEXT:    notl %eax1939; X64-NOBMI-NEXT:    andl %edi, %eax1940; X64-NOBMI-NEXT:    retq1941;1942; X64-BMI1-LABEL: bzhi64_32_b1:1943; X64-BMI1:       # %bb.0:1944; X64-BMI1-NEXT:    shll $8, %esi1945; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1946; X64-BMI1-NEXT:    retq1947;1948; X64-BMI2-LABEL: bzhi64_32_b1:1949; X64-BMI2:       # %bb.0:1950; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax1951; X64-BMI2-NEXT:    retq1952  %truncval = trunc i64 %val to i321953  %widenumlowbits = zext i8 %numlowbits to i321954  %notmask = shl nsw i32 -1, %widenumlowbits1955  %mask = xor i32 %notmask, -11956  %res = and i32 %truncval, %mask1957  ret i32 %res1958}1959 1960; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit.1961; Masking is 64-bit. Then truncation.1962define i32 @bzhi64_32_b2(i64 %val, i8 %numlowbits) nounwind {1963; X86-NOBMI-LABEL: bzhi64_32_b2:1964; X86-NOBMI:       # %bb.0:1965; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx1966; X86-NOBMI-NEXT:    movl $-1, %eax1967; X86-NOBMI-NEXT:    shll %cl, %eax1968; X86-NOBMI-NEXT:    notl %eax1969; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax1970; X86-NOBMI-NEXT:    retl1971;1972; X86-BMI1-LABEL: bzhi64_32_b2:1973; X86-BMI1:       # %bb.0:1974; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1975; X86-BMI1-NEXT:    shll $8, %eax1976; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax1977; X86-BMI1-NEXT:    retl1978;1979; X86-BMI2-LABEL: bzhi64_32_b2:1980; X86-BMI2:       # %bb.0:1981; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax1982; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax1983; X86-BMI2-NEXT:    retl1984;1985; X64-NOBMI-LABEL: bzhi64_32_b2:1986; X64-NOBMI:       # %bb.0:1987; X64-NOBMI-NEXT:    movl %esi, %ecx1988; X64-NOBMI-NEXT:    movl $-1, %eax1989; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx1990; X64-NOBMI-NEXT:    shll %cl, %eax1991; X64-NOBMI-NEXT:    notl %eax1992; X64-NOBMI-NEXT:    andl %edi, %eax1993; X64-NOBMI-NEXT:    retq1994;1995; X64-BMI1-LABEL: bzhi64_32_b2:1996; X64-BMI1:       # %bb.0:1997; X64-BMI1-NEXT:    shll $8, %esi1998; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax1999; X64-BMI1-NEXT:    retq2000;2001; X64-BMI2-LABEL: bzhi64_32_b2:2002; X64-BMI2:       # %bb.0:2003; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax2004; X64-BMI2-NEXT:    retq2005  %widenumlowbits = zext i8 %numlowbits to i322006  %notmask = shl nsw i32 -1, %widenumlowbits2007  %mask = xor i32 %notmask, -12008  %zextmask = zext i32 %mask to i642009  %wideres = and i64 %val, %zextmask2010  %res = trunc i64 %wideres to i322011  ret i32 %res2012}2013 2014; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit.2015; Masking is 64-bit. Then truncation.2016define i32 @bzhi64_32_b3(i64 %val, i8 %numlowbits) nounwind {2017; X86-NOBMI-LABEL: bzhi64_32_b3:2018; X86-NOBMI:       # %bb.0:2019; X86-NOBMI-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx2020; X86-NOBMI-NEXT:    movl $-1, %edx2021; X86-NOBMI-NEXT:    shll %cl, %edx2022; X86-NOBMI-NEXT:    xorl %eax, %eax2023; X86-NOBMI-NEXT:    testb $32, %cl2024; X86-NOBMI-NEXT:    jne .LBB29_22025; X86-NOBMI-NEXT:  # %bb.1:2026; X86-NOBMI-NEXT:    movl %edx, %eax2027; X86-NOBMI-NEXT:  .LBB29_2:2028; X86-NOBMI-NEXT:    notl %eax2029; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2030; X86-NOBMI-NEXT:    retl2031;2032; X86-BMI1-LABEL: bzhi64_32_b3:2033; X86-BMI1:       # %bb.0:2034; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx2035; X86-BMI1-NEXT:    movl $-1, %eax2036; X86-BMI1-NEXT:    shll %cl, %eax2037; X86-BMI1-NEXT:    xorl %edx, %edx2038; X86-BMI1-NEXT:    testb $32, %cl2039; X86-BMI1-NEXT:    jne .LBB29_22040; X86-BMI1-NEXT:  # %bb.1:2041; X86-BMI1-NEXT:    movl %eax, %edx2042; X86-BMI1-NEXT:  .LBB29_2:2043; X86-BMI1-NEXT:    andnl {{[0-9]+}}(%esp), %edx, %eax2044; X86-BMI1-NEXT:    retl2045;2046; X86-BMI2-LABEL: bzhi64_32_b3:2047; X86-BMI2:       # %bb.0:2048; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax2049; X86-BMI2-NEXT:    xorl %ecx, %ecx2050; X86-BMI2-NEXT:    testb $32, %al2051; X86-BMI2-NEXT:    jne .LBB29_22052; X86-BMI2-NEXT:  # %bb.1:2053; X86-BMI2-NEXT:    movl $-1, %ecx2054; X86-BMI2-NEXT:    shlxl %eax, %ecx, %ecx2055; X86-BMI2-NEXT:  .LBB29_2:2056; X86-BMI2-NEXT:    andnl {{[0-9]+}}(%esp), %ecx, %eax2057; X86-BMI2-NEXT:    retl2058;2059; X64-NOBMI-LABEL: bzhi64_32_b3:2060; X64-NOBMI:       # %bb.0:2061; X64-NOBMI-NEXT:    movl %esi, %ecx2062; X64-NOBMI-NEXT:    movl $4294967295, %eax # imm = 0xFFFFFFFF2063; X64-NOBMI-NEXT:    movl $4294967295, %edx # imm = 0xFFFFFFFF2064; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2065; X64-NOBMI-NEXT:    shlq %cl, %rdx2066; X64-NOBMI-NEXT:    xorl %edx, %eax2067; X64-NOBMI-NEXT:    andl %edi, %eax2068; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax2069; X64-NOBMI-NEXT:    retq2070;2071; X64-BMI1-LABEL: bzhi64_32_b3:2072; X64-BMI1:       # %bb.0:2073; X64-BMI1-NEXT:    shll $8, %esi2074; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax2075; X64-BMI1-NEXT:    retq2076;2077; X64-BMI2-LABEL: bzhi64_32_b3:2078; X64-BMI2:       # %bb.0:2079; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax2080; X64-BMI2-NEXT:    retq2081  %widenumlowbits = zext i8 %numlowbits to i642082  %notmask = shl nsw i64 4294967295, %widenumlowbits2083  %mask = xor i64 %notmask, 42949672952084  %wideres = and i64 %val, %mask2085  %res = trunc i64 %wideres to i322086  ret i32 %res2087}2088 2089; ---------------------------------------------------------------------------- ;2090; Pattern c. 32-bit2091; ---------------------------------------------------------------------------- ;2092 2093define i32 @bzhi32_c0(i32 %val, i32 %numlowbits, ptr %escape) nounwind {2094; X86-NOBMI-LABEL: bzhi32_c0:2095; X86-NOBMI:       # %bb.0:2096; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx2097; X86-NOBMI-NEXT:    xorl %ecx, %ecx2098; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2099; X86-NOBMI-NEXT:    movl $-1, %eax2100; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2101; X86-NOBMI-NEXT:    shrl %cl, %eax2102; X86-NOBMI-NEXT:    movl %eax, (%edx)2103; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2104; X86-NOBMI-NEXT:    retl2105;2106; X86-BMI1-LABEL: bzhi32_c0:2107; X86-BMI1:       # %bb.0:2108; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx2109; X86-BMI1-NEXT:    xorl %ecx, %ecx2110; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2111; X86-BMI1-NEXT:    movl $-1, %eax2112; X86-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2113; X86-BMI1-NEXT:    shrl %cl, %eax2114; X86-BMI1-NEXT:    movl %eax, (%edx)2115; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax2116; X86-BMI1-NEXT:    retl2117;2118; X86-BMI2-LABEL: bzhi32_c0:2119; X86-BMI2:       # %bb.0:2120; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2121; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx2122; X86-BMI2-NEXT:    movl $-1, %edx2123; X86-BMI2-NEXT:    bzhil %ecx, %edx, %edx2124; X86-BMI2-NEXT:    movl %edx, (%eax)2125; X86-BMI2-NEXT:    bzhil %ecx, {{[0-9]+}}(%esp), %eax2126; X86-BMI2-NEXT:    retl2127;2128; X64-NOBMI-LABEL: bzhi32_c0:2129; X64-NOBMI:       # %bb.0:2130; X64-NOBMI-NEXT:    movl %esi, %ecx2131; X64-NOBMI-NEXT:    negb %cl2132; X64-NOBMI-NEXT:    movl $-1, %eax2133; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2134; X64-NOBMI-NEXT:    shrl %cl, %eax2135; X64-NOBMI-NEXT:    movl %eax, (%rdx)2136; X64-NOBMI-NEXT:    andl %edi, %eax2137; X64-NOBMI-NEXT:    retq2138;2139; X64-BMI1-LABEL: bzhi32_c0:2140; X64-BMI1:       # %bb.0:2141; X64-BMI1-NEXT:    movl %esi, %ecx2142; X64-BMI1-NEXT:    negb %cl2143; X64-BMI1-NEXT:    movl $-1, %eax2144; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2145; X64-BMI1-NEXT:    shrl %cl, %eax2146; X64-BMI1-NEXT:    movl %eax, (%rdx)2147; X64-BMI1-NEXT:    andl %edi, %eax2148; X64-BMI1-NEXT:    retq2149;2150; X64-BMI2-LABEL: bzhi32_c0:2151; X64-BMI2:       # %bb.0:2152; X64-BMI2-NEXT:    movl $-1, %eax2153; X64-BMI2-NEXT:    bzhil %esi, %eax, %eax2154; X64-BMI2-NEXT:    movl %eax, (%rdx)2155; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax2156; X64-BMI2-NEXT:    retq2157  %numhighbits = sub i32 32, %numlowbits2158  %mask = lshr i32 -1, %numhighbits2159  store i32 %mask, ptr %escape2160  %masked = and i32 %mask, %val2161  ret i32 %masked2162}2163 2164define i32 @bzhi32_c1_indexzext(i32 %val, i8 %numlowbits, ptr %escape) nounwind {2165; X86-NOBMI-LABEL: bzhi32_c1_indexzext:2166; X86-NOBMI:       # %bb.0:2167; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx2168; X86-NOBMI-NEXT:    xorl %ecx, %ecx2169; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2170; X86-NOBMI-NEXT:    movl $-1, %eax2171; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2172; X86-NOBMI-NEXT:    shrl %cl, %eax2173; X86-NOBMI-NEXT:    movl %eax, (%edx)2174; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2175; X86-NOBMI-NEXT:    retl2176;2177; X86-BMI1-LABEL: bzhi32_c1_indexzext:2178; X86-BMI1:       # %bb.0:2179; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx2180; X86-BMI1-NEXT:    xorl %ecx, %ecx2181; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2182; X86-BMI1-NEXT:    movl $-1, %eax2183; X86-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2184; X86-BMI1-NEXT:    shrl %cl, %eax2185; X86-BMI1-NEXT:    movl %eax, (%edx)2186; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax2187; X86-BMI1-NEXT:    retl2188;2189; X86-BMI2-LABEL: bzhi32_c1_indexzext:2190; X86-BMI2:       # %bb.0:2191; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2192; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx2193; X86-BMI2-NEXT:    movl $-1, %edx2194; X86-BMI2-NEXT:    bzhil %ecx, %edx, %edx2195; X86-BMI2-NEXT:    movl %edx, (%eax)2196; X86-BMI2-NEXT:    bzhil %ecx, {{[0-9]+}}(%esp), %eax2197; X86-BMI2-NEXT:    retl2198;2199; X64-NOBMI-LABEL: bzhi32_c1_indexzext:2200; X64-NOBMI:       # %bb.0:2201; X64-NOBMI-NEXT:    movl %esi, %ecx2202; X64-NOBMI-NEXT:    negb %cl2203; X64-NOBMI-NEXT:    movl $-1, %eax2204; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2205; X64-NOBMI-NEXT:    shrl %cl, %eax2206; X64-NOBMI-NEXT:    movl %eax, (%rdx)2207; X64-NOBMI-NEXT:    andl %edi, %eax2208; X64-NOBMI-NEXT:    retq2209;2210; X64-BMI1-LABEL: bzhi32_c1_indexzext:2211; X64-BMI1:       # %bb.0:2212; X64-BMI1-NEXT:    movl %esi, %ecx2213; X64-BMI1-NEXT:    negb %cl2214; X64-BMI1-NEXT:    movl $-1, %eax2215; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2216; X64-BMI1-NEXT:    shrl %cl, %eax2217; X64-BMI1-NEXT:    movl %eax, (%rdx)2218; X64-BMI1-NEXT:    andl %edi, %eax2219; X64-BMI1-NEXT:    retq2220;2221; X64-BMI2-LABEL: bzhi32_c1_indexzext:2222; X64-BMI2:       # %bb.0:2223; X64-BMI2-NEXT:    movl $-1, %eax2224; X64-BMI2-NEXT:    bzhil %esi, %eax, %eax2225; X64-BMI2-NEXT:    movl %eax, (%rdx)2226; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax2227; X64-BMI2-NEXT:    retq2228  %numhighbits = sub i8 32, %numlowbits2229  %sh_prom = zext i8 %numhighbits to i322230  %mask = lshr i32 -1, %sh_prom2231  store i32 %mask, ptr %escape2232  %masked = and i32 %mask, %val2233  ret i32 %masked2234}2235 2236define i32 @bzhi32_c2_load(ptr %w, i32 %numlowbits, ptr %escape) nounwind {2237; X86-NOBMI-LABEL: bzhi32_c2_load:2238; X86-NOBMI:       # %bb.0:2239; X86-NOBMI-NEXT:    pushl %esi2240; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx2241; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax2242; X86-NOBMI-NEXT:    xorl %ecx, %ecx2243; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2244; X86-NOBMI-NEXT:    movl $-1, %esi2245; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2246; X86-NOBMI-NEXT:    shrl %cl, %esi2247; X86-NOBMI-NEXT:    movl (%eax), %eax2248; X86-NOBMI-NEXT:    andl %esi, %eax2249; X86-NOBMI-NEXT:    movl %esi, (%edx)2250; X86-NOBMI-NEXT:    popl %esi2251; X86-NOBMI-NEXT:    retl2252;2253; X86-BMI1-LABEL: bzhi32_c2_load:2254; X86-BMI1:       # %bb.0:2255; X86-BMI1-NEXT:    pushl %esi2256; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx2257; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax2258; X86-BMI1-NEXT:    xorl %ecx, %ecx2259; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2260; X86-BMI1-NEXT:    movl $-1, %esi2261; X86-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2262; X86-BMI1-NEXT:    shrl %cl, %esi2263; X86-BMI1-NEXT:    movl (%eax), %eax2264; X86-BMI1-NEXT:    andl %esi, %eax2265; X86-BMI1-NEXT:    movl %esi, (%edx)2266; X86-BMI1-NEXT:    popl %esi2267; X86-BMI1-NEXT:    retl2268;2269; X86-BMI2-LABEL: bzhi32_c2_load:2270; X86-BMI2:       # %bb.0:2271; X86-BMI2-NEXT:    pushl %esi2272; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2273; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2274; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %edx2275; X86-BMI2-NEXT:    movl $-1, %esi2276; X86-BMI2-NEXT:    bzhil %edx, %esi, %esi2277; X86-BMI2-NEXT:    bzhil %edx, (%eax), %eax2278; X86-BMI2-NEXT:    movl %esi, (%ecx)2279; X86-BMI2-NEXT:    popl %esi2280; X86-BMI2-NEXT:    retl2281;2282; X64-NOBMI-LABEL: bzhi32_c2_load:2283; X64-NOBMI:       # %bb.0:2284; X64-NOBMI-NEXT:    movl %esi, %ecx2285; X64-NOBMI-NEXT:    negb %cl2286; X64-NOBMI-NEXT:    movl $-1, %esi2287; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2288; X64-NOBMI-NEXT:    shrl %cl, %esi2289; X64-NOBMI-NEXT:    movl (%rdi), %eax2290; X64-NOBMI-NEXT:    andl %esi, %eax2291; X64-NOBMI-NEXT:    movl %esi, (%rdx)2292; X64-NOBMI-NEXT:    retq2293;2294; X64-BMI1-LABEL: bzhi32_c2_load:2295; X64-BMI1:       # %bb.0:2296; X64-BMI1-NEXT:    movl %esi, %ecx2297; X64-BMI1-NEXT:    negb %cl2298; X64-BMI1-NEXT:    movl $-1, %esi2299; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2300; X64-BMI1-NEXT:    shrl %cl, %esi2301; X64-BMI1-NEXT:    movl (%rdi), %eax2302; X64-BMI1-NEXT:    andl %esi, %eax2303; X64-BMI1-NEXT:    movl %esi, (%rdx)2304; X64-BMI1-NEXT:    retq2305;2306; X64-BMI2-LABEL: bzhi32_c2_load:2307; X64-BMI2:       # %bb.0:2308; X64-BMI2-NEXT:    movl $-1, %eax2309; X64-BMI2-NEXT:    bzhil %esi, %eax, %ecx2310; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax2311; X64-BMI2-NEXT:    movl %ecx, (%rdx)2312; X64-BMI2-NEXT:    retq2313  %val = load i32, ptr %w2314  %numhighbits = sub i32 32, %numlowbits2315  %mask = lshr i32 -1, %numhighbits2316  store i32 %mask, ptr %escape2317  %masked = and i32 %mask, %val2318  ret i32 %masked2319}2320 2321define i32 @bzhi32_c3_load_indexzext(ptr %w, i8 %numlowbits, ptr %escape) nounwind {2322; X86-NOBMI-LABEL: bzhi32_c3_load_indexzext:2323; X86-NOBMI:       # %bb.0:2324; X86-NOBMI-NEXT:    pushl %esi2325; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx2326; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax2327; X86-NOBMI-NEXT:    xorl %ecx, %ecx2328; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2329; X86-NOBMI-NEXT:    movl $-1, %esi2330; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2331; X86-NOBMI-NEXT:    shrl %cl, %esi2332; X86-NOBMI-NEXT:    movl (%eax), %eax2333; X86-NOBMI-NEXT:    andl %esi, %eax2334; X86-NOBMI-NEXT:    movl %esi, (%edx)2335; X86-NOBMI-NEXT:    popl %esi2336; X86-NOBMI-NEXT:    retl2337;2338; X86-BMI1-LABEL: bzhi32_c3_load_indexzext:2339; X86-BMI1:       # %bb.0:2340; X86-BMI1-NEXT:    pushl %esi2341; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx2342; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax2343; X86-BMI1-NEXT:    xorl %ecx, %ecx2344; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2345; X86-BMI1-NEXT:    movl $-1, %esi2346; X86-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2347; X86-BMI1-NEXT:    shrl %cl, %esi2348; X86-BMI1-NEXT:    movl (%eax), %eax2349; X86-BMI1-NEXT:    andl %esi, %eax2350; X86-BMI1-NEXT:    movl %esi, (%edx)2351; X86-BMI1-NEXT:    popl %esi2352; X86-BMI1-NEXT:    retl2353;2354; X86-BMI2-LABEL: bzhi32_c3_load_indexzext:2355; X86-BMI2:       # %bb.0:2356; X86-BMI2-NEXT:    pushl %esi2357; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2358; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2359; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %edx2360; X86-BMI2-NEXT:    movl $-1, %esi2361; X86-BMI2-NEXT:    bzhil %edx, %esi, %esi2362; X86-BMI2-NEXT:    bzhil %edx, (%eax), %eax2363; X86-BMI2-NEXT:    movl %esi, (%ecx)2364; X86-BMI2-NEXT:    popl %esi2365; X86-BMI2-NEXT:    retl2366;2367; X64-NOBMI-LABEL: bzhi32_c3_load_indexzext:2368; X64-NOBMI:       # %bb.0:2369; X64-NOBMI-NEXT:    movl %esi, %ecx2370; X64-NOBMI-NEXT:    negb %cl2371; X64-NOBMI-NEXT:    movl $-1, %esi2372; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2373; X64-NOBMI-NEXT:    shrl %cl, %esi2374; X64-NOBMI-NEXT:    movl (%rdi), %eax2375; X64-NOBMI-NEXT:    andl %esi, %eax2376; X64-NOBMI-NEXT:    movl %esi, (%rdx)2377; X64-NOBMI-NEXT:    retq2378;2379; X64-BMI1-LABEL: bzhi32_c3_load_indexzext:2380; X64-BMI1:       # %bb.0:2381; X64-BMI1-NEXT:    movl %esi, %ecx2382; X64-BMI1-NEXT:    negb %cl2383; X64-BMI1-NEXT:    movl $-1, %esi2384; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2385; X64-BMI1-NEXT:    shrl %cl, %esi2386; X64-BMI1-NEXT:    movl (%rdi), %eax2387; X64-BMI1-NEXT:    andl %esi, %eax2388; X64-BMI1-NEXT:    movl %esi, (%rdx)2389; X64-BMI1-NEXT:    retq2390;2391; X64-BMI2-LABEL: bzhi32_c3_load_indexzext:2392; X64-BMI2:       # %bb.0:2393; X64-BMI2-NEXT:    movl $-1, %eax2394; X64-BMI2-NEXT:    bzhil %esi, %eax, %ecx2395; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax2396; X64-BMI2-NEXT:    movl %ecx, (%rdx)2397; X64-BMI2-NEXT:    retq2398  %val = load i32, ptr %w2399  %numhighbits = sub i8 32, %numlowbits2400  %sh_prom = zext i8 %numhighbits to i322401  %mask = lshr i32 -1, %sh_prom2402  store i32 %mask, ptr %escape2403  %masked = and i32 %mask, %val2404  ret i32 %masked2405}2406 2407define i32 @bzhi32_c4_commutative(i32 %val, i32 %numlowbits, ptr %escape) nounwind {2408; X86-NOBMI-LABEL: bzhi32_c4_commutative:2409; X86-NOBMI:       # %bb.0:2410; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx2411; X86-NOBMI-NEXT:    xorl %ecx, %ecx2412; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2413; X86-NOBMI-NEXT:    movl $-1, %eax2414; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2415; X86-NOBMI-NEXT:    shrl %cl, %eax2416; X86-NOBMI-NEXT:    movl %eax, (%edx)2417; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2418; X86-NOBMI-NEXT:    retl2419;2420; X86-BMI1-LABEL: bzhi32_c4_commutative:2421; X86-BMI1:       # %bb.0:2422; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx2423; X86-BMI1-NEXT:    xorl %ecx, %ecx2424; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2425; X86-BMI1-NEXT:    movl $-1, %eax2426; X86-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2427; X86-BMI1-NEXT:    shrl %cl, %eax2428; X86-BMI1-NEXT:    movl %eax, (%edx)2429; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax2430; X86-BMI1-NEXT:    retl2431;2432; X86-BMI2-LABEL: bzhi32_c4_commutative:2433; X86-BMI2:       # %bb.0:2434; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2435; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx2436; X86-BMI2-NEXT:    movl $-1, %edx2437; X86-BMI2-NEXT:    bzhil %ecx, %edx, %edx2438; X86-BMI2-NEXT:    movl %edx, (%eax)2439; X86-BMI2-NEXT:    bzhil %ecx, {{[0-9]+}}(%esp), %eax2440; X86-BMI2-NEXT:    retl2441;2442; X64-NOBMI-LABEL: bzhi32_c4_commutative:2443; X64-NOBMI:       # %bb.0:2444; X64-NOBMI-NEXT:    movl %esi, %ecx2445; X64-NOBMI-NEXT:    negb %cl2446; X64-NOBMI-NEXT:    movl $-1, %eax2447; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2448; X64-NOBMI-NEXT:    shrl %cl, %eax2449; X64-NOBMI-NEXT:    movl %eax, (%rdx)2450; X64-NOBMI-NEXT:    andl %edi, %eax2451; X64-NOBMI-NEXT:    retq2452;2453; X64-BMI1-LABEL: bzhi32_c4_commutative:2454; X64-BMI1:       # %bb.0:2455; X64-BMI1-NEXT:    movl %esi, %ecx2456; X64-BMI1-NEXT:    negb %cl2457; X64-BMI1-NEXT:    movl $-1, %eax2458; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2459; X64-BMI1-NEXT:    shrl %cl, %eax2460; X64-BMI1-NEXT:    movl %eax, (%rdx)2461; X64-BMI1-NEXT:    andl %edi, %eax2462; X64-BMI1-NEXT:    retq2463;2464; X64-BMI2-LABEL: bzhi32_c4_commutative:2465; X64-BMI2:       # %bb.0:2466; X64-BMI2-NEXT:    movl $-1, %eax2467; X64-BMI2-NEXT:    bzhil %esi, %eax, %eax2468; X64-BMI2-NEXT:    movl %eax, (%rdx)2469; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax2470; X64-BMI2-NEXT:    retq2471  %numhighbits = sub i32 32, %numlowbits2472  %mask = lshr i32 -1, %numhighbits2473  store i32 %mask, ptr %escape2474  %masked = and i32 %val, %mask ; swapped order2475  ret i32 %masked2476}2477 2478; 64-bit2479 2480define i64 @bzhi64_c0(i64 %val, i64 %numlowbits, ptr %escape) nounwind {2481; X86-NOBMI-LABEL: bzhi64_c0:2482; X86-NOBMI:       # %bb.0:2483; X86-NOBMI-NEXT:    pushl %esi2484; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi2485; X86-NOBMI-NEXT:    movb $64, %cl2486; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2487; X86-NOBMI-NEXT:    movl $-1, %eax2488; X86-NOBMI-NEXT:    movl $-1, %edx2489; X86-NOBMI-NEXT:    shrl %cl, %edx2490; X86-NOBMI-NEXT:    testb $32, %cl2491; X86-NOBMI-NEXT:    je .LBB35_22492; X86-NOBMI-NEXT:  # %bb.1:2493; X86-NOBMI-NEXT:    movl %edx, %eax2494; X86-NOBMI-NEXT:    xorl %edx, %edx2495; X86-NOBMI-NEXT:  .LBB35_2:2496; X86-NOBMI-NEXT:    movl %edx, 4(%esi)2497; X86-NOBMI-NEXT:    movl %eax, (%esi)2498; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2499; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx2500; X86-NOBMI-NEXT:    popl %esi2501; X86-NOBMI-NEXT:    retl2502;2503; X86-BMI1-LABEL: bzhi64_c0:2504; X86-BMI1:       # %bb.0:2505; X86-BMI1-NEXT:    pushl %esi2506; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi2507; X86-BMI1-NEXT:    movb $64, %cl2508; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2509; X86-BMI1-NEXT:    movl $-1, %eax2510; X86-BMI1-NEXT:    movl $-1, %edx2511; X86-BMI1-NEXT:    shrl %cl, %edx2512; X86-BMI1-NEXT:    testb $32, %cl2513; X86-BMI1-NEXT:    je .LBB35_22514; X86-BMI1-NEXT:  # %bb.1:2515; X86-BMI1-NEXT:    movl %edx, %eax2516; X86-BMI1-NEXT:    xorl %edx, %edx2517; X86-BMI1-NEXT:  .LBB35_2:2518; X86-BMI1-NEXT:    movl %edx, 4(%esi)2519; X86-BMI1-NEXT:    movl %eax, (%esi)2520; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax2521; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx2522; X86-BMI1-NEXT:    popl %esi2523; X86-BMI1-NEXT:    retl2524;2525; X86-BMI2-LABEL: bzhi64_c0:2526; X86-BMI2:       # %bb.0:2527; X86-BMI2-NEXT:    pushl %ebx2528; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2529; X86-BMI2-NEXT:    movb $64, %bl2530; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %bl2531; X86-BMI2-NEXT:    movl $-1, %eax2532; X86-BMI2-NEXT:    shrxl %ebx, %eax, %edx2533; X86-BMI2-NEXT:    testb $32, %bl2534; X86-BMI2-NEXT:    je .LBB35_22535; X86-BMI2-NEXT:  # %bb.1:2536; X86-BMI2-NEXT:    movl %edx, %eax2537; X86-BMI2-NEXT:    xorl %edx, %edx2538; X86-BMI2-NEXT:  .LBB35_2:2539; X86-BMI2-NEXT:    movl %edx, 4(%ecx)2540; X86-BMI2-NEXT:    movl %eax, (%ecx)2541; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax2542; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx2543; X86-BMI2-NEXT:    popl %ebx2544; X86-BMI2-NEXT:    retl2545;2546; X64-NOBMI-LABEL: bzhi64_c0:2547; X64-NOBMI:       # %bb.0:2548; X64-NOBMI-NEXT:    movq %rsi, %rcx2549; X64-NOBMI-NEXT:    negb %cl2550; X64-NOBMI-NEXT:    movq $-1, %rax2551; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx2552; X64-NOBMI-NEXT:    shrq %cl, %rax2553; X64-NOBMI-NEXT:    movq %rax, (%rdx)2554; X64-NOBMI-NEXT:    andq %rdi, %rax2555; X64-NOBMI-NEXT:    retq2556;2557; X64-BMI1-LABEL: bzhi64_c0:2558; X64-BMI1:       # %bb.0:2559; X64-BMI1-NEXT:    movq %rsi, %rcx2560; X64-BMI1-NEXT:    negb %cl2561; X64-BMI1-NEXT:    movq $-1, %rax2562; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $rcx2563; X64-BMI1-NEXT:    shrq %cl, %rax2564; X64-BMI1-NEXT:    movq %rax, (%rdx)2565; X64-BMI1-NEXT:    andq %rdi, %rax2566; X64-BMI1-NEXT:    retq2567;2568; X64-BMI2-LABEL: bzhi64_c0:2569; X64-BMI2:       # %bb.0:2570; X64-BMI2-NEXT:    movq $-1, %rax2571; X64-BMI2-NEXT:    bzhiq %rsi, %rax, %rax2572; X64-BMI2-NEXT:    movq %rax, (%rdx)2573; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax2574; X64-BMI2-NEXT:    retq2575  %numhighbits = sub i64 64, %numlowbits2576  %mask = lshr i64 -1, %numhighbits2577  store i64 %mask, ptr %escape2578  %masked = and i64 %mask, %val2579  ret i64 %masked2580}2581 2582define i64 @bzhi64_c1_indexzext(i64 %val, i8 %numlowbits, ptr %escape) nounwind {2583; X86-NOBMI-LABEL: bzhi64_c1_indexzext:2584; X86-NOBMI:       # %bb.0:2585; X86-NOBMI-NEXT:    pushl %esi2586; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi2587; X86-NOBMI-NEXT:    movb $64, %cl2588; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2589; X86-NOBMI-NEXT:    movl $-1, %eax2590; X86-NOBMI-NEXT:    movl $-1, %edx2591; X86-NOBMI-NEXT:    shrl %cl, %edx2592; X86-NOBMI-NEXT:    testb $32, %cl2593; X86-NOBMI-NEXT:    je .LBB36_22594; X86-NOBMI-NEXT:  # %bb.1:2595; X86-NOBMI-NEXT:    movl %edx, %eax2596; X86-NOBMI-NEXT:    xorl %edx, %edx2597; X86-NOBMI-NEXT:  .LBB36_2:2598; X86-NOBMI-NEXT:    movl %edx, 4(%esi)2599; X86-NOBMI-NEXT:    movl %eax, (%esi)2600; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2601; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx2602; X86-NOBMI-NEXT:    popl %esi2603; X86-NOBMI-NEXT:    retl2604;2605; X86-BMI1-LABEL: bzhi64_c1_indexzext:2606; X86-BMI1:       # %bb.0:2607; X86-BMI1-NEXT:    pushl %esi2608; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi2609; X86-BMI1-NEXT:    movb $64, %cl2610; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2611; X86-BMI1-NEXT:    movl $-1, %eax2612; X86-BMI1-NEXT:    movl $-1, %edx2613; X86-BMI1-NEXT:    shrl %cl, %edx2614; X86-BMI1-NEXT:    testb $32, %cl2615; X86-BMI1-NEXT:    je .LBB36_22616; X86-BMI1-NEXT:  # %bb.1:2617; X86-BMI1-NEXT:    movl %edx, %eax2618; X86-BMI1-NEXT:    xorl %edx, %edx2619; X86-BMI1-NEXT:  .LBB36_2:2620; X86-BMI1-NEXT:    movl %edx, 4(%esi)2621; X86-BMI1-NEXT:    movl %eax, (%esi)2622; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax2623; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx2624; X86-BMI1-NEXT:    popl %esi2625; X86-BMI1-NEXT:    retl2626;2627; X86-BMI2-LABEL: bzhi64_c1_indexzext:2628; X86-BMI2:       # %bb.0:2629; X86-BMI2-NEXT:    pushl %ebx2630; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2631; X86-BMI2-NEXT:    movb $64, %bl2632; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %bl2633; X86-BMI2-NEXT:    movl $-1, %eax2634; X86-BMI2-NEXT:    shrxl %ebx, %eax, %edx2635; X86-BMI2-NEXT:    testb $32, %bl2636; X86-BMI2-NEXT:    je .LBB36_22637; X86-BMI2-NEXT:  # %bb.1:2638; X86-BMI2-NEXT:    movl %edx, %eax2639; X86-BMI2-NEXT:    xorl %edx, %edx2640; X86-BMI2-NEXT:  .LBB36_2:2641; X86-BMI2-NEXT:    movl %edx, 4(%ecx)2642; X86-BMI2-NEXT:    movl %eax, (%ecx)2643; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax2644; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx2645; X86-BMI2-NEXT:    popl %ebx2646; X86-BMI2-NEXT:    retl2647;2648; X64-NOBMI-LABEL: bzhi64_c1_indexzext:2649; X64-NOBMI:       # %bb.0:2650; X64-NOBMI-NEXT:    movl %esi, %ecx2651; X64-NOBMI-NEXT:    negb %cl2652; X64-NOBMI-NEXT:    movq $-1, %rax2653; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2654; X64-NOBMI-NEXT:    shrq %cl, %rax2655; X64-NOBMI-NEXT:    movq %rax, (%rdx)2656; X64-NOBMI-NEXT:    andq %rdi, %rax2657; X64-NOBMI-NEXT:    retq2658;2659; X64-BMI1-LABEL: bzhi64_c1_indexzext:2660; X64-BMI1:       # %bb.0:2661; X64-BMI1-NEXT:    movl %esi, %ecx2662; X64-BMI1-NEXT:    negb %cl2663; X64-BMI1-NEXT:    movq $-1, %rax2664; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2665; X64-BMI1-NEXT:    shrq %cl, %rax2666; X64-BMI1-NEXT:    movq %rax, (%rdx)2667; X64-BMI1-NEXT:    andq %rdi, %rax2668; X64-BMI1-NEXT:    retq2669;2670; X64-BMI2-LABEL: bzhi64_c1_indexzext:2671; X64-BMI2:       # %bb.0:2672; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi2673; X64-BMI2-NEXT:    movq $-1, %rax2674; X64-BMI2-NEXT:    bzhiq %rsi, %rax, %rax2675; X64-BMI2-NEXT:    movq %rax, (%rdx)2676; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax2677; X64-BMI2-NEXT:    retq2678  %numhighbits = sub i8 64, %numlowbits2679  %sh_prom = zext i8 %numhighbits to i642680  %mask = lshr i64 -1, %sh_prom2681  store i64 %mask, ptr %escape2682  %masked = and i64 %mask, %val2683  ret i64 %masked2684}2685 2686define i64 @bzhi64_c2_load(ptr %w, i64 %numlowbits, ptr %escape) nounwind {2687; X86-NOBMI-LABEL: bzhi64_c2_load:2688; X86-NOBMI:       # %bb.0:2689; X86-NOBMI-NEXT:    pushl %ebx2690; X86-NOBMI-NEXT:    pushl %edi2691; X86-NOBMI-NEXT:    pushl %esi2692; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi2693; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax2694; X86-NOBMI-NEXT:    movb $64, %cl2695; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2696; X86-NOBMI-NEXT:    movl $-1, %edi2697; X86-NOBMI-NEXT:    movl $-1, %ebx2698; X86-NOBMI-NEXT:    shrl %cl, %ebx2699; X86-NOBMI-NEXT:    testb $32, %cl2700; X86-NOBMI-NEXT:    je .LBB37_22701; X86-NOBMI-NEXT:  # %bb.1:2702; X86-NOBMI-NEXT:    movl %ebx, %edi2703; X86-NOBMI-NEXT:    xorl %ebx, %ebx2704; X86-NOBMI-NEXT:  .LBB37_2:2705; X86-NOBMI-NEXT:    movl 4(%eax), %edx2706; X86-NOBMI-NEXT:    andl %ebx, %edx2707; X86-NOBMI-NEXT:    movl (%eax), %eax2708; X86-NOBMI-NEXT:    andl %edi, %eax2709; X86-NOBMI-NEXT:    movl %ebx, 4(%esi)2710; X86-NOBMI-NEXT:    movl %edi, (%esi)2711; X86-NOBMI-NEXT:    popl %esi2712; X86-NOBMI-NEXT:    popl %edi2713; X86-NOBMI-NEXT:    popl %ebx2714; X86-NOBMI-NEXT:    retl2715;2716; X86-BMI1-LABEL: bzhi64_c2_load:2717; X86-BMI1:       # %bb.0:2718; X86-BMI1-NEXT:    pushl %ebx2719; X86-BMI1-NEXT:    pushl %edi2720; X86-BMI1-NEXT:    pushl %esi2721; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi2722; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax2723; X86-BMI1-NEXT:    movb $64, %cl2724; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2725; X86-BMI1-NEXT:    movl $-1, %edi2726; X86-BMI1-NEXT:    movl $-1, %ebx2727; X86-BMI1-NEXT:    shrl %cl, %ebx2728; X86-BMI1-NEXT:    testb $32, %cl2729; X86-BMI1-NEXT:    je .LBB37_22730; X86-BMI1-NEXT:  # %bb.1:2731; X86-BMI1-NEXT:    movl %ebx, %edi2732; X86-BMI1-NEXT:    xorl %ebx, %ebx2733; X86-BMI1-NEXT:  .LBB37_2:2734; X86-BMI1-NEXT:    movl 4(%eax), %edx2735; X86-BMI1-NEXT:    andl %ebx, %edx2736; X86-BMI1-NEXT:    movl (%eax), %eax2737; X86-BMI1-NEXT:    andl %edi, %eax2738; X86-BMI1-NEXT:    movl %ebx, 4(%esi)2739; X86-BMI1-NEXT:    movl %edi, (%esi)2740; X86-BMI1-NEXT:    popl %esi2741; X86-BMI1-NEXT:    popl %edi2742; X86-BMI1-NEXT:    popl %ebx2743; X86-BMI1-NEXT:    retl2744;2745; X86-BMI2-LABEL: bzhi64_c2_load:2746; X86-BMI2:       # %bb.0:2747; X86-BMI2-NEXT:    pushl %edi2748; X86-BMI2-NEXT:    pushl %esi2749; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2750; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2751; X86-BMI2-NEXT:    movb $64, %dl2752; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %dl2753; X86-BMI2-NEXT:    movl $-1, %esi2754; X86-BMI2-NEXT:    shrxl %edx, %esi, %edi2755; X86-BMI2-NEXT:    testb $32, %dl2756; X86-BMI2-NEXT:    je .LBB37_22757; X86-BMI2-NEXT:  # %bb.1:2758; X86-BMI2-NEXT:    movl %edi, %esi2759; X86-BMI2-NEXT:    xorl %edi, %edi2760; X86-BMI2-NEXT:  .LBB37_2:2761; X86-BMI2-NEXT:    movl 4(%eax), %edx2762; X86-BMI2-NEXT:    andl %edi, %edx2763; X86-BMI2-NEXT:    movl (%eax), %eax2764; X86-BMI2-NEXT:    andl %esi, %eax2765; X86-BMI2-NEXT:    movl %edi, 4(%ecx)2766; X86-BMI2-NEXT:    movl %esi, (%ecx)2767; X86-BMI2-NEXT:    popl %esi2768; X86-BMI2-NEXT:    popl %edi2769; X86-BMI2-NEXT:    retl2770;2771; X64-NOBMI-LABEL: bzhi64_c2_load:2772; X64-NOBMI:       # %bb.0:2773; X64-NOBMI-NEXT:    movq %rsi, %rcx2774; X64-NOBMI-NEXT:    negb %cl2775; X64-NOBMI-NEXT:    movq $-1, %rsi2776; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx2777; X64-NOBMI-NEXT:    shrq %cl, %rsi2778; X64-NOBMI-NEXT:    movq (%rdi), %rax2779; X64-NOBMI-NEXT:    andq %rsi, %rax2780; X64-NOBMI-NEXT:    movq %rsi, (%rdx)2781; X64-NOBMI-NEXT:    retq2782;2783; X64-BMI1-LABEL: bzhi64_c2_load:2784; X64-BMI1:       # %bb.0:2785; X64-BMI1-NEXT:    movq %rsi, %rcx2786; X64-BMI1-NEXT:    negb %cl2787; X64-BMI1-NEXT:    movq $-1, %rsi2788; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $rcx2789; X64-BMI1-NEXT:    shrq %cl, %rsi2790; X64-BMI1-NEXT:    movq (%rdi), %rax2791; X64-BMI1-NEXT:    andq %rsi, %rax2792; X64-BMI1-NEXT:    movq %rsi, (%rdx)2793; X64-BMI1-NEXT:    retq2794;2795; X64-BMI2-LABEL: bzhi64_c2_load:2796; X64-BMI2:       # %bb.0:2797; X64-BMI2-NEXT:    movq $-1, %rax2798; X64-BMI2-NEXT:    bzhiq %rsi, %rax, %rcx2799; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax2800; X64-BMI2-NEXT:    movq %rcx, (%rdx)2801; X64-BMI2-NEXT:    retq2802  %val = load i64, ptr %w2803  %numhighbits = sub i64 64, %numlowbits2804  %mask = lshr i64 -1, %numhighbits2805  store i64 %mask, ptr %escape2806  %masked = and i64 %mask, %val2807  ret i64 %masked2808}2809 2810define i64 @bzhi64_c3_load_indexzext(ptr %w, i8 %numlowbits, ptr %escape) nounwind {2811; X86-NOBMI-LABEL: bzhi64_c3_load_indexzext:2812; X86-NOBMI:       # %bb.0:2813; X86-NOBMI-NEXT:    pushl %ebx2814; X86-NOBMI-NEXT:    pushl %edi2815; X86-NOBMI-NEXT:    pushl %esi2816; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi2817; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax2818; X86-NOBMI-NEXT:    movb $64, %cl2819; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2820; X86-NOBMI-NEXT:    movl $-1, %edi2821; X86-NOBMI-NEXT:    movl $-1, %ebx2822; X86-NOBMI-NEXT:    shrl %cl, %ebx2823; X86-NOBMI-NEXT:    testb $32, %cl2824; X86-NOBMI-NEXT:    je .LBB38_22825; X86-NOBMI-NEXT:  # %bb.1:2826; X86-NOBMI-NEXT:    movl %ebx, %edi2827; X86-NOBMI-NEXT:    xorl %ebx, %ebx2828; X86-NOBMI-NEXT:  .LBB38_2:2829; X86-NOBMI-NEXT:    movl 4(%eax), %edx2830; X86-NOBMI-NEXT:    andl %ebx, %edx2831; X86-NOBMI-NEXT:    movl (%eax), %eax2832; X86-NOBMI-NEXT:    andl %edi, %eax2833; X86-NOBMI-NEXT:    movl %ebx, 4(%esi)2834; X86-NOBMI-NEXT:    movl %edi, (%esi)2835; X86-NOBMI-NEXT:    popl %esi2836; X86-NOBMI-NEXT:    popl %edi2837; X86-NOBMI-NEXT:    popl %ebx2838; X86-NOBMI-NEXT:    retl2839;2840; X86-BMI1-LABEL: bzhi64_c3_load_indexzext:2841; X86-BMI1:       # %bb.0:2842; X86-BMI1-NEXT:    pushl %ebx2843; X86-BMI1-NEXT:    pushl %edi2844; X86-BMI1-NEXT:    pushl %esi2845; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi2846; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax2847; X86-BMI1-NEXT:    movb $64, %cl2848; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2849; X86-BMI1-NEXT:    movl $-1, %edi2850; X86-BMI1-NEXT:    movl $-1, %ebx2851; X86-BMI1-NEXT:    shrl %cl, %ebx2852; X86-BMI1-NEXT:    testb $32, %cl2853; X86-BMI1-NEXT:    je .LBB38_22854; X86-BMI1-NEXT:  # %bb.1:2855; X86-BMI1-NEXT:    movl %ebx, %edi2856; X86-BMI1-NEXT:    xorl %ebx, %ebx2857; X86-BMI1-NEXT:  .LBB38_2:2858; X86-BMI1-NEXT:    movl 4(%eax), %edx2859; X86-BMI1-NEXT:    andl %ebx, %edx2860; X86-BMI1-NEXT:    movl (%eax), %eax2861; X86-BMI1-NEXT:    andl %edi, %eax2862; X86-BMI1-NEXT:    movl %ebx, 4(%esi)2863; X86-BMI1-NEXT:    movl %edi, (%esi)2864; X86-BMI1-NEXT:    popl %esi2865; X86-BMI1-NEXT:    popl %edi2866; X86-BMI1-NEXT:    popl %ebx2867; X86-BMI1-NEXT:    retl2868;2869; X86-BMI2-LABEL: bzhi64_c3_load_indexzext:2870; X86-BMI2:       # %bb.0:2871; X86-BMI2-NEXT:    pushl %edi2872; X86-BMI2-NEXT:    pushl %esi2873; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2874; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax2875; X86-BMI2-NEXT:    movb $64, %dl2876; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %dl2877; X86-BMI2-NEXT:    movl $-1, %esi2878; X86-BMI2-NEXT:    shrxl %edx, %esi, %edi2879; X86-BMI2-NEXT:    testb $32, %dl2880; X86-BMI2-NEXT:    je .LBB38_22881; X86-BMI2-NEXT:  # %bb.1:2882; X86-BMI2-NEXT:    movl %edi, %esi2883; X86-BMI2-NEXT:    xorl %edi, %edi2884; X86-BMI2-NEXT:  .LBB38_2:2885; X86-BMI2-NEXT:    movl 4(%eax), %edx2886; X86-BMI2-NEXT:    andl %edi, %edx2887; X86-BMI2-NEXT:    movl (%eax), %eax2888; X86-BMI2-NEXT:    andl %esi, %eax2889; X86-BMI2-NEXT:    movl %edi, 4(%ecx)2890; X86-BMI2-NEXT:    movl %esi, (%ecx)2891; X86-BMI2-NEXT:    popl %esi2892; X86-BMI2-NEXT:    popl %edi2893; X86-BMI2-NEXT:    retl2894;2895; X64-NOBMI-LABEL: bzhi64_c3_load_indexzext:2896; X64-NOBMI:       # %bb.0:2897; X64-NOBMI-NEXT:    movl %esi, %ecx2898; X64-NOBMI-NEXT:    negb %cl2899; X64-NOBMI-NEXT:    movq $-1, %rsi2900; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx2901; X64-NOBMI-NEXT:    shrq %cl, %rsi2902; X64-NOBMI-NEXT:    movq (%rdi), %rax2903; X64-NOBMI-NEXT:    andq %rsi, %rax2904; X64-NOBMI-NEXT:    movq %rsi, (%rdx)2905; X64-NOBMI-NEXT:    retq2906;2907; X64-BMI1-LABEL: bzhi64_c3_load_indexzext:2908; X64-BMI1:       # %bb.0:2909; X64-BMI1-NEXT:    movl %esi, %ecx2910; X64-BMI1-NEXT:    negb %cl2911; X64-BMI1-NEXT:    movq $-1, %rsi2912; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $ecx2913; X64-BMI1-NEXT:    shrq %cl, %rsi2914; X64-BMI1-NEXT:    movq (%rdi), %rax2915; X64-BMI1-NEXT:    andq %rsi, %rax2916; X64-BMI1-NEXT:    movq %rsi, (%rdx)2917; X64-BMI1-NEXT:    retq2918;2919; X64-BMI2-LABEL: bzhi64_c3_load_indexzext:2920; X64-BMI2:       # %bb.0:2921; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi2922; X64-BMI2-NEXT:    movq $-1, %rax2923; X64-BMI2-NEXT:    bzhiq %rsi, %rax, %rcx2924; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax2925; X64-BMI2-NEXT:    movq %rcx, (%rdx)2926; X64-BMI2-NEXT:    retq2927  %val = load i64, ptr %w2928  %numhighbits = sub i8 64, %numlowbits2929  %sh_prom = zext i8 %numhighbits to i642930  %mask = lshr i64 -1, %sh_prom2931  store i64 %mask, ptr %escape2932  %masked = and i64 %mask, %val2933  ret i64 %masked2934}2935 2936define i64 @bzhi64_c4_commutative(i64 %val, i64 %numlowbits, ptr %escape) nounwind {2937; X86-NOBMI-LABEL: bzhi64_c4_commutative:2938; X86-NOBMI:       # %bb.0:2939; X86-NOBMI-NEXT:    pushl %esi2940; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi2941; X86-NOBMI-NEXT:    movb $64, %cl2942; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl2943; X86-NOBMI-NEXT:    movl $-1, %eax2944; X86-NOBMI-NEXT:    movl $-1, %edx2945; X86-NOBMI-NEXT:    shrl %cl, %edx2946; X86-NOBMI-NEXT:    testb $32, %cl2947; X86-NOBMI-NEXT:    je .LBB39_22948; X86-NOBMI-NEXT:  # %bb.1:2949; X86-NOBMI-NEXT:    movl %edx, %eax2950; X86-NOBMI-NEXT:    xorl %edx, %edx2951; X86-NOBMI-NEXT:  .LBB39_2:2952; X86-NOBMI-NEXT:    movl %edx, 4(%esi)2953; X86-NOBMI-NEXT:    movl %eax, (%esi)2954; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax2955; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %edx2956; X86-NOBMI-NEXT:    popl %esi2957; X86-NOBMI-NEXT:    retl2958;2959; X86-BMI1-LABEL: bzhi64_c4_commutative:2960; X86-BMI1:       # %bb.0:2961; X86-BMI1-NEXT:    pushl %esi2962; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi2963; X86-BMI1-NEXT:    movb $64, %cl2964; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl2965; X86-BMI1-NEXT:    movl $-1, %eax2966; X86-BMI1-NEXT:    movl $-1, %edx2967; X86-BMI1-NEXT:    shrl %cl, %edx2968; X86-BMI1-NEXT:    testb $32, %cl2969; X86-BMI1-NEXT:    je .LBB39_22970; X86-BMI1-NEXT:  # %bb.1:2971; X86-BMI1-NEXT:    movl %edx, %eax2972; X86-BMI1-NEXT:    xorl %edx, %edx2973; X86-BMI1-NEXT:  .LBB39_2:2974; X86-BMI1-NEXT:    movl %edx, 4(%esi)2975; X86-BMI1-NEXT:    movl %eax, (%esi)2976; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax2977; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %edx2978; X86-BMI1-NEXT:    popl %esi2979; X86-BMI1-NEXT:    retl2980;2981; X86-BMI2-LABEL: bzhi64_c4_commutative:2982; X86-BMI2:       # %bb.0:2983; X86-BMI2-NEXT:    pushl %ebx2984; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %ecx2985; X86-BMI2-NEXT:    movb $64, %bl2986; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %bl2987; X86-BMI2-NEXT:    movl $-1, %eax2988; X86-BMI2-NEXT:    shrxl %ebx, %eax, %edx2989; X86-BMI2-NEXT:    testb $32, %bl2990; X86-BMI2-NEXT:    je .LBB39_22991; X86-BMI2-NEXT:  # %bb.1:2992; X86-BMI2-NEXT:    movl %edx, %eax2993; X86-BMI2-NEXT:    xorl %edx, %edx2994; X86-BMI2-NEXT:  .LBB39_2:2995; X86-BMI2-NEXT:    movl %edx, 4(%ecx)2996; X86-BMI2-NEXT:    movl %eax, (%ecx)2997; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax2998; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %edx2999; X86-BMI2-NEXT:    popl %ebx3000; X86-BMI2-NEXT:    retl3001;3002; X64-NOBMI-LABEL: bzhi64_c4_commutative:3003; X64-NOBMI:       # %bb.0:3004; X64-NOBMI-NEXT:    movq %rsi, %rcx3005; X64-NOBMI-NEXT:    negb %cl3006; X64-NOBMI-NEXT:    movq $-1, %rax3007; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx3008; X64-NOBMI-NEXT:    shrq %cl, %rax3009; X64-NOBMI-NEXT:    movq %rax, (%rdx)3010; X64-NOBMI-NEXT:    andq %rdi, %rax3011; X64-NOBMI-NEXT:    retq3012;3013; X64-BMI1-LABEL: bzhi64_c4_commutative:3014; X64-BMI1:       # %bb.0:3015; X64-BMI1-NEXT:    movq %rsi, %rcx3016; X64-BMI1-NEXT:    negb %cl3017; X64-BMI1-NEXT:    movq $-1, %rax3018; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $rcx3019; X64-BMI1-NEXT:    shrq %cl, %rax3020; X64-BMI1-NEXT:    movq %rax, (%rdx)3021; X64-BMI1-NEXT:    andq %rdi, %rax3022; X64-BMI1-NEXT:    retq3023;3024; X64-BMI2-LABEL: bzhi64_c4_commutative:3025; X64-BMI2:       # %bb.0:3026; X64-BMI2-NEXT:    movq $-1, %rax3027; X64-BMI2-NEXT:    bzhiq %rsi, %rax, %rax3028; X64-BMI2-NEXT:    movq %rax, (%rdx)3029; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax3030; X64-BMI2-NEXT:    retq3031  %numhighbits = sub i64 64, %numlowbits3032  %mask = lshr i64 -1, %numhighbits3033  store i64 %mask, ptr %escape3034  %masked = and i64 %val, %mask ; swapped order3035  ret i64 %masked3036}3037 3038; 64-bit, but with 32-bit output3039 3040; Everything done in 64-bit, truncation happens last.3041define i32 @bzhi64_32_c0(i64 %val, i64 %numlowbits) nounwind {3042; X86-NOBMI-LABEL: bzhi64_32_c0:3043; X86-NOBMI:       # %bb.0:3044; X86-NOBMI-NEXT:    movb $64, %cl3045; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3046; X86-NOBMI-NEXT:    movl $-1, %eax3047; X86-NOBMI-NEXT:    shrl %cl, %eax3048; X86-NOBMI-NEXT:    testb $32, %cl3049; X86-NOBMI-NEXT:    jne .LBB40_23050; X86-NOBMI-NEXT:  # %bb.1:3051; X86-NOBMI-NEXT:    movl $-1, %eax3052; X86-NOBMI-NEXT:  .LBB40_2:3053; X86-NOBMI-NEXT:    andl {{[0-9]+}}(%esp), %eax3054; X86-NOBMI-NEXT:    retl3055;3056; X86-BMI1-LABEL: bzhi64_32_c0:3057; X86-BMI1:       # %bb.0:3058; X86-BMI1-NEXT:    movb $64, %cl3059; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl3060; X86-BMI1-NEXT:    movl $-1, %eax3061; X86-BMI1-NEXT:    shrl %cl, %eax3062; X86-BMI1-NEXT:    testb $32, %cl3063; X86-BMI1-NEXT:    jne .LBB40_23064; X86-BMI1-NEXT:  # %bb.1:3065; X86-BMI1-NEXT:    movl $-1, %eax3066; X86-BMI1-NEXT:  .LBB40_2:3067; X86-BMI1-NEXT:    andl {{[0-9]+}}(%esp), %eax3068; X86-BMI1-NEXT:    retl3069;3070; X86-BMI2-LABEL: bzhi64_32_c0:3071; X86-BMI2:       # %bb.0:3072; X86-BMI2-NEXT:    movb $64, %cl3073; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %cl3074; X86-BMI2-NEXT:    movl $-1, %eax3075; X86-BMI2-NEXT:    testb $32, %cl3076; X86-BMI2-NEXT:    je .LBB40_23077; X86-BMI2-NEXT:  # %bb.1:3078; X86-BMI2-NEXT:    shrxl %ecx, %eax, %eax3079; X86-BMI2-NEXT:  .LBB40_2:3080; X86-BMI2-NEXT:    andl {{[0-9]+}}(%esp), %eax3081; X86-BMI2-NEXT:    retl3082;3083; X64-NOBMI-LABEL: bzhi64_32_c0:3084; X64-NOBMI:       # %bb.0:3085; X64-NOBMI-NEXT:    movq %rsi, %rcx3086; X64-NOBMI-NEXT:    negb %cl3087; X64-NOBMI-NEXT:    movq $-1, %rax3088; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx3089; X64-NOBMI-NEXT:    shrq %cl, %rax3090; X64-NOBMI-NEXT:    andl %edi, %eax3091; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax3092; X64-NOBMI-NEXT:    retq3093;3094; X64-BMI1-LABEL: bzhi64_32_c0:3095; X64-BMI1:       # %bb.0:3096; X64-BMI1-NEXT:    shll $8, %esi3097; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax3098; X64-BMI1-NEXT:    retq3099;3100; X64-BMI2-LABEL: bzhi64_32_c0:3101; X64-BMI2:       # %bb.0:3102; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax3103; X64-BMI2-NEXT:    retq3104  %numhighbits = sub i64 64, %numlowbits3105  %mask = lshr i64 -1, %numhighbits3106  %masked = and i64 %mask, %val3107  %res = trunc i64 %masked to i323108  ret i32 %res3109}3110 3111; Shifting happens in 64-bit, then truncation. Masking is 32-bit.3112define i32 @bzhi64_32_c1(i64 %val, i32 %numlowbits) nounwind {3113; X86-NOBMI-LABEL: bzhi64_32_c1:3114; X86-NOBMI:       # %bb.0:3115; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3116; X86-NOBMI-NEXT:    xorl %ecx, %ecx3117; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3118; X86-NOBMI-NEXT:    shll %cl, %eax3119; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3120; X86-NOBMI-NEXT:    shrl %cl, %eax3121; X86-NOBMI-NEXT:    retl3122;3123; X86-BMI1-LABEL: bzhi64_32_c1:3124; X86-BMI1:       # %bb.0:3125; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3126; X86-BMI1-NEXT:    shll $8, %eax3127; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax3128; X86-BMI1-NEXT:    retl3129;3130; X86-BMI2-LABEL: bzhi64_32_c1:3131; X86-BMI2:       # %bb.0:3132; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3133; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax3134; X86-BMI2-NEXT:    retl3135;3136; X64-NOBMI-LABEL: bzhi64_32_c1:3137; X64-NOBMI:       # %bb.0:3138; X64-NOBMI-NEXT:    movl %esi, %ecx3139; X64-NOBMI-NEXT:    movq %rdi, %rax3140; X64-NOBMI-NEXT:    negb %cl3141; X64-NOBMI-NEXT:    shll %cl, %eax3142; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3143; X64-NOBMI-NEXT:    shrl %cl, %eax3144; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax3145; X64-NOBMI-NEXT:    retq3146;3147; X64-BMI1-LABEL: bzhi64_32_c1:3148; X64-BMI1:       # %bb.0:3149; X64-BMI1-NEXT:    shll $8, %esi3150; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax3151; X64-BMI1-NEXT:    retq3152;3153; X64-BMI2-LABEL: bzhi64_32_c1:3154; X64-BMI2:       # %bb.0:3155; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax3156; X64-BMI2-NEXT:    retq3157  %truncval = trunc i64 %val to i323158  %numhighbits = sub i32 32, %numlowbits3159  %mask = lshr i32 -1, %numhighbits3160  %masked = and i32 %mask, %truncval3161  ret i32 %masked3162}3163 3164; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit.3165; Masking is 64-bit. Then truncation.3166define i32 @bzhi64_32_c2(i64 %val, i32 %numlowbits) nounwind {3167; X86-NOBMI-LABEL: bzhi64_32_c2:3168; X86-NOBMI:       # %bb.0:3169; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3170; X86-NOBMI-NEXT:    xorl %ecx, %ecx3171; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3172; X86-NOBMI-NEXT:    shll %cl, %eax3173; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3174; X86-NOBMI-NEXT:    shrl %cl, %eax3175; X86-NOBMI-NEXT:    retl3176;3177; X86-BMI1-LABEL: bzhi64_32_c2:3178; X86-BMI1:       # %bb.0:3179; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3180; X86-BMI1-NEXT:    shll $8, %eax3181; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax3182; X86-BMI1-NEXT:    retl3183;3184; X86-BMI2-LABEL: bzhi64_32_c2:3185; X86-BMI2:       # %bb.0:3186; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3187; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax3188; X86-BMI2-NEXT:    retl3189;3190; X64-NOBMI-LABEL: bzhi64_32_c2:3191; X64-NOBMI:       # %bb.0:3192; X64-NOBMI-NEXT:    movl %esi, %ecx3193; X64-NOBMI-NEXT:    movq %rdi, %rax3194; X64-NOBMI-NEXT:    negb %cl3195; X64-NOBMI-NEXT:    shll %cl, %eax3196; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3197; X64-NOBMI-NEXT:    shrl %cl, %eax3198; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax3199; X64-NOBMI-NEXT:    retq3200;3201; X64-BMI1-LABEL: bzhi64_32_c2:3202; X64-BMI1:       # %bb.0:3203; X64-BMI1-NEXT:    shll $8, %esi3204; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax3205; X64-BMI1-NEXT:    retq3206;3207; X64-BMI2-LABEL: bzhi64_32_c2:3208; X64-BMI2:       # %bb.0:3209; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax3210; X64-BMI2-NEXT:    retq3211  %numhighbits = sub i32 32, %numlowbits3212  %mask = lshr i32 -1, %numhighbits3213  %zextmask = zext i32 %mask to i643214  %masked = and i64 %zextmask, %val3215  %truncmasked = trunc i64 %masked to i323216  ret i32 %truncmasked3217}3218 3219; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit.3220; Masking is 64-bit. Then truncation.3221define i32 @bzhi64_32_c3(i64 %val, i64 %numlowbits) nounwind {3222; X86-LABEL: bzhi64_32_c3:3223; X86:       # %bb.0:3224; X86-NEXT:    movb $64, %cl3225; X86-NEXT:    subb {{[0-9]+}}(%esp), %cl3226; X86-NEXT:    xorl %eax, %eax3227; X86-NEXT:    movl $-1, %edx3228; X86-NEXT:    shrdl %cl, %eax, %edx3229; X86-NEXT:    testb $32, %cl3230; X86-NEXT:    jne .LBB43_23231; X86-NEXT:  # %bb.1:3232; X86-NEXT:    movl %edx, %eax3233; X86-NEXT:  .LBB43_2:3234; X86-NEXT:    andl {{[0-9]+}}(%esp), %eax3235; X86-NEXT:    retl3236;3237; X64-NOBMI-LABEL: bzhi64_32_c3:3238; X64-NOBMI:       # %bb.0:3239; X64-NOBMI-NEXT:    movq %rsi, %rcx3240; X64-NOBMI-NEXT:    negb %cl3241; X64-NOBMI-NEXT:    movl $4294967295, %eax # imm = 0xFFFFFFFF3242; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx3243; X64-NOBMI-NEXT:    shrq %cl, %rax3244; X64-NOBMI-NEXT:    andl %edi, %eax3245; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax3246; X64-NOBMI-NEXT:    retq3247;3248; X64-BMI1-LABEL: bzhi64_32_c3:3249; X64-BMI1:       # %bb.0:3250; X64-BMI1-NEXT:    movq %rsi, %rcx3251; X64-BMI1-NEXT:    negb %cl3252; X64-BMI1-NEXT:    movl $4294967295, %eax # imm = 0xFFFFFFFF3253; X64-BMI1-NEXT:    # kill: def $cl killed $cl killed $rcx3254; X64-BMI1-NEXT:    shrq %cl, %rax3255; X64-BMI1-NEXT:    andl %edi, %eax3256; X64-BMI1-NEXT:    # kill: def $eax killed $eax killed $rax3257; X64-BMI1-NEXT:    retq3258;3259; X64-BMI2-LABEL: bzhi64_32_c3:3260; X64-BMI2:       # %bb.0:3261; X64-BMI2-NEXT:    negb %sil3262; X64-BMI2-NEXT:    movl $4294967295, %eax # imm = 0xFFFFFFFF3263; X64-BMI2-NEXT:    shrxq %rsi, %rax, %rax3264; X64-BMI2-NEXT:    andl %edi, %eax3265; X64-BMI2-NEXT:    # kill: def $eax killed $eax killed $rax3266; X64-BMI2-NEXT:    retq3267  %numhighbits = sub i64 64, %numlowbits3268  %mask = lshr i64 4294967295, %numhighbits3269  %masked = and i64 %mask, %val3270  %truncmasked = trunc i64 %masked to i323271  ret i32 %truncmasked3272}3273 3274; ---------------------------------------------------------------------------- ;3275; Pattern d. 32-bit.3276; ---------------------------------------------------------------------------- ;3277 3278define i32 @bzhi32_d0(i32 %val, i32 %numlowbits) nounwind {3279; X86-NOBMI-LABEL: bzhi32_d0:3280; X86-NOBMI:       # %bb.0:3281; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3282; X86-NOBMI-NEXT:    xorl %ecx, %ecx3283; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3284; X86-NOBMI-NEXT:    shll %cl, %eax3285; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3286; X86-NOBMI-NEXT:    shrl %cl, %eax3287; X86-NOBMI-NEXT:    retl3288;3289; X86-BMI1-LABEL: bzhi32_d0:3290; X86-BMI1:       # %bb.0:3291; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3292; X86-BMI1-NEXT:    shll $8, %eax3293; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax3294; X86-BMI1-NEXT:    retl3295;3296; X86-BMI2-LABEL: bzhi32_d0:3297; X86-BMI2:       # %bb.0:3298; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3299; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax3300; X86-BMI2-NEXT:    retl3301;3302; X64-NOBMI-LABEL: bzhi32_d0:3303; X64-NOBMI:       # %bb.0:3304; X64-NOBMI-NEXT:    movl %esi, %ecx3305; X64-NOBMI-NEXT:    movl %edi, %eax3306; X64-NOBMI-NEXT:    negb %cl3307; X64-NOBMI-NEXT:    shll %cl, %eax3308; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3309; X64-NOBMI-NEXT:    shrl %cl, %eax3310; X64-NOBMI-NEXT:    retq3311;3312; X64-BMI1-LABEL: bzhi32_d0:3313; X64-BMI1:       # %bb.0:3314; X64-BMI1-NEXT:    shll $8, %esi3315; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax3316; X64-BMI1-NEXT:    retq3317;3318; X64-BMI2-LABEL: bzhi32_d0:3319; X64-BMI2:       # %bb.0:3320; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax3321; X64-BMI2-NEXT:    retq3322  %numhighbits = sub i32 32, %numlowbits3323  %highbitscleared = shl i32 %val, %numhighbits3324  %masked = lshr i32 %highbitscleared, %numhighbits3325  ret i32 %masked3326}3327 3328define i32 @bzhi32_d1_indexzext(i32 %val, i8 %numlowbits) nounwind {3329; X86-NOBMI-LABEL: bzhi32_d1_indexzext:3330; X86-NOBMI:       # %bb.0:3331; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3332; X86-NOBMI-NEXT:    xorl %ecx, %ecx3333; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3334; X86-NOBMI-NEXT:    shll %cl, %eax3335; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3336; X86-NOBMI-NEXT:    shrl %cl, %eax3337; X86-NOBMI-NEXT:    retl3338;3339; X86-BMI1-LABEL: bzhi32_d1_indexzext:3340; X86-BMI1:       # %bb.0:3341; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3342; X86-BMI1-NEXT:    shll $8, %eax3343; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax3344; X86-BMI1-NEXT:    retl3345;3346; X86-BMI2-LABEL: bzhi32_d1_indexzext:3347; X86-BMI2:       # %bb.0:3348; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax3349; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax3350; X86-BMI2-NEXT:    retl3351;3352; X64-NOBMI-LABEL: bzhi32_d1_indexzext:3353; X64-NOBMI:       # %bb.0:3354; X64-NOBMI-NEXT:    movl %esi, %ecx3355; X64-NOBMI-NEXT:    movl %edi, %eax3356; X64-NOBMI-NEXT:    negb %cl3357; X64-NOBMI-NEXT:    shll %cl, %eax3358; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3359; X64-NOBMI-NEXT:    shrl %cl, %eax3360; X64-NOBMI-NEXT:    retq3361;3362; X64-BMI1-LABEL: bzhi32_d1_indexzext:3363; X64-BMI1:       # %bb.0:3364; X64-BMI1-NEXT:    shll $8, %esi3365; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax3366; X64-BMI1-NEXT:    retq3367;3368; X64-BMI2-LABEL: bzhi32_d1_indexzext:3369; X64-BMI2:       # %bb.0:3370; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax3371; X64-BMI2-NEXT:    retq3372  %numhighbits = sub i8 32, %numlowbits3373  %sh_prom = zext i8 %numhighbits to i323374  %highbitscleared = shl i32 %val, %sh_prom3375  %masked = lshr i32 %highbitscleared, %sh_prom3376  ret i32 %masked3377}3378 3379define i32 @bzhi32_d2_load(ptr %w, i32 %numlowbits) nounwind {3380; X86-NOBMI-LABEL: bzhi32_d2_load:3381; X86-NOBMI:       # %bb.0:3382; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3383; X86-NOBMI-NEXT:    movl (%eax), %eax3384; X86-NOBMI-NEXT:    xorl %ecx, %ecx3385; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3386; X86-NOBMI-NEXT:    shll %cl, %eax3387; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3388; X86-NOBMI-NEXT:    shrl %cl, %eax3389; X86-NOBMI-NEXT:    retl3390;3391; X86-BMI1-LABEL: bzhi32_d2_load:3392; X86-BMI1:       # %bb.0:3393; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax3394; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx3395; X86-BMI1-NEXT:    shll $8, %ecx3396; X86-BMI1-NEXT:    bextrl %ecx, (%eax), %eax3397; X86-BMI1-NEXT:    retl3398;3399; X86-BMI2-LABEL: bzhi32_d2_load:3400; X86-BMI2:       # %bb.0:3401; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax3402; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx3403; X86-BMI2-NEXT:    bzhil %ecx, (%eax), %eax3404; X86-BMI2-NEXT:    retl3405;3406; X64-NOBMI-LABEL: bzhi32_d2_load:3407; X64-NOBMI:       # %bb.0:3408; X64-NOBMI-NEXT:    movl %esi, %ecx3409; X64-NOBMI-NEXT:    movl (%rdi), %eax3410; X64-NOBMI-NEXT:    negb %cl3411; X64-NOBMI-NEXT:    shll %cl, %eax3412; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3413; X64-NOBMI-NEXT:    shrl %cl, %eax3414; X64-NOBMI-NEXT:    retq3415;3416; X64-BMI1-LABEL: bzhi32_d2_load:3417; X64-BMI1:       # %bb.0:3418; X64-BMI1-NEXT:    shll $8, %esi3419; X64-BMI1-NEXT:    bextrl %esi, (%rdi), %eax3420; X64-BMI1-NEXT:    retq3421;3422; X64-BMI2-LABEL: bzhi32_d2_load:3423; X64-BMI2:       # %bb.0:3424; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax3425; X64-BMI2-NEXT:    retq3426  %val = load i32, ptr %w3427  %numhighbits = sub i32 32, %numlowbits3428  %highbitscleared = shl i32 %val, %numhighbits3429  %masked = lshr i32 %highbitscleared, %numhighbits3430  ret i32 %masked3431}3432 3433define i32 @bzhi32_d3_load_indexzext(ptr %w, i8 %numlowbits) nounwind {3434; X86-NOBMI-LABEL: bzhi32_d3_load_indexzext:3435; X86-NOBMI:       # %bb.0:3436; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3437; X86-NOBMI-NEXT:    movl (%eax), %eax3438; X86-NOBMI-NEXT:    xorl %ecx, %ecx3439; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3440; X86-NOBMI-NEXT:    shll %cl, %eax3441; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3442; X86-NOBMI-NEXT:    shrl %cl, %eax3443; X86-NOBMI-NEXT:    retl3444;3445; X86-BMI1-LABEL: bzhi32_d3_load_indexzext:3446; X86-BMI1:       # %bb.0:3447; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax3448; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx3449; X86-BMI1-NEXT:    shll $8, %ecx3450; X86-BMI1-NEXT:    bextrl %ecx, (%eax), %eax3451; X86-BMI1-NEXT:    retl3452;3453; X86-BMI2-LABEL: bzhi32_d3_load_indexzext:3454; X86-BMI2:       # %bb.0:3455; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax3456; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %ecx3457; X86-BMI2-NEXT:    bzhil %ecx, (%eax), %eax3458; X86-BMI2-NEXT:    retl3459;3460; X64-NOBMI-LABEL: bzhi32_d3_load_indexzext:3461; X64-NOBMI:       # %bb.0:3462; X64-NOBMI-NEXT:    movl %esi, %ecx3463; X64-NOBMI-NEXT:    movl (%rdi), %eax3464; X64-NOBMI-NEXT:    negb %cl3465; X64-NOBMI-NEXT:    shll %cl, %eax3466; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3467; X64-NOBMI-NEXT:    shrl %cl, %eax3468; X64-NOBMI-NEXT:    retq3469;3470; X64-BMI1-LABEL: bzhi32_d3_load_indexzext:3471; X64-BMI1:       # %bb.0:3472; X64-BMI1-NEXT:    shll $8, %esi3473; X64-BMI1-NEXT:    bextrl %esi, (%rdi), %eax3474; X64-BMI1-NEXT:    retq3475;3476; X64-BMI2-LABEL: bzhi32_d3_load_indexzext:3477; X64-BMI2:       # %bb.0:3478; X64-BMI2-NEXT:    bzhil %esi, (%rdi), %eax3479; X64-BMI2-NEXT:    retq3480  %val = load i32, ptr %w3481  %numhighbits = sub i8 32, %numlowbits3482  %sh_prom = zext i8 %numhighbits to i323483  %highbitscleared = shl i32 %val, %sh_prom3484  %masked = lshr i32 %highbitscleared, %sh_prom3485  ret i32 %masked3486}3487 3488; 64-bit.3489 3490define i64 @bzhi64_d0(i64 %val, i64 %numlowbits) nounwind {3491; X86-NOBMI-LABEL: bzhi64_d0:3492; X86-NOBMI:       # %bb.0:3493; X86-NOBMI-NEXT:    pushl %ebx3494; X86-NOBMI-NEXT:    pushl %edi3495; X86-NOBMI-NEXT:    pushl %esi3496; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx3497; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3498; X86-NOBMI-NEXT:    movb $64, %cl3499; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3500; X86-NOBMI-NEXT:    movl %edx, %esi3501; X86-NOBMI-NEXT:    shll %cl, %esi3502; X86-NOBMI-NEXT:    shldl %cl, %edx, %eax3503; X86-NOBMI-NEXT:    testb $32, %cl3504; X86-NOBMI-NEXT:    movl %esi, %edi3505; X86-NOBMI-NEXT:    jne .LBB48_23506; X86-NOBMI-NEXT:  # %bb.1:3507; X86-NOBMI-NEXT:    movl %eax, %edi3508; X86-NOBMI-NEXT:  .LBB48_2:3509; X86-NOBMI-NEXT:    movl %edi, %eax3510; X86-NOBMI-NEXT:    shrl %cl, %eax3511; X86-NOBMI-NEXT:    xorl %ebx, %ebx3512; X86-NOBMI-NEXT:    testb $32, %cl3513; X86-NOBMI-NEXT:    movl $0, %edx3514; X86-NOBMI-NEXT:    jne .LBB48_43515; X86-NOBMI-NEXT:  # %bb.3:3516; X86-NOBMI-NEXT:    movl %esi, %ebx3517; X86-NOBMI-NEXT:    movl %eax, %edx3518; X86-NOBMI-NEXT:  .LBB48_4:3519; X86-NOBMI-NEXT:    shrdl %cl, %edi, %ebx3520; X86-NOBMI-NEXT:    testb $32, %cl3521; X86-NOBMI-NEXT:    jne .LBB48_63522; X86-NOBMI-NEXT:  # %bb.5:3523; X86-NOBMI-NEXT:    movl %ebx, %eax3524; X86-NOBMI-NEXT:  .LBB48_6:3525; X86-NOBMI-NEXT:    popl %esi3526; X86-NOBMI-NEXT:    popl %edi3527; X86-NOBMI-NEXT:    popl %ebx3528; X86-NOBMI-NEXT:    retl3529;3530; X86-BMI1-LABEL: bzhi64_d0:3531; X86-BMI1:       # %bb.0:3532; X86-BMI1-NEXT:    pushl %ebx3533; X86-BMI1-NEXT:    pushl %edi3534; X86-BMI1-NEXT:    pushl %esi3535; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx3536; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax3537; X86-BMI1-NEXT:    movb $64, %cl3538; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl3539; X86-BMI1-NEXT:    movl %edx, %esi3540; X86-BMI1-NEXT:    shll %cl, %esi3541; X86-BMI1-NEXT:    shldl %cl, %edx, %eax3542; X86-BMI1-NEXT:    testb $32, %cl3543; X86-BMI1-NEXT:    movl %esi, %edi3544; X86-BMI1-NEXT:    jne .LBB48_23545; X86-BMI1-NEXT:  # %bb.1:3546; X86-BMI1-NEXT:    movl %eax, %edi3547; X86-BMI1-NEXT:  .LBB48_2:3548; X86-BMI1-NEXT:    movl %edi, %eax3549; X86-BMI1-NEXT:    shrl %cl, %eax3550; X86-BMI1-NEXT:    xorl %ebx, %ebx3551; X86-BMI1-NEXT:    testb $32, %cl3552; X86-BMI1-NEXT:    movl $0, %edx3553; X86-BMI1-NEXT:    jne .LBB48_43554; X86-BMI1-NEXT:  # %bb.3:3555; X86-BMI1-NEXT:    movl %esi, %ebx3556; X86-BMI1-NEXT:    movl %eax, %edx3557; X86-BMI1-NEXT:  .LBB48_4:3558; X86-BMI1-NEXT:    shrdl %cl, %edi, %ebx3559; X86-BMI1-NEXT:    testb $32, %cl3560; X86-BMI1-NEXT:    jne .LBB48_63561; X86-BMI1-NEXT:  # %bb.5:3562; X86-BMI1-NEXT:    movl %ebx, %eax3563; X86-BMI1-NEXT:  .LBB48_6:3564; X86-BMI1-NEXT:    popl %esi3565; X86-BMI1-NEXT:    popl %edi3566; X86-BMI1-NEXT:    popl %ebx3567; X86-BMI1-NEXT:    retl3568;3569; X86-BMI2-LABEL: bzhi64_d0:3570; X86-BMI2:       # %bb.0:3571; X86-BMI2-NEXT:    pushl %edi3572; X86-BMI2-NEXT:    pushl %esi3573; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax3574; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %esi3575; X86-BMI2-NEXT:    movb $64, %cl3576; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %cl3577; X86-BMI2-NEXT:    shldl %cl, %eax, %esi3578; X86-BMI2-NEXT:    shlxl %ecx, %eax, %edi3579; X86-BMI2-NEXT:    xorl %edx, %edx3580; X86-BMI2-NEXT:    testb $32, %cl3581; X86-BMI2-NEXT:    je .LBB48_23582; X86-BMI2-NEXT:  # %bb.1:3583; X86-BMI2-NEXT:    movl %edi, %esi3584; X86-BMI2-NEXT:    movl $0, %edi3585; X86-BMI2-NEXT:  .LBB48_2:3586; X86-BMI2-NEXT:    shrxl %ecx, %esi, %eax3587; X86-BMI2-NEXT:    jne .LBB48_43588; X86-BMI2-NEXT:  # %bb.3:3589; X86-BMI2-NEXT:    movl %eax, %edx3590; X86-BMI2-NEXT:  .LBB48_4:3591; X86-BMI2-NEXT:    shrdl %cl, %esi, %edi3592; X86-BMI2-NEXT:    testb $32, %cl3593; X86-BMI2-NEXT:    jne .LBB48_63594; X86-BMI2-NEXT:  # %bb.5:3595; X86-BMI2-NEXT:    movl %edi, %eax3596; X86-BMI2-NEXT:  .LBB48_6:3597; X86-BMI2-NEXT:    popl %esi3598; X86-BMI2-NEXT:    popl %edi3599; X86-BMI2-NEXT:    retl3600;3601; X64-NOBMI-LABEL: bzhi64_d0:3602; X64-NOBMI:       # %bb.0:3603; X64-NOBMI-NEXT:    movq %rsi, %rcx3604; X64-NOBMI-NEXT:    movq %rdi, %rax3605; X64-NOBMI-NEXT:    negb %cl3606; X64-NOBMI-NEXT:    shlq %cl, %rax3607; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx3608; X64-NOBMI-NEXT:    shrq %cl, %rax3609; X64-NOBMI-NEXT:    retq3610;3611; X64-BMI1-LABEL: bzhi64_d0:3612; X64-BMI1:       # %bb.0:3613; X64-BMI1-NEXT:    shll $8, %esi3614; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax3615; X64-BMI1-NEXT:    retq3616;3617; X64-BMI2-LABEL: bzhi64_d0:3618; X64-BMI2:       # %bb.0:3619; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax3620; X64-BMI2-NEXT:    retq3621  %numhighbits = sub i64 64, %numlowbits3622  %highbitscleared = shl i64 %val, %numhighbits3623  %masked = lshr i64 %highbitscleared, %numhighbits3624  ret i64 %masked3625}3626 3627define i64 @bzhi64_d1_indexzext(i64 %val, i8 %numlowbits) nounwind {3628; X86-NOBMI-LABEL: bzhi64_d1_indexzext:3629; X86-NOBMI:       # %bb.0:3630; X86-NOBMI-NEXT:    pushl %ebx3631; X86-NOBMI-NEXT:    pushl %edi3632; X86-NOBMI-NEXT:    pushl %esi3633; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %edx3634; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3635; X86-NOBMI-NEXT:    movb $64, %cl3636; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3637; X86-NOBMI-NEXT:    movl %edx, %esi3638; X86-NOBMI-NEXT:    shll %cl, %esi3639; X86-NOBMI-NEXT:    shldl %cl, %edx, %eax3640; X86-NOBMI-NEXT:    testb $32, %cl3641; X86-NOBMI-NEXT:    movl %esi, %edi3642; X86-NOBMI-NEXT:    jne .LBB49_23643; X86-NOBMI-NEXT:  # %bb.1:3644; X86-NOBMI-NEXT:    movl %eax, %edi3645; X86-NOBMI-NEXT:  .LBB49_2:3646; X86-NOBMI-NEXT:    movl %edi, %eax3647; X86-NOBMI-NEXT:    shrl %cl, %eax3648; X86-NOBMI-NEXT:    xorl %ebx, %ebx3649; X86-NOBMI-NEXT:    testb $32, %cl3650; X86-NOBMI-NEXT:    movl $0, %edx3651; X86-NOBMI-NEXT:    jne .LBB49_43652; X86-NOBMI-NEXT:  # %bb.3:3653; X86-NOBMI-NEXT:    movl %esi, %ebx3654; X86-NOBMI-NEXT:    movl %eax, %edx3655; X86-NOBMI-NEXT:  .LBB49_4:3656; X86-NOBMI-NEXT:    shrdl %cl, %edi, %ebx3657; X86-NOBMI-NEXT:    testb $32, %cl3658; X86-NOBMI-NEXT:    jne .LBB49_63659; X86-NOBMI-NEXT:  # %bb.5:3660; X86-NOBMI-NEXT:    movl %ebx, %eax3661; X86-NOBMI-NEXT:  .LBB49_6:3662; X86-NOBMI-NEXT:    popl %esi3663; X86-NOBMI-NEXT:    popl %edi3664; X86-NOBMI-NEXT:    popl %ebx3665; X86-NOBMI-NEXT:    retl3666;3667; X86-BMI1-LABEL: bzhi64_d1_indexzext:3668; X86-BMI1:       # %bb.0:3669; X86-BMI1-NEXT:    pushl %ebx3670; X86-BMI1-NEXT:    pushl %edi3671; X86-BMI1-NEXT:    pushl %esi3672; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %edx3673; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax3674; X86-BMI1-NEXT:    movb $64, %cl3675; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl3676; X86-BMI1-NEXT:    movl %edx, %esi3677; X86-BMI1-NEXT:    shll %cl, %esi3678; X86-BMI1-NEXT:    shldl %cl, %edx, %eax3679; X86-BMI1-NEXT:    testb $32, %cl3680; X86-BMI1-NEXT:    movl %esi, %edi3681; X86-BMI1-NEXT:    jne .LBB49_23682; X86-BMI1-NEXT:  # %bb.1:3683; X86-BMI1-NEXT:    movl %eax, %edi3684; X86-BMI1-NEXT:  .LBB49_2:3685; X86-BMI1-NEXT:    movl %edi, %eax3686; X86-BMI1-NEXT:    shrl %cl, %eax3687; X86-BMI1-NEXT:    xorl %ebx, %ebx3688; X86-BMI1-NEXT:    testb $32, %cl3689; X86-BMI1-NEXT:    movl $0, %edx3690; X86-BMI1-NEXT:    jne .LBB49_43691; X86-BMI1-NEXT:  # %bb.3:3692; X86-BMI1-NEXT:    movl %esi, %ebx3693; X86-BMI1-NEXT:    movl %eax, %edx3694; X86-BMI1-NEXT:  .LBB49_4:3695; X86-BMI1-NEXT:    shrdl %cl, %edi, %ebx3696; X86-BMI1-NEXT:    testb $32, %cl3697; X86-BMI1-NEXT:    jne .LBB49_63698; X86-BMI1-NEXT:  # %bb.5:3699; X86-BMI1-NEXT:    movl %ebx, %eax3700; X86-BMI1-NEXT:  .LBB49_6:3701; X86-BMI1-NEXT:    popl %esi3702; X86-BMI1-NEXT:    popl %edi3703; X86-BMI1-NEXT:    popl %ebx3704; X86-BMI1-NEXT:    retl3705;3706; X86-BMI2-LABEL: bzhi64_d1_indexzext:3707; X86-BMI2:       # %bb.0:3708; X86-BMI2-NEXT:    pushl %edi3709; X86-BMI2-NEXT:    pushl %esi3710; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax3711; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %esi3712; X86-BMI2-NEXT:    movb $64, %cl3713; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %cl3714; X86-BMI2-NEXT:    shldl %cl, %eax, %esi3715; X86-BMI2-NEXT:    shlxl %ecx, %eax, %edi3716; X86-BMI2-NEXT:    xorl %edx, %edx3717; X86-BMI2-NEXT:    testb $32, %cl3718; X86-BMI2-NEXT:    je .LBB49_23719; X86-BMI2-NEXT:  # %bb.1:3720; X86-BMI2-NEXT:    movl %edi, %esi3721; X86-BMI2-NEXT:    movl $0, %edi3722; X86-BMI2-NEXT:  .LBB49_2:3723; X86-BMI2-NEXT:    shrxl %ecx, %esi, %eax3724; X86-BMI2-NEXT:    jne .LBB49_43725; X86-BMI2-NEXT:  # %bb.3:3726; X86-BMI2-NEXT:    movl %eax, %edx3727; X86-BMI2-NEXT:  .LBB49_4:3728; X86-BMI2-NEXT:    shrdl %cl, %esi, %edi3729; X86-BMI2-NEXT:    testb $32, %cl3730; X86-BMI2-NEXT:    jne .LBB49_63731; X86-BMI2-NEXT:  # %bb.5:3732; X86-BMI2-NEXT:    movl %edi, %eax3733; X86-BMI2-NEXT:  .LBB49_6:3734; X86-BMI2-NEXT:    popl %esi3735; X86-BMI2-NEXT:    popl %edi3736; X86-BMI2-NEXT:    retl3737;3738; X64-NOBMI-LABEL: bzhi64_d1_indexzext:3739; X64-NOBMI:       # %bb.0:3740; X64-NOBMI-NEXT:    movl %esi, %ecx3741; X64-NOBMI-NEXT:    movq %rdi, %rax3742; X64-NOBMI-NEXT:    negb %cl3743; X64-NOBMI-NEXT:    shlq %cl, %rax3744; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx3745; X64-NOBMI-NEXT:    shrq %cl, %rax3746; X64-NOBMI-NEXT:    retq3747;3748; X64-BMI1-LABEL: bzhi64_d1_indexzext:3749; X64-BMI1:       # %bb.0:3750; X64-BMI1-NEXT:    # kill: def $esi killed $esi def $rsi3751; X64-BMI1-NEXT:    shll $8, %esi3752; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax3753; X64-BMI1-NEXT:    retq3754;3755; X64-BMI2-LABEL: bzhi64_d1_indexzext:3756; X64-BMI2:       # %bb.0:3757; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi3758; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax3759; X64-BMI2-NEXT:    retq3760  %numhighbits = sub i8 64, %numlowbits3761  %sh_prom = zext i8 %numhighbits to i643762  %highbitscleared = shl i64 %val, %sh_prom3763  %masked = lshr i64 %highbitscleared, %sh_prom3764  ret i64 %masked3765}3766 3767define i64 @bzhi64_d2_load(ptr %w, i64 %numlowbits) nounwind {3768; X86-NOBMI-LABEL: bzhi64_d2_load:3769; X86-NOBMI:       # %bb.0:3770; X86-NOBMI-NEXT:    pushl %ebx3771; X86-NOBMI-NEXT:    pushl %edi3772; X86-NOBMI-NEXT:    pushl %esi3773; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3774; X86-NOBMI-NEXT:    movl (%eax), %edx3775; X86-NOBMI-NEXT:    movl 4(%eax), %eax3776; X86-NOBMI-NEXT:    movb $64, %cl3777; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3778; X86-NOBMI-NEXT:    movl %edx, %esi3779; X86-NOBMI-NEXT:    shll %cl, %esi3780; X86-NOBMI-NEXT:    shldl %cl, %edx, %eax3781; X86-NOBMI-NEXT:    testb $32, %cl3782; X86-NOBMI-NEXT:    movl %esi, %edi3783; X86-NOBMI-NEXT:    jne .LBB50_23784; X86-NOBMI-NEXT:  # %bb.1:3785; X86-NOBMI-NEXT:    movl %eax, %edi3786; X86-NOBMI-NEXT:  .LBB50_2:3787; X86-NOBMI-NEXT:    movl %edi, %eax3788; X86-NOBMI-NEXT:    shrl %cl, %eax3789; X86-NOBMI-NEXT:    xorl %ebx, %ebx3790; X86-NOBMI-NEXT:    testb $32, %cl3791; X86-NOBMI-NEXT:    movl $0, %edx3792; X86-NOBMI-NEXT:    jne .LBB50_43793; X86-NOBMI-NEXT:  # %bb.3:3794; X86-NOBMI-NEXT:    movl %esi, %ebx3795; X86-NOBMI-NEXT:    movl %eax, %edx3796; X86-NOBMI-NEXT:  .LBB50_4:3797; X86-NOBMI-NEXT:    shrdl %cl, %edi, %ebx3798; X86-NOBMI-NEXT:    testb $32, %cl3799; X86-NOBMI-NEXT:    jne .LBB50_63800; X86-NOBMI-NEXT:  # %bb.5:3801; X86-NOBMI-NEXT:    movl %ebx, %eax3802; X86-NOBMI-NEXT:  .LBB50_6:3803; X86-NOBMI-NEXT:    popl %esi3804; X86-NOBMI-NEXT:    popl %edi3805; X86-NOBMI-NEXT:    popl %ebx3806; X86-NOBMI-NEXT:    retl3807;3808; X86-BMI1-LABEL: bzhi64_d2_load:3809; X86-BMI1:       # %bb.0:3810; X86-BMI1-NEXT:    pushl %ebx3811; X86-BMI1-NEXT:    pushl %edi3812; X86-BMI1-NEXT:    pushl %esi3813; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax3814; X86-BMI1-NEXT:    movl (%eax), %edx3815; X86-BMI1-NEXT:    movl 4(%eax), %eax3816; X86-BMI1-NEXT:    movb $64, %cl3817; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl3818; X86-BMI1-NEXT:    movl %edx, %esi3819; X86-BMI1-NEXT:    shll %cl, %esi3820; X86-BMI1-NEXT:    shldl %cl, %edx, %eax3821; X86-BMI1-NEXT:    testb $32, %cl3822; X86-BMI1-NEXT:    movl %esi, %edi3823; X86-BMI1-NEXT:    jne .LBB50_23824; X86-BMI1-NEXT:  # %bb.1:3825; X86-BMI1-NEXT:    movl %eax, %edi3826; X86-BMI1-NEXT:  .LBB50_2:3827; X86-BMI1-NEXT:    movl %edi, %eax3828; X86-BMI1-NEXT:    shrl %cl, %eax3829; X86-BMI1-NEXT:    xorl %ebx, %ebx3830; X86-BMI1-NEXT:    testb $32, %cl3831; X86-BMI1-NEXT:    movl $0, %edx3832; X86-BMI1-NEXT:    jne .LBB50_43833; X86-BMI1-NEXT:  # %bb.3:3834; X86-BMI1-NEXT:    movl %esi, %ebx3835; X86-BMI1-NEXT:    movl %eax, %edx3836; X86-BMI1-NEXT:  .LBB50_4:3837; X86-BMI1-NEXT:    shrdl %cl, %edi, %ebx3838; X86-BMI1-NEXT:    testb $32, %cl3839; X86-BMI1-NEXT:    jne .LBB50_63840; X86-BMI1-NEXT:  # %bb.5:3841; X86-BMI1-NEXT:    movl %ebx, %eax3842; X86-BMI1-NEXT:  .LBB50_6:3843; X86-BMI1-NEXT:    popl %esi3844; X86-BMI1-NEXT:    popl %edi3845; X86-BMI1-NEXT:    popl %ebx3846; X86-BMI1-NEXT:    retl3847;3848; X86-BMI2-LABEL: bzhi64_d2_load:3849; X86-BMI2:       # %bb.0:3850; X86-BMI2-NEXT:    pushl %edi3851; X86-BMI2-NEXT:    pushl %esi3852; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax3853; X86-BMI2-NEXT:    movl (%eax), %edx3854; X86-BMI2-NEXT:    movl 4(%eax), %esi3855; X86-BMI2-NEXT:    movb $64, %cl3856; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %cl3857; X86-BMI2-NEXT:    shldl %cl, %edx, %esi3858; X86-BMI2-NEXT:    shlxl %ecx, %edx, %edi3859; X86-BMI2-NEXT:    xorl %edx, %edx3860; X86-BMI2-NEXT:    testb $32, %cl3861; X86-BMI2-NEXT:    je .LBB50_23862; X86-BMI2-NEXT:  # %bb.1:3863; X86-BMI2-NEXT:    movl %edi, %esi3864; X86-BMI2-NEXT:    movl $0, %edi3865; X86-BMI2-NEXT:  .LBB50_2:3866; X86-BMI2-NEXT:    shrxl %ecx, %esi, %eax3867; X86-BMI2-NEXT:    jne .LBB50_43868; X86-BMI2-NEXT:  # %bb.3:3869; X86-BMI2-NEXT:    movl %eax, %edx3870; X86-BMI2-NEXT:  .LBB50_4:3871; X86-BMI2-NEXT:    shrdl %cl, %esi, %edi3872; X86-BMI2-NEXT:    testb $32, %cl3873; X86-BMI2-NEXT:    jne .LBB50_63874; X86-BMI2-NEXT:  # %bb.5:3875; X86-BMI2-NEXT:    movl %edi, %eax3876; X86-BMI2-NEXT:  .LBB50_6:3877; X86-BMI2-NEXT:    popl %esi3878; X86-BMI2-NEXT:    popl %edi3879; X86-BMI2-NEXT:    retl3880;3881; X64-NOBMI-LABEL: bzhi64_d2_load:3882; X64-NOBMI:       # %bb.0:3883; X64-NOBMI-NEXT:    movq %rsi, %rcx3884; X64-NOBMI-NEXT:    movq (%rdi), %rax3885; X64-NOBMI-NEXT:    negb %cl3886; X64-NOBMI-NEXT:    shlq %cl, %rax3887; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx3888; X64-NOBMI-NEXT:    shrq %cl, %rax3889; X64-NOBMI-NEXT:    retq3890;3891; X64-BMI1-LABEL: bzhi64_d2_load:3892; X64-BMI1:       # %bb.0:3893; X64-BMI1-NEXT:    shll $8, %esi3894; X64-BMI1-NEXT:    bextrq %rsi, (%rdi), %rax3895; X64-BMI1-NEXT:    retq3896;3897; X64-BMI2-LABEL: bzhi64_d2_load:3898; X64-BMI2:       # %bb.0:3899; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax3900; X64-BMI2-NEXT:    retq3901  %val = load i64, ptr %w3902  %numhighbits = sub i64 64, %numlowbits3903  %highbitscleared = shl i64 %val, %numhighbits3904  %masked = lshr i64 %highbitscleared, %numhighbits3905  ret i64 %masked3906}3907 3908define i64 @bzhi64_d3_load_indexzext(ptr %w, i8 %numlowbits) nounwind {3909; X86-NOBMI-LABEL: bzhi64_d3_load_indexzext:3910; X86-NOBMI:       # %bb.0:3911; X86-NOBMI-NEXT:    pushl %ebx3912; X86-NOBMI-NEXT:    pushl %edi3913; X86-NOBMI-NEXT:    pushl %esi3914; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax3915; X86-NOBMI-NEXT:    movl (%eax), %edx3916; X86-NOBMI-NEXT:    movl 4(%eax), %eax3917; X86-NOBMI-NEXT:    movb $64, %cl3918; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl3919; X86-NOBMI-NEXT:    movl %edx, %esi3920; X86-NOBMI-NEXT:    shll %cl, %esi3921; X86-NOBMI-NEXT:    shldl %cl, %edx, %eax3922; X86-NOBMI-NEXT:    testb $32, %cl3923; X86-NOBMI-NEXT:    movl %esi, %edi3924; X86-NOBMI-NEXT:    jne .LBB51_23925; X86-NOBMI-NEXT:  # %bb.1:3926; X86-NOBMI-NEXT:    movl %eax, %edi3927; X86-NOBMI-NEXT:  .LBB51_2:3928; X86-NOBMI-NEXT:    movl %edi, %eax3929; X86-NOBMI-NEXT:    shrl %cl, %eax3930; X86-NOBMI-NEXT:    xorl %ebx, %ebx3931; X86-NOBMI-NEXT:    testb $32, %cl3932; X86-NOBMI-NEXT:    movl $0, %edx3933; X86-NOBMI-NEXT:    jne .LBB51_43934; X86-NOBMI-NEXT:  # %bb.3:3935; X86-NOBMI-NEXT:    movl %esi, %ebx3936; X86-NOBMI-NEXT:    movl %eax, %edx3937; X86-NOBMI-NEXT:  .LBB51_4:3938; X86-NOBMI-NEXT:    shrdl %cl, %edi, %ebx3939; X86-NOBMI-NEXT:    testb $32, %cl3940; X86-NOBMI-NEXT:    jne .LBB51_63941; X86-NOBMI-NEXT:  # %bb.5:3942; X86-NOBMI-NEXT:    movl %ebx, %eax3943; X86-NOBMI-NEXT:  .LBB51_6:3944; X86-NOBMI-NEXT:    popl %esi3945; X86-NOBMI-NEXT:    popl %edi3946; X86-NOBMI-NEXT:    popl %ebx3947; X86-NOBMI-NEXT:    retl3948;3949; X86-BMI1-LABEL: bzhi64_d3_load_indexzext:3950; X86-BMI1:       # %bb.0:3951; X86-BMI1-NEXT:    pushl %ebx3952; X86-BMI1-NEXT:    pushl %edi3953; X86-BMI1-NEXT:    pushl %esi3954; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax3955; X86-BMI1-NEXT:    movl (%eax), %edx3956; X86-BMI1-NEXT:    movl 4(%eax), %eax3957; X86-BMI1-NEXT:    movb $64, %cl3958; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl3959; X86-BMI1-NEXT:    movl %edx, %esi3960; X86-BMI1-NEXT:    shll %cl, %esi3961; X86-BMI1-NEXT:    shldl %cl, %edx, %eax3962; X86-BMI1-NEXT:    testb $32, %cl3963; X86-BMI1-NEXT:    movl %esi, %edi3964; X86-BMI1-NEXT:    jne .LBB51_23965; X86-BMI1-NEXT:  # %bb.1:3966; X86-BMI1-NEXT:    movl %eax, %edi3967; X86-BMI1-NEXT:  .LBB51_2:3968; X86-BMI1-NEXT:    movl %edi, %eax3969; X86-BMI1-NEXT:    shrl %cl, %eax3970; X86-BMI1-NEXT:    xorl %ebx, %ebx3971; X86-BMI1-NEXT:    testb $32, %cl3972; X86-BMI1-NEXT:    movl $0, %edx3973; X86-BMI1-NEXT:    jne .LBB51_43974; X86-BMI1-NEXT:  # %bb.3:3975; X86-BMI1-NEXT:    movl %esi, %ebx3976; X86-BMI1-NEXT:    movl %eax, %edx3977; X86-BMI1-NEXT:  .LBB51_4:3978; X86-BMI1-NEXT:    shrdl %cl, %edi, %ebx3979; X86-BMI1-NEXT:    testb $32, %cl3980; X86-BMI1-NEXT:    jne .LBB51_63981; X86-BMI1-NEXT:  # %bb.5:3982; X86-BMI1-NEXT:    movl %ebx, %eax3983; X86-BMI1-NEXT:  .LBB51_6:3984; X86-BMI1-NEXT:    popl %esi3985; X86-BMI1-NEXT:    popl %edi3986; X86-BMI1-NEXT:    popl %ebx3987; X86-BMI1-NEXT:    retl3988;3989; X86-BMI2-LABEL: bzhi64_d3_load_indexzext:3990; X86-BMI2:       # %bb.0:3991; X86-BMI2-NEXT:    pushl %edi3992; X86-BMI2-NEXT:    pushl %esi3993; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax3994; X86-BMI2-NEXT:    movl (%eax), %edx3995; X86-BMI2-NEXT:    movl 4(%eax), %esi3996; X86-BMI2-NEXT:    movb $64, %cl3997; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %cl3998; X86-BMI2-NEXT:    shldl %cl, %edx, %esi3999; X86-BMI2-NEXT:    shlxl %ecx, %edx, %edi4000; X86-BMI2-NEXT:    xorl %edx, %edx4001; X86-BMI2-NEXT:    testb $32, %cl4002; X86-BMI2-NEXT:    je .LBB51_24003; X86-BMI2-NEXT:  # %bb.1:4004; X86-BMI2-NEXT:    movl %edi, %esi4005; X86-BMI2-NEXT:    movl $0, %edi4006; X86-BMI2-NEXT:  .LBB51_2:4007; X86-BMI2-NEXT:    shrxl %ecx, %esi, %eax4008; X86-BMI2-NEXT:    jne .LBB51_44009; X86-BMI2-NEXT:  # %bb.3:4010; X86-BMI2-NEXT:    movl %eax, %edx4011; X86-BMI2-NEXT:  .LBB51_4:4012; X86-BMI2-NEXT:    shrdl %cl, %esi, %edi4013; X86-BMI2-NEXT:    testb $32, %cl4014; X86-BMI2-NEXT:    jne .LBB51_64015; X86-BMI2-NEXT:  # %bb.5:4016; X86-BMI2-NEXT:    movl %edi, %eax4017; X86-BMI2-NEXT:  .LBB51_6:4018; X86-BMI2-NEXT:    popl %esi4019; X86-BMI2-NEXT:    popl %edi4020; X86-BMI2-NEXT:    retl4021;4022; X64-NOBMI-LABEL: bzhi64_d3_load_indexzext:4023; X64-NOBMI:       # %bb.0:4024; X64-NOBMI-NEXT:    movl %esi, %ecx4025; X64-NOBMI-NEXT:    movq (%rdi), %rax4026; X64-NOBMI-NEXT:    negb %cl4027; X64-NOBMI-NEXT:    shlq %cl, %rax4028; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx4029; X64-NOBMI-NEXT:    shrq %cl, %rax4030; X64-NOBMI-NEXT:    retq4031;4032; X64-BMI1-LABEL: bzhi64_d3_load_indexzext:4033; X64-BMI1:       # %bb.0:4034; X64-BMI1-NEXT:    # kill: def $esi killed $esi def $rsi4035; X64-BMI1-NEXT:    shll $8, %esi4036; X64-BMI1-NEXT:    bextrq %rsi, (%rdi), %rax4037; X64-BMI1-NEXT:    retq4038;4039; X64-BMI2-LABEL: bzhi64_d3_load_indexzext:4040; X64-BMI2:       # %bb.0:4041; X64-BMI2-NEXT:    # kill: def $esi killed $esi def $rsi4042; X64-BMI2-NEXT:    bzhiq %rsi, (%rdi), %rax4043; X64-BMI2-NEXT:    retq4044  %val = load i64, ptr %w4045  %numhighbits = sub i8 64, %numlowbits4046  %sh_prom = zext i8 %numhighbits to i644047  %highbitscleared = shl i64 %val, %sh_prom4048  %masked = lshr i64 %highbitscleared, %sh_prom4049  ret i64 %masked4050}4051 4052; 64-bit, but with 32-bit output4053 4054; Everything done in 64-bit, truncation happens last.4055define i32 @bzhi64_32_d0(i64 %val, i64 %numlowbits) nounwind {4056; X86-NOBMI-LABEL: bzhi64_32_d0:4057; X86-NOBMI:       # %bb.0:4058; X86-NOBMI-NEXT:    pushl %esi4059; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %esi4060; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax4061; X86-NOBMI-NEXT:    movb $64, %cl4062; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl4063; X86-NOBMI-NEXT:    movl %esi, %edx4064; X86-NOBMI-NEXT:    shll %cl, %edx4065; X86-NOBMI-NEXT:    shldl %cl, %esi, %eax4066; X86-NOBMI-NEXT:    testb $32, %cl4067; X86-NOBMI-NEXT:    je .LBB52_24068; X86-NOBMI-NEXT:  # %bb.1:4069; X86-NOBMI-NEXT:    movl %edx, %eax4070; X86-NOBMI-NEXT:    xorl %edx, %edx4071; X86-NOBMI-NEXT:  .LBB52_2:4072; X86-NOBMI-NEXT:    shrdl %cl, %eax, %edx4073; X86-NOBMI-NEXT:    shrl %cl, %eax4074; X86-NOBMI-NEXT:    testb $32, %cl4075; X86-NOBMI-NEXT:    jne .LBB52_44076; X86-NOBMI-NEXT:  # %bb.3:4077; X86-NOBMI-NEXT:    movl %edx, %eax4078; X86-NOBMI-NEXT:  .LBB52_4:4079; X86-NOBMI-NEXT:    popl %esi4080; X86-NOBMI-NEXT:    retl4081;4082; X86-BMI1-LABEL: bzhi64_32_d0:4083; X86-BMI1:       # %bb.0:4084; X86-BMI1-NEXT:    pushl %esi4085; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %esi4086; X86-BMI1-NEXT:    movl {{[0-9]+}}(%esp), %eax4087; X86-BMI1-NEXT:    movb $64, %cl4088; X86-BMI1-NEXT:    subb {{[0-9]+}}(%esp), %cl4089; X86-BMI1-NEXT:    movl %esi, %edx4090; X86-BMI1-NEXT:    shll %cl, %edx4091; X86-BMI1-NEXT:    shldl %cl, %esi, %eax4092; X86-BMI1-NEXT:    testb $32, %cl4093; X86-BMI1-NEXT:    je .LBB52_24094; X86-BMI1-NEXT:  # %bb.1:4095; X86-BMI1-NEXT:    movl %edx, %eax4096; X86-BMI1-NEXT:    xorl %edx, %edx4097; X86-BMI1-NEXT:  .LBB52_2:4098; X86-BMI1-NEXT:    shrdl %cl, %eax, %edx4099; X86-BMI1-NEXT:    shrl %cl, %eax4100; X86-BMI1-NEXT:    testb $32, %cl4101; X86-BMI1-NEXT:    jne .LBB52_44102; X86-BMI1-NEXT:  # %bb.3:4103; X86-BMI1-NEXT:    movl %edx, %eax4104; X86-BMI1-NEXT:  .LBB52_4:4105; X86-BMI1-NEXT:    popl %esi4106; X86-BMI1-NEXT:    retl4107;4108; X86-BMI2-LABEL: bzhi64_32_d0:4109; X86-BMI2:       # %bb.0:4110; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %eax4111; X86-BMI2-NEXT:    movl {{[0-9]+}}(%esp), %edx4112; X86-BMI2-NEXT:    movb $64, %cl4113; X86-BMI2-NEXT:    subb {{[0-9]+}}(%esp), %cl4114; X86-BMI2-NEXT:    shldl %cl, %eax, %edx4115; X86-BMI2-NEXT:    shlxl %ecx, %eax, %eax4116; X86-BMI2-NEXT:    testb $32, %cl4117; X86-BMI2-NEXT:    je .LBB52_24118; X86-BMI2-NEXT:  # %bb.1:4119; X86-BMI2-NEXT:    movl %eax, %edx4120; X86-BMI2-NEXT:    xorl %eax, %eax4121; X86-BMI2-NEXT:  .LBB52_2:4122; X86-BMI2-NEXT:    shrdl %cl, %edx, %eax4123; X86-BMI2-NEXT:    testb $32, %cl4124; X86-BMI2-NEXT:    je .LBB52_44125; X86-BMI2-NEXT:  # %bb.3:4126; X86-BMI2-NEXT:    shrxl %ecx, %edx, %eax4127; X86-BMI2-NEXT:  .LBB52_4:4128; X86-BMI2-NEXT:    retl4129;4130; X64-NOBMI-LABEL: bzhi64_32_d0:4131; X64-NOBMI:       # %bb.0:4132; X64-NOBMI-NEXT:    movq %rsi, %rcx4133; X64-NOBMI-NEXT:    movq %rdi, %rax4134; X64-NOBMI-NEXT:    negb %cl4135; X64-NOBMI-NEXT:    shlq %cl, %rax4136; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $rcx4137; X64-NOBMI-NEXT:    shrq %cl, %rax4138; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax4139; X64-NOBMI-NEXT:    retq4140;4141; X64-BMI1-LABEL: bzhi64_32_d0:4142; X64-BMI1:       # %bb.0:4143; X64-BMI1-NEXT:    shll $8, %esi4144; X64-BMI1-NEXT:    bextrq %rsi, %rdi, %rax4145; X64-BMI1-NEXT:    # kill: def $eax killed $eax killed $rax4146; X64-BMI1-NEXT:    retq4147;4148; X64-BMI2-LABEL: bzhi64_32_d0:4149; X64-BMI2:       # %bb.0:4150; X64-BMI2-NEXT:    bzhiq %rsi, %rdi, %rax4151; X64-BMI2-NEXT:    # kill: def $eax killed $eax killed $rax4152; X64-BMI2-NEXT:    retq4153  %numhighbits = sub i64 64, %numlowbits4154  %highbitscleared = shl i64 %val, %numhighbits4155  %masked = lshr i64 %highbitscleared, %numhighbits4156  %res = trunc i64 %masked to i324157  ret i32 %res4158}4159 4160; Shifting happens in 64-bit, then truncation. Masking is 32-bit.4161define i32 @bzhi64_32_d1(i64 %val, i32 %numlowbits) nounwind {4162; X86-NOBMI-LABEL: bzhi64_32_d1:4163; X86-NOBMI:       # %bb.0:4164; X86-NOBMI-NEXT:    movl {{[0-9]+}}(%esp), %eax4165; X86-NOBMI-NEXT:    xorl %ecx, %ecx4166; X86-NOBMI-NEXT:    subb {{[0-9]+}}(%esp), %cl4167; X86-NOBMI-NEXT:    shll %cl, %eax4168; X86-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx4169; X86-NOBMI-NEXT:    shrl %cl, %eax4170; X86-NOBMI-NEXT:    retl4171;4172; X86-BMI1-LABEL: bzhi64_32_d1:4173; X86-BMI1:       # %bb.0:4174; X86-BMI1-NEXT:    movzbl {{[0-9]+}}(%esp), %eax4175; X86-BMI1-NEXT:    shll $8, %eax4176; X86-BMI1-NEXT:    bextrl %eax, {{[0-9]+}}(%esp), %eax4177; X86-BMI1-NEXT:    retl4178;4179; X86-BMI2-LABEL: bzhi64_32_d1:4180; X86-BMI2:       # %bb.0:4181; X86-BMI2-NEXT:    movzbl {{[0-9]+}}(%esp), %eax4182; X86-BMI2-NEXT:    bzhil %eax, {{[0-9]+}}(%esp), %eax4183; X86-BMI2-NEXT:    retl4184;4185; X64-NOBMI-LABEL: bzhi64_32_d1:4186; X64-NOBMI:       # %bb.0:4187; X64-NOBMI-NEXT:    movl %esi, %ecx4188; X64-NOBMI-NEXT:    movq %rdi, %rax4189; X64-NOBMI-NEXT:    negb %cl4190; X64-NOBMI-NEXT:    shll %cl, %eax4191; X64-NOBMI-NEXT:    # kill: def $cl killed $cl killed $ecx4192; X64-NOBMI-NEXT:    shrl %cl, %eax4193; X64-NOBMI-NEXT:    # kill: def $eax killed $eax killed $rax4194; X64-NOBMI-NEXT:    retq4195;4196; X64-BMI1-LABEL: bzhi64_32_d1:4197; X64-BMI1:       # %bb.0:4198; X64-BMI1-NEXT:    shll $8, %esi4199; X64-BMI1-NEXT:    bextrl %esi, %edi, %eax4200; X64-BMI1-NEXT:    retq4201;4202; X64-BMI2-LABEL: bzhi64_32_d1:4203; X64-BMI2:       # %bb.0:4204; X64-BMI2-NEXT:    bzhil %esi, %edi, %eax4205; X64-BMI2-NEXT:    retq4206  %truncval = trunc i64 %val to i324207  %numhighbits = sub i32 32, %numlowbits4208  %highbitscleared = shl i32 %truncval, %numhighbits4209  %masked = lshr i32 %highbitscleared, %numhighbits4210  ret i32 %masked4211}4212 4213; ---------------------------------------------------------------------------- ;4214; Constant mask4215; ---------------------------------------------------------------------------- ;4216 4217; 32-bit4218 4219define i32 @bzhi32_constant_mask32(i32 %val) nounwind {4220; X86-LABEL: bzhi32_constant_mask32:4221; X86:       # %bb.0:4222; X86-NEXT:    movl $2147483647, %eax # imm = 0x7FFFFFFF4223; X86-NEXT:    andl {{[0-9]+}}(%esp), %eax4224; X86-NEXT:    retl4225;4226; X64-LABEL: bzhi32_constant_mask32:4227; X64:       # %bb.0:4228; X64-NEXT:    movl %edi, %eax4229; X64-NEXT:    andl $2147483647, %eax # imm = 0x7FFFFFFF4230; X64-NEXT:    retq4231  %masked = and i32 %val, 21474836474232  ret i32 %masked4233}4234 4235define i32 @bzhi32_constant_mask32_load(ptr %val) nounwind {4236; X86-LABEL: bzhi32_constant_mask32_load:4237; X86:       # %bb.0:4238; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx4239; X86-NEXT:    movl $2147483647, %eax # imm = 0x7FFFFFFF4240; X86-NEXT:    andl (%ecx), %eax4241; X86-NEXT:    retl4242;4243; X64-LABEL: bzhi32_constant_mask32_load:4244; X64:       # %bb.0:4245; X64-NEXT:    movl $2147483647, %eax # imm = 0x7FFFFFFF4246; X64-NEXT:    andl (%rdi), %eax4247; X64-NEXT:    retq4248  %val1 = load i32, ptr %val4249  %masked = and i32 %val1, 21474836474250  ret i32 %masked4251}4252 4253define i32 @bzhi32_constant_mask16(i32 %val) nounwind {4254; X86-LABEL: bzhi32_constant_mask16:4255; X86:       # %bb.0:4256; X86-NEXT:    movl $32767, %eax # imm = 0x7FFF4257; X86-NEXT:    andl {{[0-9]+}}(%esp), %eax4258; X86-NEXT:    retl4259;4260; X64-LABEL: bzhi32_constant_mask16:4261; X64:       # %bb.0:4262; X64-NEXT:    movl %edi, %eax4263; X64-NEXT:    andl $32767, %eax # imm = 0x7FFF4264; X64-NEXT:    retq4265  %masked = and i32 %val, 327674266  ret i32 %masked4267}4268 4269define i32 @bzhi32_constant_mask16_load(ptr %val) nounwind {4270; X86-LABEL: bzhi32_constant_mask16_load:4271; X86:       # %bb.0:4272; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx4273; X86-NEXT:    movl $32767, %eax # imm = 0x7FFF4274; X86-NEXT:    andl (%ecx), %eax4275; X86-NEXT:    retl4276;4277; X64-LABEL: bzhi32_constant_mask16_load:4278; X64:       # %bb.0:4279; X64-NEXT:    movl $32767, %eax # imm = 0x7FFF4280; X64-NEXT:    andl (%rdi), %eax4281; X64-NEXT:    retq4282  %val1 = load i32, ptr %val4283  %masked = and i32 %val1, 327674284  ret i32 %masked4285}4286 4287define i32 @bzhi32_constant_mask8(i32 %val) nounwind {4288; X86-LABEL: bzhi32_constant_mask8:4289; X86:       # %bb.0:4290; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax4291; X86-NEXT:    andl $127, %eax4292; X86-NEXT:    retl4293;4294; X64-LABEL: bzhi32_constant_mask8:4295; X64:       # %bb.0:4296; X64-NEXT:    movl %edi, %eax4297; X64-NEXT:    andl $127, %eax4298; X64-NEXT:    retq4299  %masked = and i32 %val, 1274300  ret i32 %masked4301}4302 4303define i32 @bzhi32_constant_mask8_load(ptr %val) nounwind {4304; X86-LABEL: bzhi32_constant_mask8_load:4305; X86:       # %bb.0:4306; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax4307; X86-NEXT:    movl (%eax), %eax4308; X86-NEXT:    andl $127, %eax4309; X86-NEXT:    retl4310;4311; X64-LABEL: bzhi32_constant_mask8_load:4312; X64:       # %bb.0:4313; X64-NEXT:    movl (%rdi), %eax4314; X64-NEXT:    andl $127, %eax4315; X64-NEXT:    retq4316  %val1 = load i32, ptr %val4317  %masked = and i32 %val1, 1274318  ret i32 %masked4319}4320 4321; 64-bit4322 4323define i64 @bzhi64_constant_mask64(i64 %val) nounwind {4324; X86-LABEL: bzhi64_constant_mask64:4325; X86:       # %bb.0:4326; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax4327; X86-NEXT:    movl $1073741823, %edx # imm = 0x3FFFFFFF4328; X86-NEXT:    andl {{[0-9]+}}(%esp), %edx4329; X86-NEXT:    retl4330;4331; X64-NOBMI-LABEL: bzhi64_constant_mask64:4332; X64-NOBMI:       # %bb.0:4333; X64-NOBMI-NEXT:    movabsq $4611686018427387903, %rax # imm = 0x3FFFFFFFFFFFFFFF4334; X64-NOBMI-NEXT:    andq %rdi, %rax4335; X64-NOBMI-NEXT:    retq4336;4337; X64-BMI1NOTBM-LABEL: bzhi64_constant_mask64:4338; X64-BMI1NOTBM:       # %bb.0:4339; X64-BMI1NOTBM-NEXT:    movl $15872, %eax # imm = 0x3E004340; X64-BMI1NOTBM-NEXT:    bextrq %rax, %rdi, %rax4341; X64-BMI1NOTBM-NEXT:    retq4342;4343; X64-BMI1TBM-LABEL: bzhi64_constant_mask64:4344; X64-BMI1TBM:       # %bb.0:4345; X64-BMI1TBM-NEXT:    bextrq $15872, %rdi, %rax # imm = 0x3E004346; X64-BMI1TBM-NEXT:    retq4347;4348; X64-BMI2TBM-LABEL: bzhi64_constant_mask64:4349; X64-BMI2TBM:       # %bb.0:4350; X64-BMI2TBM-NEXT:    bextrq $15872, %rdi, %rax # imm = 0x3E004351; X64-BMI2TBM-NEXT:    retq4352;4353; X64-BMI2NOTBM-LABEL: bzhi64_constant_mask64:4354; X64-BMI2NOTBM:       # %bb.0:4355; X64-BMI2NOTBM-NEXT:    movb $62, %al4356; X64-BMI2NOTBM-NEXT:    bzhiq %rax, %rdi, %rax4357; X64-BMI2NOTBM-NEXT:    retq4358  %masked = and i64 %val, 46116860184273879034359  ret i64 %masked4360}4361 4362define i64 @bzhi64_constant_mask64_load(ptr %val) nounwind {4363; X86-LABEL: bzhi64_constant_mask64_load:4364; X86:       # %bb.0:4365; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx4366; X86-NEXT:    movl (%ecx), %eax4367; X86-NEXT:    movl $1073741823, %edx # imm = 0x3FFFFFFF4368; X86-NEXT:    andl 4(%ecx), %edx4369; X86-NEXT:    retl4370;4371; X64-NOBMI-LABEL: bzhi64_constant_mask64_load:4372; X64-NOBMI:       # %bb.0:4373; X64-NOBMI-NEXT:    movabsq $4611686018427387903, %rax # imm = 0x3FFFFFFFFFFFFFFF4374; X64-NOBMI-NEXT:    andq (%rdi), %rax4375; X64-NOBMI-NEXT:    retq4376;4377; X64-BMI1NOTBM-LABEL: bzhi64_constant_mask64_load:4378; X64-BMI1NOTBM:       # %bb.0:4379; X64-BMI1NOTBM-NEXT:    movl $15872, %eax # imm = 0x3E004380; X64-BMI1NOTBM-NEXT:    bextrq %rax, (%rdi), %rax4381; X64-BMI1NOTBM-NEXT:    retq4382;4383; X64-BMI1TBM-LABEL: bzhi64_constant_mask64_load:4384; X64-BMI1TBM:       # %bb.0:4385; X64-BMI1TBM-NEXT:    bextrq $15872, (%rdi), %rax # imm = 0x3E004386; X64-BMI1TBM-NEXT:    retq4387;4388; X64-BMI2TBM-LABEL: bzhi64_constant_mask64_load:4389; X64-BMI2TBM:       # %bb.0:4390; X64-BMI2TBM-NEXT:    bextrq $15872, (%rdi), %rax # imm = 0x3E004391; X64-BMI2TBM-NEXT:    retq4392;4393; X64-BMI2NOTBM-LABEL: bzhi64_constant_mask64_load:4394; X64-BMI2NOTBM:       # %bb.0:4395; X64-BMI2NOTBM-NEXT:    movb $62, %al4396; X64-BMI2NOTBM-NEXT:    bzhiq %rax, (%rdi), %rax4397; X64-BMI2NOTBM-NEXT:    retq4398  %val1 = load i64, ptr %val4399  %masked = and i64 %val1, 46116860184273879034400  ret i64 %masked4401}4402 4403define i64 @bzhi64_constant_mask32(i64 %val) nounwind {4404; X86-LABEL: bzhi64_constant_mask32:4405; X86:       # %bb.0:4406; X86-NEXT:    movl $2147483647, %eax # imm = 0x7FFFFFFF4407; X86-NEXT:    andl {{[0-9]+}}(%esp), %eax4408; X86-NEXT:    xorl %edx, %edx4409; X86-NEXT:    retl4410;4411; X64-LABEL: bzhi64_constant_mask32:4412; X64:       # %bb.0:4413; X64-NEXT:    movq %rdi, %rax4414; X64-NEXT:    andl $2147483647, %eax # imm = 0x7FFFFFFF4415; X64-NEXT:    retq4416  %masked = and i64 %val, 21474836474417  ret i64 %masked4418}4419 4420define i64 @bzhi64_constant_mask32_load(ptr %val) nounwind {4421; X86-LABEL: bzhi64_constant_mask32_load:4422; X86:       # %bb.0:4423; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx4424; X86-NEXT:    movl $2147483647, %eax # imm = 0x7FFFFFFF4425; X86-NEXT:    andl (%ecx), %eax4426; X86-NEXT:    xorl %edx, %edx4427; X86-NEXT:    retl4428;4429; X64-LABEL: bzhi64_constant_mask32_load:4430; X64:       # %bb.0:4431; X64-NEXT:    movq (%rdi), %rax4432; X64-NEXT:    andl $2147483647, %eax # imm = 0x7FFFFFFF4433; X64-NEXT:    retq4434  %val1 = load i64, ptr %val4435  %masked = and i64 %val1, 21474836474436  ret i64 %masked4437}4438 4439define i64 @bzhi64_constant_mask16(i64 %val) nounwind {4440; X86-LABEL: bzhi64_constant_mask16:4441; X86:       # %bb.0:4442; X86-NEXT:    movl $32767, %eax # imm = 0x7FFF4443; X86-NEXT:    andl {{[0-9]+}}(%esp), %eax4444; X86-NEXT:    xorl %edx, %edx4445; X86-NEXT:    retl4446;4447; X64-LABEL: bzhi64_constant_mask16:4448; X64:       # %bb.0:4449; X64-NEXT:    movq %rdi, %rax4450; X64-NEXT:    andl $32767, %eax # imm = 0x7FFF4451; X64-NEXT:    retq4452  %masked = and i64 %val, 327674453  ret i64 %masked4454}4455 4456define i64 @bzhi64_constant_mask16_load(ptr %val) nounwind {4457; X86-LABEL: bzhi64_constant_mask16_load:4458; X86:       # %bb.0:4459; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx4460; X86-NEXT:    movl $32767, %eax # imm = 0x7FFF4461; X86-NEXT:    andl (%ecx), %eax4462; X86-NEXT:    xorl %edx, %edx4463; X86-NEXT:    retl4464;4465; X64-LABEL: bzhi64_constant_mask16_load:4466; X64:       # %bb.0:4467; X64-NEXT:    movq (%rdi), %rax4468; X64-NEXT:    andl $32767, %eax # imm = 0x7FFF4469; X64-NEXT:    retq4470  %val1 = load i64, ptr %val4471  %masked = and i64 %val1, 327674472  ret i64 %masked4473}4474 4475define i64 @bzhi64_constant_mask8(i64 %val) nounwind {4476; X86-LABEL: bzhi64_constant_mask8:4477; X86:       # %bb.0:4478; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax4479; X86-NEXT:    andl $127, %eax4480; X86-NEXT:    xorl %edx, %edx4481; X86-NEXT:    retl4482;4483; X64-LABEL: bzhi64_constant_mask8:4484; X64:       # %bb.0:4485; X64-NEXT:    movq %rdi, %rax4486; X64-NEXT:    andl $127, %eax4487; X64-NEXT:    retq4488  %masked = and i64 %val, 1274489  ret i64 %masked4490}4491 4492define i64 @bzhi64_constant_mask8_load(ptr %val) nounwind {4493; X86-LABEL: bzhi64_constant_mask8_load:4494; X86:       # %bb.0:4495; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax4496; X86-NEXT:    movl (%eax), %eax4497; X86-NEXT:    andl $127, %eax4498; X86-NEXT:    xorl %edx, %edx4499; X86-NEXT:    retl4500;4501; X64-LABEL: bzhi64_constant_mask8_load:4502; X64:       # %bb.0:4503; X64-NEXT:    movq (%rdi), %rax4504; X64-NEXT:    andl $127, %eax4505; X64-NEXT:    retq4506  %val1 = load i64, ptr %val4507  %masked = and i64 %val1, 1274508  ret i64 %masked4509}4510 4511; Ensure constant hoisting doesn't prevent BEXTR/BZHI instructions in both paths.4512define void @PR111323(ptr nocapture noundef writeonly %use, i64 noundef %x, i64 noundef %y) nounwind {4513; X86-LABEL: PR111323:4514; X86:       # %bb.0: # %entry4515; X86-NEXT:    pushl %edi4516; X86-NEXT:    pushl %esi4517; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax4518; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx4519; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx4520; X86-NEXT:    movl {{[0-9]+}}(%esp), %esi4521; X86-NEXT:    movzwl {{[0-9]+}}(%esp), %edi4522; X86-NEXT:    movl %edi, 4(%ecx)4523; X86-NEXT:    movl %esi, (%ecx)4524; X86-NEXT:    movl %edx, %esi4525; X86-NEXT:    orl %eax, %esi4526; X86-NEXT:    je .LBB68_24527; X86-NEXT:  # %bb.1: # %if.end4528; X86-NEXT:    andl $65535, %eax # imm = 0xFFFF4529; X86-NEXT:    andl $-1, %edx4530; X86-NEXT:    movl %edx, 8(%ecx)4531; X86-NEXT:    movl %eax, 12(%ecx)4532; X86-NEXT:  .LBB68_2: # %return4533; X86-NEXT:    popl %esi4534; X86-NEXT:    popl %edi4535; X86-NEXT:    retl4536;4537; X64-NOBMI-LABEL: PR111323:4538; X64-NOBMI:       # %bb.0: # %entry4539; X64-NOBMI-NEXT:    movabsq $281474976710655, %rax # imm = 0xFFFFFFFFFFFF4540; X64-NOBMI-NEXT:    andq %rax, %rsi4541; X64-NOBMI-NEXT:    movq %rsi, (%rdi)4542; X64-NOBMI-NEXT:    testq %rdx, %rdx4543; X64-NOBMI-NEXT:    je .LBB68_24544; X64-NOBMI-NEXT:  # %bb.1: # %if.end4545; X64-NOBMI-NEXT:    andq %rax, %rdx4546; X64-NOBMI-NEXT:    movq %rdx, 8(%rdi)4547; X64-NOBMI-NEXT:  .LBB68_2: # %return4548; X64-NOBMI-NEXT:    retq4549;4550; X64-BMI1NOTBM-LABEL: PR111323:4551; X64-BMI1NOTBM:       # %bb.0: # %entry4552; X64-BMI1NOTBM-NEXT:    movl $12288, %eax # imm = 0x30004553; X64-BMI1NOTBM-NEXT:    bextrq %rax, %rsi, %rax4554; X64-BMI1NOTBM-NEXT:    movq %rax, (%rdi)4555; X64-BMI1NOTBM-NEXT:    testq %rdx, %rdx4556; X64-BMI1NOTBM-NEXT:    je .LBB68_24557; X64-BMI1NOTBM-NEXT:  # %bb.1: # %if.end4558; X64-BMI1NOTBM-NEXT:    movl $12288, %eax # imm = 0x30004559; X64-BMI1NOTBM-NEXT:    bextrq %rax, %rdx, %rax4560; X64-BMI1NOTBM-NEXT:    movq %rax, 8(%rdi)4561; X64-BMI1NOTBM-NEXT:  .LBB68_2: # %return4562; X64-BMI1NOTBM-NEXT:    retq4563;4564; X64-BMI1TBM-LABEL: PR111323:4565; X64-BMI1TBM:       # %bb.0: # %entry4566; X64-BMI1TBM-NEXT:    bextrq $12288, %rsi, %rax # imm = 0x30004567; X64-BMI1TBM-NEXT:    movq %rax, (%rdi)4568; X64-BMI1TBM-NEXT:    testq %rdx, %rdx4569; X64-BMI1TBM-NEXT:    je .LBB68_24570; X64-BMI1TBM-NEXT:  # %bb.1: # %if.end4571; X64-BMI1TBM-NEXT:    bextrq $12288, %rdx, %rax # imm = 0x30004572; X64-BMI1TBM-NEXT:    movq %rax, 8(%rdi)4573; X64-BMI1TBM-NEXT:  .LBB68_2: # %return4574; X64-BMI1TBM-NEXT:    retq4575;4576; X64-BMI2TBM-LABEL: PR111323:4577; X64-BMI2TBM:       # %bb.0: # %entry4578; X64-BMI2TBM-NEXT:    bextrq $12288, %rsi, %rax # imm = 0x30004579; X64-BMI2TBM-NEXT:    movq %rax, (%rdi)4580; X64-BMI2TBM-NEXT:    testq %rdx, %rdx4581; X64-BMI2TBM-NEXT:    je .LBB68_24582; X64-BMI2TBM-NEXT:  # %bb.1: # %if.end4583; X64-BMI2TBM-NEXT:    bextrq $12288, %rdx, %rax # imm = 0x30004584; X64-BMI2TBM-NEXT:    movq %rax, 8(%rdi)4585; X64-BMI2TBM-NEXT:  .LBB68_2: # %return4586; X64-BMI2TBM-NEXT:    retq4587;4588; X64-BMI2NOTBM-LABEL: PR111323:4589; X64-BMI2NOTBM:       # %bb.0: # %entry4590; X64-BMI2NOTBM-NEXT:    movb $48, %al4591; X64-BMI2NOTBM-NEXT:    bzhiq %rax, %rsi, %rcx4592; X64-BMI2NOTBM-NEXT:    movq %rcx, (%rdi)4593; X64-BMI2NOTBM-NEXT:    testq %rdx, %rdx4594; X64-BMI2NOTBM-NEXT:    je .LBB68_24595; X64-BMI2NOTBM-NEXT:  # %bb.1: # %if.end4596; X64-BMI2NOTBM-NEXT:    bzhiq %rax, %rdx, %rax4597; X64-BMI2NOTBM-NEXT:    movq %rax, 8(%rdi)4598; X64-BMI2NOTBM-NEXT:  .LBB68_2: # %return4599; X64-BMI2NOTBM-NEXT:    retq4600entry:4601  %and = and i64 %x, 2814749767106554602  store i64 %and, ptr %use, align 84603  %cmp = icmp eq i64 %y, 04604  br i1 %cmp, label %return, label %if.end4605 4606if.end:4607  %and1 = and i64 %y, 2814749767106554608  %arrayidx2 = getelementptr inbounds i8, ptr %use, i64 84609  store i64 %and1, ptr %arrayidx2, align 84610  br label %return4611 4612return:4613  ret void4614}4615