1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=i686-apple-darwin9 -mattr=+sse,+sse2,+sse4.1 | FileCheck %s --check-prefix=X32 3; RUN: llc < %s -mtriple=x86_64-apple-darwin9 -mattr=+sse,+sse2,+sse4.1 | FileCheck %s --check-prefix=X64 4; RUN: llc < %s -mtriple=i686-apple-darwin9 -mattr=+avx | FileCheck %s --check-prefix=X32_AVX --check-prefix=X32_AVX1 5; RUN: llc < %s -mtriple=x86_64-apple-darwin9 -mattr=+avx | FileCheck %s --check-prefix=X64_AVX --check-prefix=X64_AVX1 6; RUN: llc < %s -mtriple=i686-apple-darwin9 -mattr=+avx512f | FileCheck %s --check-prefix=X32_AVX --check-prefix=X32_AVX512 7; RUN: llc < %s -mtriple=x86_64-apple-darwin9 -mattr=+avx512f | FileCheck %s --check-prefix=X64_AVX --check-prefix=X64_AVX512 8 9define i16 @test1(float %f) nounwind { 10; X32-LABEL: test1: 11; X32: ## BB#0: 12; X32-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 13; X32-NEXT: xorps %xmm1, %xmm1 14; X32-NEXT: subss LCPI0_0, %xmm0 15; X32-NEXT: mulss LCPI0_1, %xmm0 16; X32-NEXT: minss LCPI0_2, %xmm0 17; X32-NEXT: maxss %xmm1, %xmm0 18; X32-NEXT: cvttss2si %xmm0, %eax 19; X32-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 20; X32-NEXT: retl 21; 22; X64-LABEL: test1: 23; X64: ## BB#0: 24; X64-NEXT: xorps %xmm1, %xmm1 25; X64-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3] 26; X64-NEXT: subss {{.*}}(%rip), %xmm0 27; X64-NEXT: mulss {{.*}}(%rip), %xmm0 28; X64-NEXT: minss {{.*}}(%rip), %xmm0 29; X64-NEXT: maxss %xmm1, %xmm0 30; X64-NEXT: cvttss2si %xmm0, %eax 31; X64-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 32; X64-NEXT: retq 33; 34; X32_AVX-LABEL: test1: 35; X32_AVX: ## BB#0: 36; X32_AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero 37; X32_AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1 38; X32_AVX-NEXT: vsubss LCPI0_0, %xmm0, %xmm0 39; X32_AVX-NEXT: vmulss LCPI0_1, %xmm0, %xmm0 40; X32_AVX-NEXT: vminss LCPI0_2, %xmm0, %xmm0 41; X32_AVX-NEXT: vmaxss %xmm1, %xmm0, %xmm0 42; X32_AVX-NEXT: vcvttss2si %xmm0, %eax 43; X32_AVX-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 44; X32_AVX-NEXT: retl 45; 46; X64_AVX1-LABEL: test1: 47; X64_AVX1: ## BB#0: 48; X64_AVX1-NEXT: vxorps %xmm1, %xmm1, %xmm1 49; X64_AVX1-NEXT: vblendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3] 50; X64_AVX1-NEXT: vsubss {{.*}}(%rip), %xmm0, %xmm0 51; X64_AVX1-NEXT: vmulss {{.*}}(%rip), %xmm0, %xmm0 52; X64_AVX1-NEXT: vminss {{.*}}(%rip), %xmm0, %xmm0 53; X64_AVX1-NEXT: vmaxss %xmm1, %xmm0, %xmm0 54; X64_AVX1-NEXT: vcvttss2si %xmm0, %eax 55; X64_AVX1-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 56; X64_AVX1-NEXT: retq 57; 58; X64_AVX512-LABEL: test1: 59; X64_AVX512: ## BB#0: 60; X64_AVX512-NEXT: vxorps %xmm1, %xmm1, %xmm1 61; X64_AVX512-NEXT: vmovss {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3] 62; X64_AVX512-NEXT: vsubss {{.*}}(%rip), %xmm0, %xmm0 63; X64_AVX512-NEXT: vmulss {{.*}}(%rip), %xmm0, %xmm0 64; X64_AVX512-NEXT: vminss {{.*}}(%rip), %xmm0, %xmm0 65; X64_AVX512-NEXT: vmaxss %xmm1, %xmm0, %xmm0 66; X64_AVX512-NEXT: vcvttss2si %xmm0, %eax 67; X64_AVX512-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 68; X64_AVX512-NEXT: retq 69 %tmp = insertelement <4 x float> undef, float %f, i32 0 ; <<4 x float>> [#uses=1] 70 %tmp10 = insertelement <4 x float> %tmp, float 0.000000e+00, i32 1 ; <<4 x float>> [#uses=1] 71 %tmp11 = insertelement <4 x float> %tmp10, float 0.000000e+00, i32 2 ; <<4 x float>> [#uses=1] 72 %tmp12 = insertelement <4 x float> %tmp11, float 0.000000e+00, i32 3 ; <<4 x float>> [#uses=1] 73 %tmp28 = tail call <4 x float> @llvm.x86.sse.sub.ss( <4 x float> %tmp12, <4 x float> < float 1.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00 > ) ; <<4 x float>> [#uses=1] 74 %tmp37 = tail call <4 x float> @llvm.x86.sse.mul.ss( <4 x float> %tmp28, <4 x float> < float 5.000000e-01, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00 > ) ; <<4 x float>> [#uses=1] 75 %tmp48 = tail call <4 x float> @llvm.x86.sse.min.ss( <4 x float> %tmp37, <4 x float> < float 6.553500e+04, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00 > ) ; <<4 x float>> [#uses=1] 76 %tmp59 = tail call <4 x float> @llvm.x86.sse.max.ss( <4 x float> %tmp48, <4 x float> zeroinitializer ) ; <<4 x float>> [#uses=1] 77 %tmp.upgrd.1 = tail call i32 @llvm.x86.sse.cvttss2si( <4 x float> %tmp59 ) ; <i32> [#uses=1] 78 %tmp69 = trunc i32 %tmp.upgrd.1 to i16 ; <i16> [#uses=1] 79 ret i16 %tmp69 80} 81 82define i16 @test2(float %f) nounwind { 83; X32-LABEL: test2: 84; X32: ## BB#0: 85; X32-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 86; X32-NEXT: addss LCPI1_0, %xmm0 87; X32-NEXT: mulss LCPI1_1, %xmm0 88; X32-NEXT: minss LCPI1_2, %xmm0 89; X32-NEXT: xorps %xmm1, %xmm1 90; X32-NEXT: maxss %xmm1, %xmm0 91; X32-NEXT: cvttss2si %xmm0, %eax 92; X32-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 93; X32-NEXT: retl 94; 95; X64-LABEL: test2: 96; X64: ## BB#0: 97; X64-NEXT: addss {{.*}}(%rip), %xmm0 98; X64-NEXT: mulss {{.*}}(%rip), %xmm0 99; X64-NEXT: minss {{.*}}(%rip), %xmm0 100; X64-NEXT: xorps %xmm1, %xmm1 101; X64-NEXT: maxss %xmm1, %xmm0 102; X64-NEXT: cvttss2si %xmm0, %eax 103; X64-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 104; X64-NEXT: retq 105; 106; X32_AVX-LABEL: test2: 107; X32_AVX: ## BB#0: 108; X32_AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero 109; X32_AVX-NEXT: vaddss LCPI1_0, %xmm0, %xmm0 110; X32_AVX-NEXT: vmulss LCPI1_1, %xmm0, %xmm0 111; X32_AVX-NEXT: vminss LCPI1_2, %xmm0, %xmm0 112; X32_AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1 113; X32_AVX-NEXT: vmaxss %xmm1, %xmm0, %xmm0 114; X32_AVX-NEXT: vcvttss2si %xmm0, %eax 115; X32_AVX-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 116; X32_AVX-NEXT: retl 117; 118; X64_AVX-LABEL: test2: 119; X64_AVX: ## BB#0: 120; X64_AVX-NEXT: vaddss {{.*}}(%rip), %xmm0, %xmm0 121; X64_AVX-NEXT: vmulss {{.*}}(%rip), %xmm0, %xmm0 122; X64_AVX-NEXT: vminss {{.*}}(%rip), %xmm0, %xmm0 123; X64_AVX-NEXT: vxorps %xmm1, %xmm1, %xmm1 124; X64_AVX-NEXT: vmaxss %xmm1, %xmm0, %xmm0 125; X64_AVX-NEXT: vcvttss2si %xmm0, %eax 126; X64_AVX-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> 127; X64_AVX-NEXT: retq 128 %tmp28 = fsub float %f, 1.000000e+00 ; <float> [#uses=1] 129 %tmp37 = fmul float %tmp28, 5.000000e-01 ; <float> [#uses=1] 130 %tmp375 = insertelement <4 x float> undef, float %tmp37, i32 0 ; <<4 x float>> [#uses=1] 131 %tmp48 = tail call <4 x float> @llvm.x86.sse.min.ss( <4 x float> %tmp375, <4 x float> < float 6.553500e+04, float undef, float undef, float undef > ) ; <<4 x float>> [#uses=1] 132 %tmp59 = tail call <4 x float> @llvm.x86.sse.max.ss( <4 x float> %tmp48, <4 x float> < float 0.000000e+00, float undef, float undef, float undef > ) ; <<4 x float>> [#uses=1] 133 %tmp = tail call i32 @llvm.x86.sse.cvttss2si( <4 x float> %tmp59 ) ; <i32> [#uses=1] 134 %tmp69 = trunc i32 %tmp to i16 ; <i16> [#uses=1] 135 ret i16 %tmp69 136} 137 138declare <4 x float> @llvm.x86.sse.sub.ss(<4 x float>, <4 x float>) 139 140declare <4 x float> @llvm.x86.sse.mul.ss(<4 x float>, <4 x float>) 141 142declare <4 x float> @llvm.x86.sse.min.ss(<4 x float>, <4 x float>) 143 144declare <4 x float> @llvm.x86.sse.max.ss(<4 x float>, <4 x float>) 145 146declare i32 @llvm.x86.sse.cvttss2si(<4 x float>) 147 148declare <4 x float> @llvm.x86.sse41.round.ss(<4 x float>, <4 x float>, i32) 149 150declare <4 x float> @f() 151 152define <4 x float> @test3(<4 x float> %A, float *%b, i32 %C) nounwind { 153; X32-LABEL: test3: 154; X32: ## BB#0: 155; X32-NEXT: movl {{[0-9]+}}(%esp), %eax 156; X32-NEXT: roundss $4, (%eax), %xmm0 157; X32-NEXT: retl 158; 159; X64-LABEL: test3: 160; X64: ## BB#0: 161; X64-NEXT: roundss $4, (%rdi), %xmm0 162; X64-NEXT: retq 163; 164; X32_AVX-LABEL: test3: 165; X32_AVX: ## BB#0: 166; X32_AVX-NEXT: movl {{[0-9]+}}(%esp), %eax 167; X32_AVX-NEXT: vroundss $4, (%eax), %xmm0, %xmm0 168; X32_AVX-NEXT: retl 169; 170; X64_AVX-LABEL: test3: 171; X64_AVX: ## BB#0: 172; X64_AVX-NEXT: vroundss $4, (%rdi), %xmm0, %xmm0 173; X64_AVX-NEXT: retq 174 %a = load float , float *%b 175 %B = insertelement <4 x float> undef, float %a, i32 0 176 %X = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> %A, <4 x float> %B, i32 4) 177 ret <4 x float> %X 178} 179 180define <4 x float> @test4(<4 x float> %A, float *%b, i32 %C) nounwind { 181; X32-LABEL: test4: 182; X32: ## BB#0: 183; X32-NEXT: subl $28, %esp 184; X32-NEXT: movl {{[0-9]+}}(%esp), %eax 185; X32-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 186; X32-NEXT: movaps %xmm0, (%esp) ## 16-byte Spill 187; X32-NEXT: calll _f 188; X32-NEXT: movaps (%esp), %xmm1 ## 16-byte Reload 189; X32-NEXT: roundss $4, %xmm1, %xmm0 190; X32-NEXT: addl $28, %esp 191; X32-NEXT: retl 192; 193; X64-LABEL: test4: 194; X64: ## BB#0: 195; X64-NEXT: subq $24, %rsp 196; X64-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero 197; X64-NEXT: movaps %xmm0, (%rsp) ## 16-byte Spill 198; X64-NEXT: callq _f 199; X64-NEXT: movaps (%rsp), %xmm1 ## 16-byte Reload 200; X64-NEXT: roundss $4, %xmm1, %xmm0 201; X64-NEXT: addq $24, %rsp 202; X64-NEXT: retq 203; 204; X32_AVX-LABEL: test4: 205; X32_AVX: ## BB#0: 206; X32_AVX-NEXT: subl $28, %esp 207; X32_AVX-NEXT: movl {{[0-9]+}}(%esp), %eax 208; X32_AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero 209; X32_AVX-NEXT: vmovaps %xmm0, (%esp) ## 16-byte Spill 210; X32_AVX-NEXT: calll _f 211; X32_AVX-NEXT: vroundss $4, (%esp), %xmm0, %xmm0 ## 16-byte Folded Reload 212; X32_AVX-NEXT: addl $28, %esp 213; X32_AVX-NEXT: retl 214; 215; X64_AVX-LABEL: test4: 216; X64_AVX: ## BB#0: 217; X64_AVX-NEXT: subq $24, %rsp 218; X64_AVX-NEXT: vmovss {{.*#+}} xmm0 = mem[0],zero,zero,zero 219; X64_AVX-NEXT: vmovaps %xmm0, (%rsp) ## 16-byte Spill 220; X64_AVX-NEXT: callq _f 221; X64_AVX-NEXT: vroundss $4, (%rsp), %xmm0, %xmm0 ## 16-byte Folded Reload 222; X64_AVX-NEXT: addq $24, %rsp 223; X64_AVX-NEXT: retq 224 %a = load float , float *%b 225 %B = insertelement <4 x float> undef, float %a, i32 0 226 %q = call <4 x float> @f() 227 %X = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> %q, <4 x float> %B, i32 4) 228 ret <4 x float> %X 229} 230 231; PR13576 232define <2 x double> @test5() nounwind uwtable readnone noinline { 233; X32-LABEL: test5: 234; X32: ## BB#0: ## %entry 235; X32-NEXT: movaps {{.*#+}} xmm0 = [4.569870e+02,1.233210e+02] 236; X32-NEXT: movl $128, %eax 237; X32-NEXT: cvtsi2sdl %eax, %xmm0 238; X32-NEXT: retl 239; 240; X64-LABEL: test5: 241; X64: ## BB#0: ## %entry 242; X64-NEXT: movaps {{.*#+}} xmm0 = [4.569870e+02,1.233210e+02] 243; X64-NEXT: movl $128, %eax 244; X64-NEXT: cvtsi2sdl %eax, %xmm0 245; X64-NEXT: retq 246; 247; X32_AVX-LABEL: test5: 248; X32_AVX: ## BB#0: ## %entry 249; X32_AVX-NEXT: vmovaps {{.*#+}} xmm0 = [4.569870e+02,1.233210e+02] 250; X32_AVX-NEXT: movl $128, %eax 251; X32_AVX-NEXT: vcvtsi2sdl %eax, %xmm0, %xmm0 252; X32_AVX-NEXT: retl 253; 254; X64_AVX-LABEL: test5: 255; X64_AVX: ## BB#0: ## %entry 256; X64_AVX-NEXT: vmovaps {{.*#+}} xmm0 = [4.569870e+02,1.233210e+02] 257; X64_AVX-NEXT: movl $128, %eax 258; X64_AVX-NEXT: vcvtsi2sdl %eax, %xmm0, %xmm0 259; X64_AVX-NEXT: retq 260entry: 261 %0 = tail call <2 x double> @llvm.x86.sse2.cvtsi2sd(<2 x double> <double 4.569870e+02, double 1.233210e+02>, i32 128) nounwind readnone 262 ret <2 x double> %0 263} 264 265declare <2 x double> @llvm.x86.sse2.cvtsi2sd(<2 x double>, i32) nounwind readnone 266 267define <4 x float> @minss_fold(float* %x, <4 x float> %y) { 268; X32-LABEL: minss_fold: 269; X32: ## BB#0: ## %entry 270; X32-NEXT: movl {{[0-9]+}}(%esp), %eax 271; X32-NEXT: minss (%eax), %xmm0 272; X32-NEXT: retl 273; 274; X64-LABEL: minss_fold: 275; X64: ## BB#0: ## %entry 276; X64-NEXT: minss (%rdi), %xmm0 277; X64-NEXT: retq 278; 279; X32_AVX-LABEL: minss_fold: 280; X32_AVX: ## BB#0: ## %entry 281; X32_AVX-NEXT: movl {{[0-9]+}}(%esp), %eax 282; X32_AVX-NEXT: vminss (%eax), %xmm0, %xmm0 283; X32_AVX-NEXT: retl 284; 285; X64_AVX-LABEL: minss_fold: 286; X64_AVX: ## BB#0: ## %entry 287; X64_AVX-NEXT: vminss (%rdi), %xmm0, %xmm0 288; X64_AVX-NEXT: retq 289entry: 290 %0 = load float, float* %x, align 1 291 %vecinit.i = insertelement <4 x float> undef, float %0, i32 0 292 %vecinit2.i = insertelement <4 x float> %vecinit.i, float 0.000000e+00, i32 1 293 %vecinit3.i = insertelement <4 x float> %vecinit2.i, float 0.000000e+00, i32 2 294 %vecinit4.i = insertelement <4 x float> %vecinit3.i, float 0.000000e+00, i32 3 295 %1 = tail call <4 x float> @llvm.x86.sse.min.ss(<4 x float> %y, <4 x float> %vecinit4.i) 296 ret <4 x float> %1 297} 298 299define <4 x float> @maxss_fold(float* %x, <4 x float> %y) { 300; X32-LABEL: maxss_fold: 301; X32: ## BB#0: ## %entry 302; X32-NEXT: movl {{[0-9]+}}(%esp), %eax 303; X32-NEXT: maxss (%eax), %xmm0 304; X32-NEXT: retl 305; 306; X64-LABEL: maxss_fold: 307; X64: ## BB#0: ## %entry 308; X64-NEXT: maxss (%rdi), %xmm0 309; X64-NEXT: retq 310; 311; X32_AVX-LABEL: maxss_fold: 312; X32_AVX: ## BB#0: ## %entry 313; X32_AVX-NEXT: movl {{[0-9]+}}(%esp), %eax 314; X32_AVX-NEXT: vmaxss (%eax), %xmm0, %xmm0 315; X32_AVX-NEXT: retl 316; 317; X64_AVX-LABEL: maxss_fold: 318; X64_AVX: ## BB#0: ## %entry 319; X64_AVX-NEXT: vmaxss (%rdi), %xmm0, %xmm0 320; X64_AVX-NEXT: retq 321entry: 322 %0 = load float, float* %x, align 1 323 %vecinit.i = insertelement <4 x float> undef, float %0, i32 0 324 %vecinit2.i = insertelement <4 x float> %vecinit.i, float 0.000000e+00, i32 1 325 %vecinit3.i = insertelement <4 x float> %vecinit2.i, float 0.000000e+00, i32 2 326 %vecinit4.i = insertelement <4 x float> %vecinit3.i, float 0.000000e+00, i32 3 327 %1 = tail call <4 x float> @llvm.x86.sse.max.ss(<4 x float> %y, <4 x float> %vecinit4.i) 328 ret <4 x float> %1 329} 330 331define <4 x float> @cmpss_fold(float* %x, <4 x float> %y) { 332; X32-LABEL: cmpss_fold: 333; X32: ## BB#0: ## %entry 334; X32-NEXT: movl {{[0-9]+}}(%esp), %eax 335; X32-NEXT: cmpeqss (%eax), %xmm0 336; X32-NEXT: retl 337; 338; X64-LABEL: cmpss_fold: 339; X64: ## BB#0: ## %entry 340; X64-NEXT: cmpeqss (%rdi), %xmm0 341; X64-NEXT: retq 342; 343; X32_AVX-LABEL: cmpss_fold: 344; X32_AVX: ## BB#0: ## %entry 345; X32_AVX-NEXT: movl {{[0-9]+}}(%esp), %eax 346; X32_AVX-NEXT: vcmpeqss (%eax), %xmm0, %xmm0 347; X32_AVX-NEXT: retl 348; 349; X64_AVX-LABEL: cmpss_fold: 350; X64_AVX: ## BB#0: ## %entry 351; X64_AVX-NEXT: vcmpeqss (%rdi), %xmm0, %xmm0 352; X64_AVX-NEXT: retq 353entry: 354 %0 = load float, float* %x, align 1 355 %vecinit.i = insertelement <4 x float> undef, float %0, i32 0 356 %vecinit2.i = insertelement <4 x float> %vecinit.i, float 0.000000e+00, i32 1 357 %vecinit3.i = insertelement <4 x float> %vecinit2.i, float 0.000000e+00, i32 2 358 %vecinit4.i = insertelement <4 x float> %vecinit3.i, float 0.000000e+00, i32 3 359 %1 = tail call <4 x float> @llvm.x86.sse.cmp.ss(<4 x float> %y, <4 x float> %vecinit4.i, i8 0) 360 ret <4 x float> %1 361} 362declare <4 x float> @llvm.x86.sse.cmp.ss(<4 x float>, <4 x float>, i8) nounwind readnone 363