1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=i686-- | FileCheck %s --check-prefixes=X86 3; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=X64 4 5; 6; fixed avg(x,y) = add(and(x,y),ashr(xor(x,y),1)) 7; 8; ext avg(x,y) = trunc(ashr(add(sext(x),sext(y)),1)) 9; 10 11define i8 @test_fixed_i8(i8 %a0, i8 %a1) nounwind { 12; X86-LABEL: test_fixed_i8: 13; X86: # %bb.0: 14; X86-NEXT: movsbl {{[0-9]+}}(%esp), %ecx 15; X86-NEXT: movsbl {{[0-9]+}}(%esp), %eax 16; X86-NEXT: addl %ecx, %eax 17; X86-NEXT: shrl %eax 18; X86-NEXT: # kill: def $al killed $al killed $eax 19; X86-NEXT: retl 20; 21; X64-LABEL: test_fixed_i8: 22; X64: # %bb.0: 23; X64-NEXT: movsbl %sil, %ecx 24; X64-NEXT: movsbl %dil, %eax 25; X64-NEXT: addl %ecx, %eax 26; X64-NEXT: shrl %eax 27; X64-NEXT: # kill: def $al killed $al killed $eax 28; X64-NEXT: retq 29 %and = and i8 %a0, %a1 30 %xor = xor i8 %a0, %a1 31 %shift = ashr i8 %xor, 1 32 %res = add i8 %and, %shift 33 ret i8 %res 34} 35 36define i8 @test_ext_i8(i8 %a0, i8 %a1) nounwind { 37; X86-LABEL: test_ext_i8: 38; X86: # %bb.0: 39; X86-NEXT: movsbl {{[0-9]+}}(%esp), %ecx 40; X86-NEXT: movsbl {{[0-9]+}}(%esp), %eax 41; X86-NEXT: addl %ecx, %eax 42; X86-NEXT: shrl %eax 43; X86-NEXT: # kill: def $al killed $al killed $eax 44; X86-NEXT: retl 45; 46; X64-LABEL: test_ext_i8: 47; X64: # %bb.0: 48; X64-NEXT: movsbl %sil, %ecx 49; X64-NEXT: movsbl %dil, %eax 50; X64-NEXT: addl %ecx, %eax 51; X64-NEXT: shrl %eax 52; X64-NEXT: # kill: def $al killed $al killed $eax 53; X64-NEXT: retq 54 %x0 = sext i8 %a0 to i16 55 %x1 = sext i8 %a1 to i16 56 %sum = add i16 %x0, %x1 57 %shift = ashr i16 %sum, 1 58 %res = trunc i16 %shift to i8 59 ret i8 %res 60} 61 62define i16 @test_fixed_i16(i16 %a0, i16 %a1) nounwind { 63; X86-LABEL: test_fixed_i16: 64; X86: # %bb.0: 65; X86-NEXT: movswl {{[0-9]+}}(%esp), %ecx 66; X86-NEXT: movswl {{[0-9]+}}(%esp), %eax 67; X86-NEXT: addl %ecx, %eax 68; X86-NEXT: shrl %eax 69; X86-NEXT: # kill: def $ax killed $ax killed $eax 70; X86-NEXT: retl 71; 72; X64-LABEL: test_fixed_i16: 73; X64: # %bb.0: 74; X64-NEXT: movswl %si, %ecx 75; X64-NEXT: movswl %di, %eax 76; X64-NEXT: addl %ecx, %eax 77; X64-NEXT: shrl %eax 78; X64-NEXT: # kill: def $ax killed $ax killed $eax 79; X64-NEXT: retq 80 %and = and i16 %a0, %a1 81 %xor = xor i16 %a0, %a1 82 %shift = ashr i16 %xor, 1 83 %res = add i16 %and, %shift 84 ret i16 %res 85} 86 87define i16 @test_ext_i16(i16 %a0, i16 %a1) nounwind { 88; X86-LABEL: test_ext_i16: 89; X86: # %bb.0: 90; X86-NEXT: movswl {{[0-9]+}}(%esp), %ecx 91; X86-NEXT: movswl {{[0-9]+}}(%esp), %eax 92; X86-NEXT: addl %ecx, %eax 93; X86-NEXT: shrl %eax 94; X86-NEXT: # kill: def $ax killed $ax killed $eax 95; X86-NEXT: retl 96; 97; X64-LABEL: test_ext_i16: 98; X64: # %bb.0: 99; X64-NEXT: movswl %si, %ecx 100; X64-NEXT: movswl %di, %eax 101; X64-NEXT: addl %ecx, %eax 102; X64-NEXT: shrl %eax 103; X64-NEXT: # kill: def $ax killed $ax killed $eax 104; X64-NEXT: retq 105 %x0 = sext i16 %a0 to i32 106 %x1 = sext i16 %a1 to i32 107 %sum = add i32 %x0, %x1 108 %shift = ashr i32 %sum, 1 109 %res = trunc i32 %shift to i16 110 ret i16 %res 111} 112 113define i32 @test_fixed_i32(i32 %a0, i32 %a1) nounwind { 114; X86-LABEL: test_fixed_i32: 115; X86: # %bb.0: 116; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 117; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 118; X86-NEXT: movl %eax, %edx 119; X86-NEXT: andl %ecx, %edx 120; X86-NEXT: xorl %ecx, %eax 121; X86-NEXT: sarl %eax 122; X86-NEXT: addl %edx, %eax 123; X86-NEXT: retl 124; 125; X64-LABEL: test_fixed_i32: 126; X64: # %bb.0: 127; X64-NEXT: movslq %esi, %rcx 128; X64-NEXT: movslq %edi, %rax 129; X64-NEXT: addq %rcx, %rax 130; X64-NEXT: shrq %rax 131; X64-NEXT: # kill: def $eax killed $eax killed $rax 132; X64-NEXT: retq 133 %and = and i32 %a0, %a1 134 %xor = xor i32 %a1, %a0 135 %shift = ashr i32 %xor, 1 136 %res = add i32 %and, %shift 137 ret i32 %res 138} 139 140define i32 @test_ext_i32(i32 %a0, i32 %a1) nounwind { 141; X86-LABEL: test_ext_i32: 142; X86: # %bb.0: 143; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 144; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 145; X86-NEXT: movl %eax, %edx 146; X86-NEXT: andl %ecx, %edx 147; X86-NEXT: xorl %ecx, %eax 148; X86-NEXT: sarl %eax 149; X86-NEXT: addl %edx, %eax 150; X86-NEXT: retl 151; 152; X64-LABEL: test_ext_i32: 153; X64: # %bb.0: 154; X64-NEXT: movslq %esi, %rcx 155; X64-NEXT: movslq %edi, %rax 156; X64-NEXT: addq %rcx, %rax 157; X64-NEXT: shrq %rax 158; X64-NEXT: # kill: def $eax killed $eax killed $rax 159; X64-NEXT: retq 160 %x0 = sext i32 %a0 to i64 161 %x1 = sext i32 %a1 to i64 162 %sum = add i64 %x0, %x1 163 %shift = ashr i64 %sum, 1 164 %res = trunc i64 %shift to i32 165 ret i32 %res 166} 167 168define i64 @test_fixed_i64(i64 %a0, i64 %a1) nounwind { 169; X86-LABEL: test_fixed_i64: 170; X86: # %bb.0: 171; X86-NEXT: pushl %ebx 172; X86-NEXT: pushl %edi 173; X86-NEXT: pushl %esi 174; X86-NEXT: movl {{[0-9]+}}(%esp), %esi 175; X86-NEXT: movl {{[0-9]+}}(%esp), %edi 176; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 177; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 178; X86-NEXT: movl %eax, %ebx 179; X86-NEXT: xorl %esi, %ebx 180; X86-NEXT: movl %ecx, %edx 181; X86-NEXT: xorl %edi, %edx 182; X86-NEXT: shrdl $1, %edx, %ebx 183; X86-NEXT: andl %edi, %ecx 184; X86-NEXT: sarl %edx 185; X86-NEXT: andl %esi, %eax 186; X86-NEXT: addl %ebx, %eax 187; X86-NEXT: adcl %ecx, %edx 188; X86-NEXT: popl %esi 189; X86-NEXT: popl %edi 190; X86-NEXT: popl %ebx 191; X86-NEXT: retl 192; 193; X64-LABEL: test_fixed_i64: 194; X64: # %bb.0: 195; X64-NEXT: movq %rdi, %rax 196; X64-NEXT: andq %rsi, %rax 197; X64-NEXT: xorq %rsi, %rdi 198; X64-NEXT: sarq %rdi 199; X64-NEXT: addq %rdi, %rax 200; X64-NEXT: retq 201 %and = and i64 %a0, %a1 202 %xor = xor i64 %a1, %a0 203 %shift = ashr i64 %xor, 1 204 %res = add i64 %and, %shift 205 ret i64 %res 206} 207 208define i64 @test_ext_i64(i64 %a0, i64 %a1) nounwind { 209; X86-LABEL: test_ext_i64: 210; X86: # %bb.0: 211; X86-NEXT: pushl %ebx 212; X86-NEXT: pushl %edi 213; X86-NEXT: pushl %esi 214; X86-NEXT: movl {{[0-9]+}}(%esp), %esi 215; X86-NEXT: movl {{[0-9]+}}(%esp), %edi 216; X86-NEXT: movl {{[0-9]+}}(%esp), %eax 217; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx 218; X86-NEXT: movl %eax, %ebx 219; X86-NEXT: xorl %esi, %ebx 220; X86-NEXT: movl %ecx, %edx 221; X86-NEXT: xorl %edi, %edx 222; X86-NEXT: shrdl $1, %edx, %ebx 223; X86-NEXT: andl %edi, %ecx 224; X86-NEXT: sarl %edx 225; X86-NEXT: andl %esi, %eax 226; X86-NEXT: addl %ebx, %eax 227; X86-NEXT: adcl %ecx, %edx 228; X86-NEXT: popl %esi 229; X86-NEXT: popl %edi 230; X86-NEXT: popl %ebx 231; X86-NEXT: retl 232; 233; X64-LABEL: test_ext_i64: 234; X64: # %bb.0: 235; X64-NEXT: movq %rdi, %rax 236; X64-NEXT: andq %rsi, %rax 237; X64-NEXT: xorq %rsi, %rdi 238; X64-NEXT: sarq %rdi 239; X64-NEXT: addq %rdi, %rax 240; X64-NEXT: retq 241 %x0 = sext i64 %a0 to i128 242 %x1 = sext i64 %a1 to i128 243 %sum = add i128 %x0, %x1 244 %shift = ashr i128 %sum, 1 245 %res = trunc i128 %shift to i64 246 ret i64 %res 247} 248