1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=i386-unknown-unknown -disable-cgp-branch-opts | FileCheck %s --check-prefix=CHECK --check-prefix=X32 3; RUN: llc < %s -mtriple=x86_64-unknown-unknown -disable-cgp-branch-opts | FileCheck %s --check-prefix=CHECK --check-prefix=X64 4 5; rdar://7573216 6; PR6146 7 8define i32 @t1(i32 %x) nounwind readnone ssp { 9; X32-LABEL: t1: 10; X32: # %bb.0: 11; X32-NEXT: cmpl $1, {{[0-9]+}}(%esp) 12; X32-NEXT: sbbl %eax, %eax 13; X32-NEXT: retl 14; 15; X64-LABEL: t1: 16; X64: # %bb.0: 17; X64-NEXT: cmpl $1, %edi 18; X64-NEXT: sbbl %eax, %eax 19; X64-NEXT: retq 20 %t0 = icmp eq i32 %x, 0 21 %if = select i1 %t0, i32 -1, i32 0 22 ret i32 %if 23} 24 25define i32 @t2(i32 %x) nounwind readnone ssp { 26; X32-LABEL: t2: 27; X32: # %bb.0: 28; X32-NEXT: cmpl $1, {{[0-9]+}}(%esp) 29; X32-NEXT: sbbl %eax, %eax 30; X32-NEXT: retl 31; 32; X64-LABEL: t2: 33; X64: # %bb.0: 34; X64-NEXT: cmpl $1, %edi 35; X64-NEXT: sbbl %eax, %eax 36; X64-NEXT: retq 37 %t0 = icmp eq i32 %x, 0 38 %if = sext i1 %t0 to i32 39 ret i32 %if 40} 41 42define i32 @t3() nounwind readonly { 43; X32-LABEL: t3: 44; X32: # %bb.0: # %entry 45; X32-NEXT: cmpl $1, %eax 46; X32-NEXT: sbbl %eax, %eax 47; X32-NEXT: cmpl %eax, %eax 48; X32-NEXT: sbbl %eax, %eax 49; X32-NEXT: xorl %eax, %eax 50; X32-NEXT: retl 51; 52; X64-LABEL: t3: 53; X64: # %bb.0: # %entry 54; X64-NEXT: xorl %eax, %eax 55; X64-NEXT: testl %eax, %eax 56; X64-NEXT: sete %al 57; X64-NEXT: negq %rax 58; X64-NEXT: cmpq %rax, %rax 59; X64-NEXT: xorl %eax, %eax 60; X64-NEXT: retq 61entry: 62 %not.tobool = icmp eq i32 undef, 0 63 %cond = sext i1 %not.tobool to i32 64 %conv = sext i1 %not.tobool to i64 65 %add13 = add i64 0, %conv 66 %cmp = icmp ult i64 undef, %add13 67 br i1 %cmp, label %if.then, label %if.end 68 69if.then: 70 br label %if.end 71 72if.end: 73 %xor27 = xor i32 undef, %cond 74 ret i32 0 75} 76 77define i32 @t4(i64 %x) nounwind readnone ssp { 78; X32-LABEL: t4: 79; X32: # %bb.0: 80; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx 81; X32-NEXT: xorl %eax, %eax 82; X32-NEXT: orl {{[0-9]+}}(%esp), %ecx 83; X32-NEXT: sete %al 84; X32-NEXT: negl %eax 85; X32-NEXT: retl 86; 87; X64-LABEL: t4: 88; X64: # %bb.0: 89; X64-NEXT: cmpq $1, %rdi 90; X64-NEXT: sbbl %eax, %eax 91; X64-NEXT: retq 92 %t0 = icmp eq i64 %x, 0 93 %t1 = sext i1 %t0 to i32 94 ret i32 %t1 95} 96 97define i64 @t5(i32 %x) nounwind readnone ssp { 98; X32-LABEL: t5: 99; X32: # %bb.0: 100; X32-NEXT: cmpl $1, {{[0-9]+}}(%esp) 101; X32-NEXT: sbbl %eax, %eax 102; X32-NEXT: movl %eax, %edx 103; X32-NEXT: retl 104; 105; X64-LABEL: t5: 106; X64: # %bb.0: 107; X64-NEXT: cmpl $1, %edi 108; X64-NEXT: sbbq %rax, %rax 109; X64-NEXT: retq 110 %t0 = icmp eq i32 %x, 0 111 %t1 = sext i1 %t0 to i64 112 ret i64 %t1 113} 114 115; sext (xor Bool, -1) --> sub (zext Bool), 1 116 117define i32 @select_0_or_1s(i1 %cond) { 118; X32-LABEL: select_0_or_1s: 119; X32: # %bb.0: 120; X32-NEXT: movzbl {{[0-9]+}}(%esp), %eax 121; X32-NEXT: andl $1, %eax 122; X32-NEXT: decl %eax 123; X32-NEXT: retl 124; 125; X64-LABEL: select_0_or_1s: 126; X64: # %bb.0: 127; X64-NEXT: # kill: def $edi killed $edi def $rdi 128; X64-NEXT: andl $1, %edi 129; X64-NEXT: leal -1(%rdi), %eax 130; X64-NEXT: retq 131 %not = xor i1 %cond, 1 132 %sext = sext i1 %not to i32 133 ret i32 %sext 134} 135 136; sext (xor Bool, -1) --> sub (zext Bool), 1 137 138define i32 @select_0_or_1s_zeroext(i1 zeroext %cond) { 139; X32-LABEL: select_0_or_1s_zeroext: 140; X32: # %bb.0: 141; X32-NEXT: movzbl {{[0-9]+}}(%esp), %eax 142; X32-NEXT: decl %eax 143; X32-NEXT: retl 144; 145; X64-LABEL: select_0_or_1s_zeroext: 146; X64: # %bb.0: 147; X64-NEXT: # kill: def $edi killed $edi def $rdi 148; X64-NEXT: leal -1(%rdi), %eax 149; X64-NEXT: retq 150 %not = xor i1 %cond, 1 151 %sext = sext i1 %not to i32 152 ret i32 %sext 153} 154 155; sext (xor Bool, -1) --> sub (zext Bool), 1 156 157define i32 @select_0_or_1s_signext(i1 signext %cond) { 158; X32-LABEL: select_0_or_1s_signext: 159; X32: # %bb.0: 160; X32-NEXT: movzbl {{[0-9]+}}(%esp), %eax 161; X32-NEXT: andl $1, %eax 162; X32-NEXT: decl %eax 163; X32-NEXT: retl 164; 165; X64-LABEL: select_0_or_1s_signext: 166; X64: # %bb.0: 167; X64-NEXT: notl %edi 168; X64-NEXT: movl %edi, %eax 169; X64-NEXT: retq 170 %not = xor i1 %cond, 1 171 %sext = sext i1 %not to i32 172 ret i32 %sext 173} 174 175