756 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; REQUIRES: x86-registered-target,sparc-registered-target3; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-linux" | FileCheck %s --check-prefixes=CHECK,DOUBLE-4BYTE-ALIGN4; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-win32" | FileCheck %s --check-prefixes=CHECK,DOUBLE-8BYTE-ALIGN5; RUN: opt < %s -passes=instcombine -S -mtriple "x86_64-pc-win32" | FileCheck %s --check-prefixes=CHECK,DOUBLE-8BYTE-ALIGN6; RUN: opt < %s -passes=instcombine -S -mtriple "i386-pc-mingw32" | FileCheck %s --check-prefixes=CHECK,DOUBLE-8BYTE-ALIGN7; RUN: opt < %s -passes=instcombine -S -mtriple "x86_64-pc-mingw32" | FileCheck %s --check-prefixes=CHECK,DOUBLE-8BYTE-ALIGN8; RUN: opt < %s -passes=instcombine -S -mtriple "sparc-sun-solaris" | FileCheck %s --check-prefixes=CHECK,DOUBLE-8BYTE-ALIGN9; RUN: opt < %s -passes=instcombine -S -mtriple "x86_64-pc-win32" -enable-debugify 2>&1 | FileCheck --check-prefix=DBG-VALID %s10 11declare double @floor(double)12declare double @ceil(double)13declare double @round(double)14declare double @roundeven(double)15declare double @nearbyint(double)16declare double @trunc(double)17declare double @fabs(double)18 19declare double @llvm.ceil.f64(double)20declare <2 x double> @llvm.ceil.v2f64(<2 x double>)21 22declare double @llvm.fabs.f64(double)23declare <2 x double> @llvm.fabs.v2f64(<2 x double>)24 25declare double @llvm.floor.f64(double)26declare <2 x double> @llvm.floor.v2f64(<2 x double>)27 28declare double @llvm.nearbyint.f64(double)29declare <2 x double> @llvm.nearbyint.v2f64(<2 x double>)30 31declare float @llvm.rint.f32(float)32declare <2 x float> @llvm.rint.v2f32(<2 x float>)33 34declare double @llvm.round.f64(double)35declare <2 x double> @llvm.round.v2f64(<2 x double>)36 37declare double @llvm.roundeven.f64(double)38declare <2 x double> @llvm.roundeven.v2f64(<2 x double>)39 40declare double @llvm.trunc.f64(double)41declare <2 x double> @llvm.trunc.v2f64(<2 x double>)42 43define float @test_shrink_libcall_floor(float %C) {44; CHECK-LABEL: @test_shrink_libcall_floor(45; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.floor.f32(float [[C:%.*]])46; CHECK-NEXT: ret float [[TMP1]]47;48 %D = fpext float %C to double49 ; --> floorf50 %E = call double @floor(double %D)51 %F = fptrunc double %E to float52 ret float %F53}54 55define float @test_shrink_libcall_ceil(float %C) {56; CHECK-LABEL: @test_shrink_libcall_ceil(57; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.ceil.f32(float [[C:%.*]])58; CHECK-NEXT: ret float [[TMP1]]59;60 %D = fpext float %C to double61 ; --> ceilf62 %E = call double @ceil(double %D)63 %F = fptrunc double %E to float64 ret float %F65}66 67define float @test_shrink_libcall_round(float %C) {68; CHECK-LABEL: @test_shrink_libcall_round(69; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.round.f32(float [[C:%.*]])70; CHECK-NEXT: ret float [[TMP1]]71;72 %D = fpext float %C to double73 ; --> roundf74 %E = call double @round(double %D)75 %F = fptrunc double %E to float76 ret float %F77}78 79define float @test_shrink_libcall_roundeven(float %C) {80; CHECK-LABEL: @test_shrink_libcall_roundeven(81; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.roundeven.f32(float [[C:%.*]])82; CHECK-NEXT: ret float [[TMP1]]83;84 %D = fpext float %C to double85 ; --> roundeven86 %E = call double @roundeven(double %D)87 %F = fptrunc double %E to float88 ret float %F89}90 91define float @test_shrink_libcall_nearbyint(float %C) {92; CHECK-LABEL: @test_shrink_libcall_nearbyint(93; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.nearbyint.f32(float [[C:%.*]])94; CHECK-NEXT: ret float [[TMP1]]95;96 %D = fpext float %C to double97 ; --> nearbyintf98 %E = call double @nearbyint(double %D)99 %F = fptrunc double %E to float100 ret float %F101}102 103define float @test_shrink_libcall_trunc(float %C) {104; CHECK-LABEL: @test_shrink_libcall_trunc(105; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.trunc.f32(float [[C:%.*]])106; CHECK-NEXT: ret float [[TMP1]]107;108 %D = fpext float %C to double109 ; --> truncf110 %E = call double @trunc(double %D)111 %F = fptrunc double %E to float112 ret float %F113}114 115; This is replaced with the intrinsic, which does the right thing on116; tested platforms.117define float @test_shrink_libcall_fabs(float %C) {118; CHECK-LABEL: @test_shrink_libcall_fabs(119; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float [[C:%.*]])120; CHECK-NEXT: ret float [[TMP1]]121;122 %D = fpext float %C to double123 %E = call double @fabs(double %D)124 %F = fptrunc double %E to float125 ret float %F126}127 128; Make sure fast math flags are preserved129define float @test_shrink_libcall_fabs_fast(float %C) {130; CHECK-LABEL: @test_shrink_libcall_fabs_fast(131; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.fabs.f32(float [[C:%.*]])132; CHECK-NEXT: ret float [[TMP1]]133;134 %D = fpext float %C to double135 %E = call fast double @fabs(double %D)136 %F = fptrunc double %E to float137 ret float %F138}139 140define float @test_shrink_intrin_ceil(float %C) {141; CHECK-LABEL: @test_shrink_intrin_ceil(142; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.ceil.f32(float [[C:%.*]])143; CHECK-NEXT: ret float [[TMP1]]144;145 %D = fpext float %C to double146 %E = call double @llvm.ceil.f64(double %D)147 %F = fptrunc double %E to float148 ret float %F149}150 151define float @test_shrink_intrin_fabs(float %C) {152; CHECK-LABEL: @test_shrink_intrin_fabs(153; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float [[C:%.*]])154; CHECK-NEXT: ret float [[TMP1]]155;156 %D = fpext float %C to double157 %E = call double @llvm.fabs.f64(double %D)158 %F = fptrunc double %E to float159 ret float %F160}161 162define float @test_shrink_intrin_floor(float %C) {163; CHECK-LABEL: @test_shrink_intrin_floor(164; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.floor.f32(float [[C:%.*]])165; CHECK-NEXT: ret float [[TMP1]]166;167 %D = fpext float %C to double168 %E = call double @llvm.floor.f64(double %D)169 %F = fptrunc double %E to float170 ret float %F171}172 173define float @test_shrink_intrin_nearbyint(float %C) {174; CHECK-LABEL: @test_shrink_intrin_nearbyint(175; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.nearbyint.f32(float [[C:%.*]])176; CHECK-NEXT: ret float [[TMP1]]177;178 %D = fpext float %C to double179 %E = call double @llvm.nearbyint.f64(double %D)180 %F = fptrunc double %E to float181 ret float %F182}183 184define half @test_shrink_intrin_rint(half %C) {185; CHECK-LABEL: @test_shrink_intrin_rint(186; CHECK-NEXT: [[TMP1:%.*]] = call half @llvm.rint.f16(half [[C:%.*]])187; CHECK-NEXT: ret half [[TMP1]]188;189 %D = fpext half %C to float190 %E = call float @llvm.rint.f32(float %D)191 %F = fptrunc float %E to half192 ret half %F193}194 195define float @test_shrink_intrin_round(float %C) {196; CHECK-LABEL: @test_shrink_intrin_round(197; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.round.f32(float [[C:%.*]])198; CHECK-NEXT: ret float [[TMP1]]199;200 %D = fpext float %C to double201 %E = call double @llvm.round.f64(double %D)202 %F = fptrunc double %E to float203 ret float %F204}205 206define float @test_shrink_intrin_roundeven(float %C) {207; CHECK-LABEL: @test_shrink_intrin_roundeven(208; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.roundeven.f32(float [[C:%.*]])209; CHECK-NEXT: ret float [[TMP1]]210;211 %D = fpext float %C to double212 %E = call double @llvm.roundeven.f64(double %D)213 %F = fptrunc double %E to float214 ret float %F215}216 217define float @test_shrink_intrin_trunc(float %C) {218; CHECK-LABEL: @test_shrink_intrin_trunc(219; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.trunc.f32(float [[C:%.*]])220; CHECK-NEXT: ret float [[TMP1]]221;222 %D = fpext float %C to double223 %E = call double @llvm.trunc.f64(double %D)224 %F = fptrunc double %E to float225 ret float %F226}227 228declare void @use_v2f64(<2 x double>)229declare void @use_v2f32(<2 x float>)230 231define <2 x float> @test_shrink_intrin_ceil_multi_use(<2 x float> %C) {232; CHECK-LABEL: @test_shrink_intrin_ceil_multi_use(233; CHECK-NEXT: [[D:%.*]] = fpext <2 x float> [[C:%.*]] to <2 x double>234; CHECK-NEXT: [[E:%.*]] = call <2 x double> @llvm.ceil.v2f64(<2 x double> [[D]])235; CHECK-NEXT: [[F:%.*]] = fptrunc <2 x double> [[E]] to <2 x float>236; CHECK-NEXT: call void @use_v2f64(<2 x double> [[D]])237; CHECK-NEXT: ret <2 x float> [[F]]238;239 %D = fpext <2 x float> %C to <2 x double>240 %E = call <2 x double> @llvm.ceil.v2f64(<2 x double> %D)241 %F = fptrunc <2 x double> %E to <2 x float>242 call void @use_v2f64(<2 x double> %D)243 ret <2 x float> %F244}245 246define <2 x float> @test_shrink_intrin_fabs_multi_use(<2 x float> %C) {247; CHECK-LABEL: @test_shrink_intrin_fabs_multi_use(248; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[C:%.*]])249; CHECK-NEXT: [[E:%.*]] = fpext <2 x float> [[TMP1]] to <2 x double>250; CHECK-NEXT: call void @use_v2f64(<2 x double> [[E]])251; CHECK-NEXT: ret <2 x float> [[TMP1]]252;253 %D = fpext <2 x float> %C to <2 x double>254 %E = call <2 x double> @llvm.fabs.v2f64(<2 x double> %D)255 %F = fptrunc <2 x double> %E to <2 x float>256 call void @use_v2f64(<2 x double> %E)257 ret <2 x float> %F258}259 260define <2 x float> @test_shrink_intrin_floor_multi_use(<2 x float> %C) {261; CHECK-LABEL: @test_shrink_intrin_floor_multi_use(262; CHECK-NEXT: [[D:%.*]] = fpext <2 x float> [[C:%.*]] to <2 x double>263; CHECK-NEXT: [[E:%.*]] = call <2 x double> @llvm.floor.v2f64(<2 x double> [[D]])264; CHECK-NEXT: [[F:%.*]] = fptrunc <2 x double> [[E]] to <2 x float>265; CHECK-NEXT: call void @use_v2f64(<2 x double> [[D]])266; CHECK-NEXT: call void @use_v2f64(<2 x double> [[E]])267; CHECK-NEXT: ret <2 x float> [[F]]268;269 %D = fpext <2 x float> %C to <2 x double>270 %E = call <2 x double> @llvm.floor.v2f64(<2 x double> %D)271 %F = fptrunc <2 x double> %E to <2 x float>272 call void @use_v2f64(<2 x double> %D)273 call void @use_v2f64(<2 x double> %E)274 ret <2 x float> %F275}276 277define <2 x float> @test_shrink_intrin_nearbyint_multi_use(<2 x float> %C) {278; CHECK-LABEL: @test_shrink_intrin_nearbyint_multi_use(279; CHECK-NEXT: [[D:%.*]] = fpext <2 x float> [[C:%.*]] to <2 x double>280; CHECK-NEXT: [[E:%.*]] = call <2 x double> @llvm.nearbyint.v2f64(<2 x double> [[D]])281; CHECK-NEXT: [[F:%.*]] = fptrunc <2 x double> [[E]] to <2 x float>282; CHECK-NEXT: call void @use_v2f64(<2 x double> [[D]])283; CHECK-NEXT: ret <2 x float> [[F]]284;285 %D = fpext <2 x float> %C to <2 x double>286 %E = call <2 x double> @llvm.nearbyint.v2f64(<2 x double> %D)287 %F = fptrunc <2 x double> %E to <2 x float>288 call void @use_v2f64(<2 x double> %D)289 ret <2 x float> %F290}291 292define <2 x half> @test_shrink_intrin_rint_multi_use(<2 x half> %C) {293; CHECK-LABEL: @test_shrink_intrin_rint_multi_use(294; CHECK-NEXT: [[TMP1:%.*]] = call <2 x half> @llvm.rint.v2f16(<2 x half> [[C:%.*]])295; CHECK-NEXT: [[E:%.*]] = fpext <2 x half> [[TMP1]] to <2 x float>296; CHECK-NEXT: call void @use_v2f32(<2 x float> [[E]])297; CHECK-NEXT: ret <2 x half> [[TMP1]]298;299 %D = fpext <2 x half> %C to <2 x float>300 %E = call <2 x float> @llvm.rint.v2f32(<2 x float> %D)301 %F = fptrunc <2 x float> %E to <2 x half>302 call void @use_v2f32(<2 x float> %E)303 ret <2 x half> %F304}305 306define <2 x float> @test_shrink_intrin_round_multi_use(<2 x float> %C) {307; CHECK-LABEL: @test_shrink_intrin_round_multi_use(308; CHECK-NEXT: [[D:%.*]] = fpext <2 x float> [[C:%.*]] to <2 x double>309; CHECK-NEXT: [[E:%.*]] = call <2 x double> @llvm.round.v2f64(<2 x double> [[D]])310; CHECK-NEXT: [[F:%.*]] = fptrunc <2 x double> [[E]] to <2 x float>311; CHECK-NEXT: call void @use_v2f64(<2 x double> [[D]])312; CHECK-NEXT: call void @use_v2f64(<2 x double> [[E]])313; CHECK-NEXT: ret <2 x float> [[F]]314;315 %D = fpext <2 x float> %C to <2 x double>316 %E = call <2 x double> @llvm.round.v2f64(<2 x double> %D)317 %F = fptrunc <2 x double> %E to <2 x float>318 call void @use_v2f64(<2 x double> %D)319 call void @use_v2f64(<2 x double> %E)320 ret <2 x float> %F321}322 323define <2 x float> @test_shrink_intrin_roundeven_multi_use(<2 x float> %C) {324; CHECK-LABEL: @test_shrink_intrin_roundeven_multi_use(325; CHECK-NEXT: [[D:%.*]] = fpext <2 x float> [[C:%.*]] to <2 x double>326; CHECK-NEXT: [[E:%.*]] = call <2 x double> @llvm.roundeven.v2f64(<2 x double> [[D]])327; CHECK-NEXT: [[F:%.*]] = fptrunc <2 x double> [[E]] to <2 x float>328; CHECK-NEXT: call void @use_v2f64(<2 x double> [[D]])329; CHECK-NEXT: call void @use_v2f64(<2 x double> [[E]])330; CHECK-NEXT: ret <2 x float> [[F]]331;332 %D = fpext <2 x float> %C to <2 x double>333 %E = call <2 x double> @llvm.roundeven.v2f64(<2 x double> %D)334 %F = fptrunc <2 x double> %E to <2 x float>335 call void @use_v2f64(<2 x double> %D)336 call void @use_v2f64(<2 x double> %E)337 ret <2 x float> %F338}339 340define <2 x float> @test_shrink_intrin_trunc_multi_use(<2 x float> %C) {341; CHECK-LABEL: @test_shrink_intrin_trunc_multi_use(342; CHECK-NEXT: [[D:%.*]] = fpext <2 x float> [[C:%.*]] to <2 x double>343; CHECK-NEXT: [[E:%.*]] = call <2 x double> @llvm.trunc.v2f64(<2 x double> [[D]])344; CHECK-NEXT: [[F:%.*]] = fptrunc <2 x double> [[E]] to <2 x float>345; CHECK-NEXT: call void @use_v2f64(<2 x double> [[D]])346; CHECK-NEXT: ret <2 x float> [[F]]347;348 %D = fpext <2 x float> %C to <2 x double>349 %E = call <2 x double> @llvm.trunc.v2f64(<2 x double> %D)350 %F = fptrunc <2 x double> %E to <2 x float>351 call void @use_v2f64(<2 x double> %D)352 ret <2 x float> %F353}354 355; Make sure fast math flags are preserved356define float @test_shrink_intrin_fabs_fast(float %C) {357; CHECK-LABEL: @test_shrink_intrin_fabs_fast(358; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.fabs.f32(float [[C:%.*]])359; CHECK-NEXT: ret float [[TMP1]]360;361 %D = fpext float %C to double362 %E = call fast double @llvm.fabs.f64(double %D)363 %F = fptrunc double %E to float364 ret float %F365}366 367define float @test_no_shrink_intrin_floor(double %D) {368; CHECK-LABEL: @test_no_shrink_intrin_floor(369; CHECK-NEXT: [[E:%.*]] = call double @llvm.floor.f64(double [[D:%.*]])370; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to float371; CHECK-NEXT: ret float [[F]]372;373 %E = call double @llvm.floor.f64(double %D)374 %F = fptrunc double %E to float375 ret float %F376}377 378define float @test_no_shrink_intrin_ceil(double %D) {379; CHECK-LABEL: @test_no_shrink_intrin_ceil(380; CHECK-NEXT: [[E:%.*]] = call double @llvm.ceil.f64(double [[D:%.*]])381; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to float382; CHECK-NEXT: ret float [[F]]383;384 %E = call double @llvm.ceil.f64(double %D)385 %F = fptrunc double %E to float386 ret float %F387}388 389define float @test_no_shrink_intrin_round(double %D) {390; CHECK-LABEL: @test_no_shrink_intrin_round(391; CHECK-NEXT: [[E:%.*]] = call double @llvm.round.f64(double [[D:%.*]])392; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to float393; CHECK-NEXT: ret float [[F]]394;395 %E = call double @llvm.round.f64(double %D)396 %F = fptrunc double %E to float397 ret float %F398}399 400define float @test_no_shrink_intrin_roundeven(double %D) {401; CHECK-LABEL: @test_no_shrink_intrin_roundeven(402; CHECK-NEXT: [[E:%.*]] = call double @llvm.roundeven.f64(double [[D:%.*]])403; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to float404; CHECK-NEXT: ret float [[F]]405;406 %E = call double @llvm.roundeven.f64(double %D)407 %F = fptrunc double %E to float408 ret float %F409}410 411define float @test_no_shrink_intrin_nearbyint(double %D) {412; CHECK-LABEL: @test_no_shrink_intrin_nearbyint(413; CHECK-NEXT: [[E:%.*]] = call double @llvm.nearbyint.f64(double [[D:%.*]])414; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to float415; CHECK-NEXT: ret float [[F]]416;417 %E = call double @llvm.nearbyint.f64(double %D)418 %F = fptrunc double %E to float419 ret float %F420}421 422define float @test_no_shrink_intrin_trunc(double %D) {423; CHECK-LABEL: @test_no_shrink_intrin_trunc(424; CHECK-NEXT: [[E:%.*]] = call double @llvm.trunc.f64(double [[D:%.*]])425; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to float426; CHECK-NEXT: ret float [[F]]427;428 %E = call double @llvm.trunc.f64(double %D)429 %F = fptrunc double %E to float430 ret float %F431}432 433define float @test_shrink_intrin_fabs_double_src(double %D) {434; CHECK-LABEL: @test_shrink_intrin_fabs_double_src(435; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[D:%.*]] to float436; CHECK-NEXT: [[F:%.*]] = call float @llvm.fabs.f32(float [[TMP1]])437; CHECK-NEXT: ret float [[F]]438;439 %E = call double @llvm.fabs.f64(double %D)440 %F = fptrunc double %E to float441 ret float %F442}443 444; Make sure fast math flags are preserved445define float @test_shrink_intrin_fabs_fast_double_src(double %D) {446; CHECK-LABEL: @test_shrink_intrin_fabs_fast_double_src(447; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[D:%.*]] to float448; CHECK-NEXT: [[F:%.*]] = call fast float @llvm.fabs.f32(float [[TMP1]])449; CHECK-NEXT: ret float [[F]]450;451 %E = call fast double @llvm.fabs.f64(double %D)452 %F = fptrunc fast double %E to float453 ret float %F454}455 456define float @test_shrink_float_convertible_constant_intrin_floor() {457; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_floor(458; CHECK-NEXT: ret float 2.000000e+00459;460 %E = call double @llvm.floor.f64(double 2.1)461 %F = fptrunc double %E to float462 ret float %F463}464 465define float @test_shrink_float_convertible_constant_intrin_ceil() {466; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_ceil(467; CHECK-NEXT: ret float 3.000000e+00468;469 %E = call double @llvm.ceil.f64(double 2.1)470 %F = fptrunc double %E to float471 ret float %F472}473 474define float @test_shrink_float_convertible_constant_intrin_round() {475; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_round(476; CHECK-NEXT: ret float 2.000000e+00477;478 %E = call double @llvm.round.f64(double 2.1)479 %F = fptrunc double %E to float480 ret float %F481}482 483define float @test_shrink_float_convertible_constant_intrin_roundeven() {484; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_roundeven(485; CHECK-NEXT: ret float 2.000000e+00486;487 %E = call double @llvm.roundeven.f64(double 2.1)488 %F = fptrunc double %E to float489 ret float %F490}491 492define float @test_shrink_float_convertible_constant_intrin_nearbyint() {493; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_nearbyint(494; CHECK-NEXT: ret float 2.000000e+00495;496 %E = call double @llvm.nearbyint.f64(double 2.1)497 %F = fptrunc double %E to float498 ret float %F499}500 501define float @test_shrink_float_convertible_constant_intrin_trunc() {502; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_trunc(503; CHECK-NEXT: ret float 2.000000e+00504;505 %E = call double @llvm.trunc.f64(double 2.1)506 %F = fptrunc double %E to float507 ret float %F508}509 510define float @test_shrink_float_convertible_constant_intrin_fabs() {511; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_fabs(512; CHECK-NEXT: ret float 0x4000CCCCC0000000513;514 %E = call double @llvm.fabs.f64(double 2.1)515 %F = fptrunc double %E to float516 ret float %F517}518 519; Make sure fast math flags are preserved520define float @test_shrink_float_convertible_constant_intrin_fabs_fast() {521; CHECK-LABEL: @test_shrink_float_convertible_constant_intrin_fabs_fast(522; CHECK-NEXT: ret float 0x4000CCCCC0000000523;524 %E = call fast double @llvm.fabs.f64(double 2.1)525 %F = fptrunc double %E to float526 ret float %F527}528 529define half @test_no_shrink_mismatched_type_intrin_floor(double %D) {530; CHECK-LABEL: @test_no_shrink_mismatched_type_intrin_floor(531; CHECK-NEXT: [[E:%.*]] = call double @llvm.floor.f64(double [[D:%.*]])532; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to half533; CHECK-NEXT: ret half [[F]]534;535 %E = call double @llvm.floor.f64(double %D)536 %F = fptrunc double %E to half537 ret half %F538}539 540define half @test_no_shrink_mismatched_type_intrin_ceil(double %D) {541; CHECK-LABEL: @test_no_shrink_mismatched_type_intrin_ceil(542; CHECK-NEXT: [[E:%.*]] = call double @llvm.ceil.f64(double [[D:%.*]])543; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to half544; CHECK-NEXT: ret half [[F]]545;546 %E = call double @llvm.ceil.f64(double %D)547 %F = fptrunc double %E to half548 ret half %F549}550 551define half @test_no_shrink_mismatched_type_intrin_round(double %D) {552; CHECK-LABEL: @test_no_shrink_mismatched_type_intrin_round(553; CHECK-NEXT: [[E:%.*]] = call double @llvm.round.f64(double [[D:%.*]])554; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to half555; CHECK-NEXT: ret half [[F]]556;557 %E = call double @llvm.round.f64(double %D)558 %F = fptrunc double %E to half559 ret half %F560}561 562define half @test_no_shrink_mismatched_type_intrin_roundeven(double %D) {563; CHECK-LABEL: @test_no_shrink_mismatched_type_intrin_roundeven(564; CHECK-NEXT: [[E:%.*]] = call double @llvm.roundeven.f64(double [[D:%.*]])565; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to half566; CHECK-NEXT: ret half [[F]]567;568 %E = call double @llvm.roundeven.f64(double %D)569 %F = fptrunc double %E to half570 ret half %F571}572 573define half @test_no_shrink_mismatched_type_intrin_nearbyint(double %D) {574; CHECK-LABEL: @test_no_shrink_mismatched_type_intrin_nearbyint(575; CHECK-NEXT: [[E:%.*]] = call double @llvm.nearbyint.f64(double [[D:%.*]])576; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to half577; CHECK-NEXT: ret half [[F]]578;579 %E = call double @llvm.nearbyint.f64(double %D)580 %F = fptrunc double %E to half581 ret half %F582}583 584define half @test_no_shrink_mismatched_type_intrin_trunc(double %D) {585; CHECK-LABEL: @test_no_shrink_mismatched_type_intrin_trunc(586; CHECK-NEXT: [[E:%.*]] = call double @llvm.trunc.f64(double [[D:%.*]])587; CHECK-NEXT: [[F:%.*]] = fptrunc double [[E]] to half588; CHECK-NEXT: ret half [[F]]589;590 %E = call double @llvm.trunc.f64(double %D)591 %F = fptrunc double %E to half592 ret half %F593}594 595define half @test_shrink_mismatched_type_intrin_fabs_double_src(double %D) {596; CHECK-LABEL: @test_shrink_mismatched_type_intrin_fabs_double_src(597; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[D:%.*]] to half598; CHECK-NEXT: [[F:%.*]] = call half @llvm.fabs.f16(half [[TMP1]])599; CHECK-NEXT: ret half [[F]]600;601 %E = call double @llvm.fabs.f64(double %D)602 %F = fptrunc double %E to half603 ret half %F604}605 606; Make sure fast math flags are preserved607define half @test_mismatched_type_intrin_fabs_fast_double_src(double %D) {608; CHECK-LABEL: @test_mismatched_type_intrin_fabs_fast_double_src(609; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[D:%.*]] to half610; CHECK-NEXT: [[F:%.*]] = call fast half @llvm.fabs.f16(half [[TMP1]])611; CHECK-NEXT: ret half [[F]]612;613 %E = call fast double @llvm.fabs.f64(double %D)614 %F = fptrunc fast double %E to half615 ret half %F616}617 618define <2 x double> @test_shrink_intrin_floor_fp16_vec(<2 x half> %C) {619; CHECK-LABEL: @test_shrink_intrin_floor_fp16_vec(620; CHECK-NEXT: [[TMP1:%.*]] = call arcp <2 x half> @llvm.floor.v2f16(<2 x half> [[C:%.*]])621; CHECK-NEXT: [[E:%.*]] = fpext <2 x half> [[TMP1]] to <2 x double>622; CHECK-NEXT: ret <2 x double> [[E]]623;624 %D = fpext <2 x half> %C to <2 x double>625 %E = call arcp <2 x double> @llvm.floor.v2f64(<2 x double> %D)626 ret <2 x double> %E627}628 629define float @test_shrink_intrin_ceil_fp16_src(half %C) {630; CHECK-LABEL: @test_shrink_intrin_ceil_fp16_src(631; CHECK-NEXT: [[TMP1:%.*]] = call half @llvm.ceil.f16(half [[C:%.*]])632; CHECK-NEXT: [[F:%.*]] = fpext half [[TMP1]] to float633; CHECK-NEXT: ret float [[F]]634;635 %D = fpext half %C to double636 %E = call double @llvm.ceil.f64(double %D)637 %F = fptrunc double %E to float638 ret float %F639}640 641define <2 x double> @test_shrink_intrin_round_fp16_vec(<2 x half> %C) {642; CHECK-LABEL: @test_shrink_intrin_round_fp16_vec(643; CHECK-NEXT: [[TMP1:%.*]] = call <2 x half> @llvm.round.v2f16(<2 x half> [[C:%.*]])644; CHECK-NEXT: [[E:%.*]] = fpext <2 x half> [[TMP1]] to <2 x double>645; CHECK-NEXT: ret <2 x double> [[E]]646;647 %D = fpext <2 x half> %C to <2 x double>648 %E = call <2 x double> @llvm.round.v2f64(<2 x double> %D)649 ret <2 x double> %E650}651 652define <2 x double> @test_shrink_intrin_roundeven_fp16_vec(<2 x half> %C) {653; CHECK-LABEL: @test_shrink_intrin_roundeven_fp16_vec(654; CHECK-NEXT: [[TMP1:%.*]] = call <2 x half> @llvm.roundeven.v2f16(<2 x half> [[C:%.*]])655; CHECK-NEXT: [[E:%.*]] = fpext <2 x half> [[TMP1]] to <2 x double>656; CHECK-NEXT: ret <2 x double> [[E]]657;658 %D = fpext <2 x half> %C to <2 x double>659 %E = call <2 x double> @llvm.roundeven.v2f64(<2 x double> %D)660 ret <2 x double> %E661}662 663define float @test_shrink_intrin_nearbyint_fp16_src(half %C) {664; CHECK-LABEL: @test_shrink_intrin_nearbyint_fp16_src(665; CHECK-NEXT: [[TMP1:%.*]] = call half @llvm.nearbyint.f16(half [[C:%.*]])666; CHECK-NEXT: [[F:%.*]] = fpext half [[TMP1]] to float667; CHECK-NEXT: ret float [[F]]668;669 %D = fpext half %C to double670 %E = call double @llvm.nearbyint.f64(double %D)671 %F = fptrunc double %E to float672 ret float %F673}674 675define <2 x double> @test_shrink_intrin_trunc_fp16_src(<2 x half> %C) {676; CHECK-LABEL: @test_shrink_intrin_trunc_fp16_src(677; CHECK-NEXT: [[TMP1:%.*]] = call <2 x half> @llvm.trunc.v2f16(<2 x half> [[C:%.*]])678; CHECK-NEXT: [[E:%.*]] = fpext <2 x half> [[TMP1]] to <2 x double>679; CHECK-NEXT: ret <2 x double> [[E]]680;681 %D = fpext <2 x half> %C to <2 x double>682 %E = call <2 x double> @llvm.trunc.v2f64(<2 x double> %D)683 ret <2 x double> %E684}685 686define float @test_shrink_intrin_fabs_fp16_src(half %C) {687; CHECK-LABEL: @test_shrink_intrin_fabs_fp16_src(688; CHECK-NEXT: [[TMP1:%.*]] = call half @llvm.fabs.f16(half [[C:%.*]])689; CHECK-NEXT: [[F:%.*]] = fpext half [[TMP1]] to float690; CHECK-NEXT: ret float [[F]]691;692 %D = fpext half %C to double693 %E = call double @llvm.fabs.f64(double %D)694 %F = fptrunc double %E to float695 ret float %F696}697 698; Make sure fast math flags are preserved699define float @test_shrink_intrin_fabs_fast_fp16_src(half %C) {700; CHECK-LABEL: @test_shrink_intrin_fabs_fast_fp16_src(701; CHECK-NEXT: [[TMP1:%.*]] = call fast half @llvm.fabs.f16(half [[C:%.*]])702; CHECK-NEXT: [[F:%.*]] = fpext half [[TMP1]] to float703; CHECK-NEXT: ret float [[F]]704;705 %D = fpext half %C to double706 %E = call fast double @llvm.fabs.f64(double %D)707 %F = fptrunc double %E to float708 ret float %F709}710 711define float @test_no_shrink_intrin_floor_multi_use_fpext(half %C) {712; DOUBLE-4BYTE-ALIGN-LABEL: @test_no_shrink_intrin_floor_multi_use_fpext(713; DOUBLE-4BYTE-ALIGN-NEXT: [[D:%.*]] = fpext half [[C:%.*]] to double714; DOUBLE-4BYTE-ALIGN-NEXT: store volatile double [[D]], ptr undef, align 4715; DOUBLE-4BYTE-ALIGN-NEXT: [[E:%.*]] = call double @llvm.floor.f64(double [[D]])716; DOUBLE-4BYTE-ALIGN-NEXT: [[F:%.*]] = fptrunc double [[E]] to float717; DOUBLE-4BYTE-ALIGN-NEXT: ret float [[F]]718;719; DOUBLE-8BYTE-ALIGN-LABEL: @test_no_shrink_intrin_floor_multi_use_fpext(720; DOUBLE-8BYTE-ALIGN-NEXT: [[D:%.*]] = fpext half [[C:%.*]] to double721; DOUBLE-8BYTE-ALIGN-NEXT: store volatile double [[D]], ptr undef, align 8722; DOUBLE-8BYTE-ALIGN-NEXT: [[E:%.*]] = call double @llvm.floor.f64(double [[D]])723; DOUBLE-8BYTE-ALIGN-NEXT: [[F:%.*]] = fptrunc double [[E]] to float724; DOUBLE-8BYTE-ALIGN-NEXT: ret float [[F]]725;726 %D = fpext half %C to double727 store volatile double %D, ptr undef728 %E = call double @llvm.floor.f64(double %D)729 %F = fptrunc double %E to float730 ret float %F731}732 733define float @test_no_shrink_intrin_fabs_multi_use_fpext(half %C) {734; DOUBLE-4BYTE-ALIGN-LABEL: @test_no_shrink_intrin_fabs_multi_use_fpext(735; DOUBLE-4BYTE-ALIGN-NEXT: [[D:%.*]] = fpext half [[C:%.*]] to double736; DOUBLE-4BYTE-ALIGN-NEXT: store volatile double [[D]], ptr undef, align 4737; DOUBLE-4BYTE-ALIGN-NEXT: [[E:%.*]] = call double @llvm.fabs.f64(double [[D]])738; DOUBLE-4BYTE-ALIGN-NEXT: [[F:%.*]] = fptrunc double [[E]] to float739; DOUBLE-4BYTE-ALIGN-NEXT: ret float [[F]]740;741; DOUBLE-8BYTE-ALIGN-LABEL: @test_no_shrink_intrin_fabs_multi_use_fpext(742; DOUBLE-8BYTE-ALIGN-NEXT: [[D:%.*]] = fpext half [[C:%.*]] to double743; DOUBLE-8BYTE-ALIGN-NEXT: store volatile double [[D]], ptr undef, align 8744; DOUBLE-8BYTE-ALIGN-NEXT: [[E:%.*]] = call double @llvm.fabs.f64(double [[D]])745; DOUBLE-8BYTE-ALIGN-NEXT: [[F:%.*]] = fptrunc double [[E]] to float746; DOUBLE-8BYTE-ALIGN-NEXT: ret float [[F]]747;748 %D = fpext half %C to double749 store volatile double %D, ptr undef750 %E = call double @llvm.fabs.f64(double %D)751 %F = fptrunc double %E to float752 ret float %F753}754 755; DBG-VALID: CheckModuleDebugify: PASS756