brintos

brintos / llvm-project-archived public Read only

0
0
Text · 26.6 KiB · 0ccaa9c Raw
593 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3; RUN: opt < %s -passes=instcombine -use-constant-fp-for-fixed-length-splat -use-constant-int-for-fixed-length-splat -S | FileCheck %s4 5; (X < C1) ? C1 : MIN(X, C2)6define float @clamp_float_fast_ordered_strict_maxmin(float %x) {7; CHECK-LABEL: @clamp_float_fast_ordered_strict_maxmin(8; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+029; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+0210; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+0011; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MIN]], float 1.000000e+0012; CHECK-NEXT:    ret float [[R1]]13;14  %cmp2 = fcmp fast olt float %x, 255.015  %min = select i1 %cmp2, float %x, float 255.016  %cmp1 = fcmp fast olt float %x, 1.017  %r = select i1 %cmp1, float 1.0, float %min18  ret float %r19}20 21; (X <= C1) ? C1 : MIN(X, C2)22define float @clamp_float_fast_ordered_nonstrict_maxmin(float %x) {23; CHECK-LABEL: @clamp_float_fast_ordered_nonstrict_maxmin(24; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+0225; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+0226; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+0027; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MIN]], float 1.000000e+0028; CHECK-NEXT:    ret float [[R1]]29;30  %cmp2 = fcmp fast olt float %x, 255.031  %min = select i1 %cmp2, float %x, float 255.032  %cmp1 = fcmp fast ole float %x, 1.033  %r = select i1 %cmp1, float 1.0, float %min34  ret float %r35}36 37; (X > C1) ? C1 : MAX(X, C2)38define float @clamp_float_fast_ordered_strict_minmax(float %x) {39; CHECK-LABEL: @clamp_float_fast_ordered_strict_minmax(40; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+0041; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+0042; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+0243; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MAX]], float 2.550000e+0244; CHECK-NEXT:    ret float [[R1]]45;46  %cmp2 = fcmp fast ogt float %x, 1.047  %max = select i1 %cmp2, float %x, float 1.048  %cmp1 = fcmp fast ogt float %x, 255.049  %r = select i1 %cmp1, float 255.0, float %max50  ret float %r51}52 53; (X >= C1) ? C1 : MAX(X, C2)54define float @clamp_float_fast_ordered_nonstrict_minmax(float %x) {55; CHECK-LABEL: @clamp_float_fast_ordered_nonstrict_minmax(56; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+0057; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+0058; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+0259; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MAX]], float 2.550000e+0260; CHECK-NEXT:    ret float [[R1]]61;62  %cmp2 = fcmp fast ogt float %x, 1.063  %max = select i1 %cmp2, float %x, float 1.064  %cmp1 = fcmp fast oge float %x, 255.065  %r = select i1 %cmp1, float 255.0, float %max66  ret float %r67}68 69 70; The same for unordered71 72; (X < C1) ? C1 : MIN(X, C2)73define float @clamp_float_fast_unordered_strict_maxmin(float %x) {74; CHECK-LABEL: @clamp_float_fast_unordered_strict_maxmin(75; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+0276; CHECK-NEXT:    [[MIN:%.*]] = select nnan ninf i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]77; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+0078; CHECK-NEXT:    [[R:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MIN]], float 1.000000e+0079; CHECK-NEXT:    ret float [[R]]80;81  %cmp2 = fcmp fast ult float %x, 255.082  %min = select i1 %cmp2, float %x, float 255.083  %cmp1 = fcmp fast ult float %x, 1.084  %r = select i1 %cmp1, float 1.0, float %min85  ret float %r86}87 88; (X <= C1) ? C1 : MIN(X, C2)89define float @clamp_float_fast_unordered_nonstrict_maxmin(float %x) {90; CHECK-LABEL: @clamp_float_fast_unordered_nonstrict_maxmin(91; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+0292; CHECK-NEXT:    [[MIN:%.*]] = select nnan ninf i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]93; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+0094; CHECK-NEXT:    [[R:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MIN]], float 1.000000e+0095; CHECK-NEXT:    ret float [[R]]96;97  %cmp2 = fcmp fast ult float %x, 255.098  %min = select i1 %cmp2, float %x, float 255.099  %cmp1 = fcmp fast ule float %x, 1.0100  %r = select i1 %cmp1, float 1.0, float %min101  ret float %r102}103 104; (X > C1) ? C1 : MAX(X, C2)105define float @clamp_float_fast_unordered_strict_minmax(float %x) {106; CHECK-LABEL: @clamp_float_fast_unordered_strict_minmax(107; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp fast ole float [[X:%.*]], 1.000000e+00108; CHECK-NEXT:    [[MAX:%.*]] = select nnan ninf i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]109; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02110; CHECK-NEXT:    [[R:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MAX]], float 2.550000e+02111; CHECK-NEXT:    ret float [[R]]112;113  %cmp2 = fcmp fast ugt float %x, 1.0114  %max = select i1 %cmp2, float %x, float 1.0115  %cmp1 = fcmp fast ugt float %x, 255.0116  %r = select i1 %cmp1, float 255.0, float %max117  ret float %r118}119 120; (X >= C1) ? C1 : MAX(X, C2)121define float @clamp_float_fast_unordered_nonstrict_minmax(float %x) {122; CHECK-LABEL: @clamp_float_fast_unordered_nonstrict_minmax(123; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp fast ole float [[X:%.*]], 1.000000e+00124; CHECK-NEXT:    [[MAX:%.*]] = select nnan ninf i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]125; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02126; CHECK-NEXT:    [[R:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MAX]], float 2.550000e+02127; CHECK-NEXT:    ret float [[R]]128;129  %cmp2 = fcmp fast ugt float %x, 1.0130  %max = select i1 %cmp2, float %x, float 1.0131  %cmp1 = fcmp fast uge float %x, 255.0132  %r = select i1 %cmp1, float 255.0, float %max133  ret float %r134}135 136; Some more checks with fast137 138; (X > 1.0) ? min(x, 255.0) : 1.0139define float @clamp_test_1(float %x) {140; CHECK-LABEL: @clamp_test_1(141; CHECK-NEXT:    [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02142; CHECK-NEXT:    [[INNER_SEL:%.*]] = select nnan ninf i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]143; CHECK-NEXT:    [[OUTER_CMP:%.*]] = fcmp fast oge float [[INNER_SEL]], 1.000000e+00144; CHECK-NEXT:    [[R:%.*]] = select nnan ninf i1 [[OUTER_CMP]], float [[INNER_SEL]], float 1.000000e+00145; CHECK-NEXT:    ret float [[R]]146;147  %inner_cmp = fcmp fast ult float %x, 255.0148  %inner_sel = select i1 %inner_cmp, float %x, float 255.0149  %outer_cmp = fcmp fast ugt float %x, 1.0150  %r = select i1 %outer_cmp, float %inner_sel, float 1.0151  ret float %r152}153 154; And something negative155 156; Like @clamp_test_1 but HighConst < LowConst157define float @clamp_negative_wrong_const(float %x) {158; CHECK-LABEL: @clamp_negative_wrong_const(159; CHECK-NEXT:    [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02160; CHECK-NEXT:    [[INNER_SEL:%.*]] = select nnan ninf i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]161; CHECK-NEXT:    [[OUTER_CMP:%.*]] = fcmp fast ugt float [[X]], 5.120000e+02162; CHECK-NEXT:    [[R:%.*]] = select i1 [[OUTER_CMP]], float [[INNER_SEL]], float 5.120000e+02163; CHECK-NEXT:    ret float [[R]]164;165  %inner_cmp = fcmp fast ult float %x, 255.0166  %inner_sel = select i1 %inner_cmp, float %x, float 255.0167  %outer_cmp = fcmp fast ugt float %x, 512.0168  %r = select i1 %outer_cmp, float %inner_sel, float 512.0169  ret float %r170}171 172; Like @clamp_test_1 but both are min173define float @clamp_negative_same_op(float %x) {174; CHECK-LABEL: @clamp_negative_same_op(175; CHECK-NEXT:    [[OUTER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 1.000000e+00176; CHECK-NEXT:    [[R:%.*]] = select nnan ninf i1 [[OUTER_CMP_INV]], float 1.000000e+00, float [[X]]177; CHECK-NEXT:    ret float [[R]]178;179  %inner_cmp = fcmp fast ult float %x, 255.0180  %inner_sel = select i1 %inner_cmp, float %x, float 255.0181  %outer_cmp = fcmp fast ult float %x, 1.0182  %r = select i1 %outer_cmp, float %inner_sel, float 1.0183  ret float %r184}185 186 187; And now without fast.188 189; First, check that we don't do bad things in the presence of signed zeros190define float @clamp_float_with_zero1(float %x) {191; CHECK-LABEL: @clamp_float_with_zero1(192; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02193; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02194; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ole float [[X]], 0.000000e+00195; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float [[MIN]]196; CHECK-NEXT:    ret float [[R]]197;198  %cmp2 = fcmp fast olt float %x, 255.0199  %min = select i1 %cmp2, float %x, float 255.0200  %cmp1 = fcmp ole float %x, 0.0201  %r = select i1 %cmp1, float 0.0, float %min202  ret float %r203}204 205define float @clamp_float_with_zero2(float %x) {206; CHECK-LABEL: @clamp_float_with_zero2(207; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02208; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02209; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[X]], 0.000000e+00210; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float [[MIN]]211; CHECK-NEXT:    ret float [[R]]212;213  %cmp2 = fcmp fast olt float %x, 255.0214  %min = select i1 %cmp2, float %x, float 255.0215  %cmp1 = fcmp olt float %x, 0.0216  %r = select i1 %cmp1, float 0.0, float %min217  ret float %r218}219 220; Also, here we care more about the ordering of the inner min/max, so221; two times more cases.222; TODO: that is not implemented yet, so these checks are for the223;       future. This means that checks below can just check that224;       "fcmp.*%x" happens twice for each label.225 226; (X < C1) ? C1 : MIN(X, C2)227define float @clamp_float_ordered_strict_maxmin1(float %x) {228; CHECK-LABEL: @clamp_float_ordered_strict_maxmin1(229; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02230; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02231; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00232; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]233; CHECK-NEXT:    ret float [[R]]234;235  %cmp2 = fcmp olt float %x, 255.0                   ; X is NaN => false236  %min = select i1 %cmp2, float %x, float 255.0      ;             255.0237  %cmp1 = fcmp olt float %x, 1.0                     ;             false238  %r = select i1 %cmp1, float 1.0, float %min        ;             min (255.0)239  ret float %r240}241 242define float @clamp_float_ordered_strict_maxmin2(float %x) {243; CHECK-LABEL: @clamp_float_ordered_strict_maxmin2(244; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02245; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]246; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00247; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]248; CHECK-NEXT:    ret float [[R]]249;250  %cmp2 = fcmp ult float %x, 255.0                  ; X is NaN => true251  %min = select i1 %cmp2, float %x, float 255.0     ;             NaN252  %cmp1 = fcmp olt float %x, 1.0                    ;             false253  %r = select i1 %cmp1, float 1.0, float %min       ;             min (NaN)254  ret float %r255}256 257; (X <= C1) ? C1 : MIN(X, C2)258define float @clamp_float_ordered_nonstrict_maxmin1(float %x) {259; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin1(260; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02261; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02262; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00263; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]264; CHECK-NEXT:    ret float [[R]]265;266  %cmp2 = fcmp olt float %x, 255.0                  ; X is NaN => false267  %min = select i1 %cmp2, float %x, float 255.0     ;             255.0268  %cmp1 = fcmp ole float %x, 1.0                    ;             false269  %r = select i1 %cmp1, float 1.0, float %min       ;             min (255.0)270  ret float %r271}272 273define float @clamp_float_ordered_nonstrict_maxmin2(float %x) {274; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin2(275; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02276; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]277; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00278; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]279; CHECK-NEXT:    ret float [[R]]280;281  %cmp2 = fcmp ult float %x, 255.0                  ; x is NaN => true282  %min = select i1 %cmp2, float %x, float 255.0     ;             NaN283  %cmp1 = fcmp ole float %x, 1.0                    ;             false284  %r = select i1 %cmp1, float 1.0, float %min       ;             min (NaN)285  ret float %r286}287 288; (X > C1) ? C1 : MAX(X, C2)289define float @clamp_float_ordered_strict_minmax1(float %x) {290; CHECK-LABEL: @clamp_float_ordered_strict_minmax1(291; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00292; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00293; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02294; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]295; CHECK-NEXT:    ret float [[R]]296;297  %cmp2 = fcmp ogt float %x, 1.0                    ; x is NaN => false298  %max = select i1 %cmp2, float %x, float 1.0       ;             1.0299  %cmp1 = fcmp ogt float %x, 255.0                  ;             false300  %r = select i1 %cmp1, float 255.0, float %max     ;             max (1.0)301  ret float %r302}303 304define float @clamp_float_ordered_strict_minmax2(float %x) {305; CHECK-LABEL: @clamp_float_ordered_strict_minmax2(306; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00307; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]308; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02309; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]310; CHECK-NEXT:    ret float [[R]]311;312  %cmp2 = fcmp ugt float %x, 1.0                    ; x is NaN => true313  %max = select i1 %cmp2, float %x, float 1.0       ;             NaN314  %cmp1 = fcmp ogt float %x, 255.0                  ;             false315  %r = select i1 %cmp1, float 255.0, float %max     ;             max (NaN)316  ret float %r317}318 319; (X >= C1) ? C1 : MAX(X, C2)320define float @clamp_float_ordered_nonstrict_minmax1(float %x) {321; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax1(322; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00323; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00324; CHECK-NEXT:    [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02325; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]326; CHECK-NEXT:    ret float [[R]]327;328  %cmp2 = fcmp ogt float %x, 1.0                    ; x is NaN => false329  %max = select i1 %cmp2, float %x, float 1.0       ;             1.0330  %cmp1 = fcmp oge float %x, 255.0                  ;             false331  %r = select i1 %cmp1, float 255.0, float %max     ;             max (1.0)332  ret float %r333}334 335define float @clamp_float_ordered_nonstrict_minmax2(float %x) {336; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax2(337; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00338; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]339; CHECK-NEXT:    [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02340; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]341; CHECK-NEXT:    ret float [[R]]342;343  %cmp2 = fcmp ugt float %x, 1.0                    ; x is NaN => true344  %max = select i1 %cmp2, float %x, float 1.0       ;             NaN345  %cmp1 = fcmp oge float %x, 255.0                  ;             false346  %r = select i1 %cmp1, float 255.0, float %max     ;             max (NaN)347  ret float %r348}349 350 351; The same for unordered352 353; (X < C1) ? C1 : MIN(X, C2)354define float @clamp_float_unordered_strict_maxmin1(float %x) {355; CHECK-LABEL: @clamp_float_unordered_strict_maxmin1(356; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02357; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02358; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00359; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]360; CHECK-NEXT:    ret float [[R]]361;362  %cmp2 = fcmp olt float %x, 255.0                  ; x is NaN => false363  %min = select i1 %cmp2, float %x, float 255.0     ;             255.0364  %cmp1 = fcmp ult float %x, 1.0                    ;             true365  %r = select i1 %cmp1, float 1.0, float %min       ;             1.0366  ret float %r367}368 369define float @clamp_float_unordered_strict_maxmin2(float %x) {370; CHECK-LABEL: @clamp_float_unordered_strict_maxmin2(371; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02372; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]373; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00374; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]375; CHECK-NEXT:    ret float [[R]]376;377  %cmp2 = fcmp ult float %x, 255.0                  ; x is NaN => true378  %min = select i1 %cmp2, float %x, float 255.0     ;             NaN379  %cmp1 = fcmp ult float %x, 1.0                    ;             true380  %r = select i1 %cmp1, float 1.0, float %min       ;             1.0381  ret float %r382}383 384; (X <= C1) ? C1 : MIN(X, C2)385define float @clamp_float_unordered_nonstrict_maxmin1(float %x) {386; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin1(387; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02388; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02389; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00390; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]391; CHECK-NEXT:    ret float [[R]]392;393  %cmp2 = fcmp olt float %x, 255.0                  ; x is NaN => false394  %min = select i1 %cmp2, float %x, float 255.0     ;             255.0395  %cmp1 = fcmp ule float %x, 1.0                    ;             true396  %r = select i1 %cmp1, float 1.0, float %min       ;             1.0397  ret float %r398}399 400define float @clamp_float_unordered_nonstrict_maxmin2(float %x) {401; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin2(402; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02403; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]404; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00405; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]406; CHECK-NEXT:    ret float [[R]]407;408  %cmp2 = fcmp ult float %x, 255.0                  ; x is NaN => true409  %min = select i1 %cmp2, float %x, float 255.0     ;             NaN410  %cmp1 = fcmp ule float %x, 1.0                    ;             true411  %r = select i1 %cmp1, float 1.0, float %min       ;             1.0412  ret float %r413}414 415; (X > C1) ? C1 : MAX(X, C2)416define float @clamp_float_unordered_strict_minmax1(float %x) {417; CHECK-LABEL: @clamp_float_unordered_strict_minmax1(418; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00419; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00420; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02421; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]422; CHECK-NEXT:    ret float [[R]]423;424  %cmp2 = fcmp ogt float %x, 1.0                    ; x is NaN => false425  %max = select i1 %cmp2, float %x, float 1.0       ;             1.0426  %cmp1 = fcmp ugt float %x, 255.0                  ;             true427  %r = select i1 %cmp1, float 255.0, float %max     ;             255.0428  ret float %r429}430 431define float @clamp_float_unordered_strict_minmax2(float %x) {432; CHECK-LABEL: @clamp_float_unordered_strict_minmax2(433; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00434; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]435; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02436; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]437; CHECK-NEXT:    ret float [[R]]438;439  %cmp2 = fcmp ugt float %x, 1.0                    ; x is NaN => true440  %max = select i1 %cmp2, float %x, float 1.0       ;             NaN441  %cmp1 = fcmp ugt float %x, 255.0                  ;             true442  %r = select i1 %cmp1, float 255.0, float %max     ;             255.0443  ret float %r444}445 446; (X >= C1) ? C1 : MAX(X, C2)447define float @clamp_float_unordered_nonstrict_minmax1(float %x) {448; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax1(449; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00450; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00451; CHECK-NEXT:    [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02452; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]453; CHECK-NEXT:    ret float [[R]]454;455  %cmp2 = fcmp ogt float %x, 1.0                    ; x is NaN => false456  %max = select i1 %cmp2, float %x, float 1.0       ;             1.0457  %cmp1 = fcmp uge float %x, 255.0                  ;             true458  %r = select i1 %cmp1, float 255.0, float %max     ;             255.0459  ret float %r460}461 462define float @clamp_float_unordered_nonstrict_minmax2(float %x) {463; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax2(464; CHECK-NEXT:    [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00465; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]466; CHECK-NEXT:    [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02467; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]468; CHECK-NEXT:    ret float [[R]]469;470  %cmp2 = fcmp ugt float %x, 1.0                    ; x is NaN => true471  %max = select i1 %cmp2, float %x, float 1.0       ;             NaN472  %cmp1 = fcmp uge float %x, 255.0                  ;             true473  %r = select i1 %cmp1, float 255.0, float %max     ;             255.0474  ret float %r475}476 477;; Check casts behavior478define float @ui32_clamp_and_cast_to_float(i32 %x) {479; CHECK-LABEL: @ui32_clamp_and_cast_to_float(480; CHECK-NEXT:    [[LO_CMP:%.*]] = icmp eq i32 [[X:%.*]], 0481; CHECK-NEXT:    [[MIN1:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 255)482; CHECK-NEXT:    [[MIN:%.*]] = uitofp nneg i32 [[MIN1]] to float483; CHECK-NEXT:    [[R:%.*]] = select i1 [[LO_CMP]], float 1.000000e+00, float [[MIN]]484; CHECK-NEXT:    ret float [[R]]485;486  %f_x = uitofp i32 %x to float487  %up_cmp = icmp ugt i32 %x, 255488  %lo_cmp = icmp ult i32 %x, 1489  %min = select i1 %up_cmp, float 255.0, float %f_x490  %r = select i1 %lo_cmp, float 1.0, float %min491  ret float %r492}493 494define float @ui64_clamp_and_cast_to_float(i64 %x) {495; CHECK-LABEL: @ui64_clamp_and_cast_to_float(496; CHECK-NEXT:    [[LO_CMP:%.*]] = icmp eq i64 [[X:%.*]], 0497; CHECK-NEXT:    [[MIN1:%.*]] = call i64 @llvm.umin.i64(i64 [[X]], i64 255)498; CHECK-NEXT:    [[MIN:%.*]] = uitofp nneg i64 [[MIN1]] to float499; CHECK-NEXT:    [[R:%.*]] = select i1 [[LO_CMP]], float 1.000000e+00, float [[MIN]]500; CHECK-NEXT:    ret float [[R]]501;502  %f_x = uitofp i64 %x to float503  %up_cmp = icmp ugt i64 %x, 255504  %lo_cmp = icmp ult i64 %x, 1505  %min = select i1 %up_cmp, float 255.0, float %f_x506  %r = select i1 %lo_cmp, float 1.0, float %min507  ret float %r508}509 510define float @mixed_clamp_to_float_1(i32 %x) {511; CHECK-LABEL: @mixed_clamp_to_float_1(512; CHECK-NEXT:    [[R1:%.*]] = call i32 @llvm.smax.i32(i32 [[SI_MIN:%.*]], i32 1)513; CHECK-NEXT:    [[R2:%.*]] = call i32 @llvm.smin.i32(i32 [[R1]], i32 255)514; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[R2]] to float515; CHECK-NEXT:    ret float [[R]]516;517  %si_min_cmp = icmp sgt i32 %x, 255518  %si_min = select i1 %si_min_cmp, i32 255, i32 %x519  %f_min = sitofp i32 %si_min to float520  %f_x = sitofp i32 %x to float521  %lo_cmp = fcmp ult float %f_x, 1.0522  %r = select i1 %lo_cmp, float 1.0, float %f_min523  ret float %r524}525 526define i32 @mixed_clamp_to_i32_1(float %x) {527; CHECK-LABEL: @mixed_clamp_to_i32_1(528; CHECK-NEXT:    [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02529; CHECK-NEXT:    [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 2.550000e+02, float [[X]]530; CHECK-NEXT:    [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32531; CHECK-NEXT:    [[I32_X:%.*]] = fptosi float [[X]] to i32532; CHECK-NEXT:    [[LO_CMP:%.*]] = icmp eq i32 [[I32_X]], 0533; CHECK-NEXT:    [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]534; CHECK-NEXT:    ret i32 [[R]]535;536  %float_min_cmp = fcmp ogt float %x, 255.0537  %float_min = select i1 %float_min_cmp, float 255.0, float %x538  %i32_min = fptosi float %float_min to i32539  %i32_x = fptosi float %x to i32540  %lo_cmp = icmp ult i32 %i32_x, 1541  %r = select i1 %lo_cmp, i32 1, i32 %i32_min542  ret i32 %r543}544 545define float @mixed_clamp_to_float_2(i32 %x) {546; CHECK-LABEL: @mixed_clamp_to_float_2(547; CHECK-NEXT:    [[R1:%.*]] = call i32 @llvm.smax.i32(i32 [[SI_MIN:%.*]], i32 1)548; CHECK-NEXT:    [[R2:%.*]] = call i32 @llvm.smin.i32(i32 [[R1]], i32 255)549; CHECK-NEXT:    [[R:%.*]] = uitofp nneg i32 [[R2]] to float550; CHECK-NEXT:    ret float [[R]]551;552  %si_min_cmp = icmp sgt i32 %x, 255553  %si_min = select i1 %si_min_cmp, i32 255, i32 %x554  %f_min = sitofp i32 %si_min to float555  %lo_cmp = icmp slt i32 %x, 1556  %r = select i1 %lo_cmp, float 1.0, float %f_min557  ret float %r558}559 560define i32 @mixed_clamp_to_i32_2(float %x) {561; CHECK-LABEL: @mixed_clamp_to_i32_2(562; CHECK-NEXT:    [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02563; CHECK-NEXT:    [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 2.550000e+02, float [[X]]564; CHECK-NEXT:    [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32565; CHECK-NEXT:    [[LO_CMP:%.*]] = fcmp olt float [[X]], 1.000000e+00566; CHECK-NEXT:    [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]567; CHECK-NEXT:    ret i32 [[R]]568;569  %float_min_cmp = fcmp ogt float %x, 255.0570  %float_min = select i1 %float_min_cmp, float 255.0, float %x571  %i32_min = fptosi float %float_min to i32572  %lo_cmp = fcmp olt float %x, 1.0573  %r = select i1 %lo_cmp, i32 1, i32 %i32_min574  ret i32 %r575}576 577 578define <2 x float> @mixed_clamp_to_float_vec(<2 x i32> %x) {579; CHECK-LABEL: @mixed_clamp_to_float_vec(580; CHECK-NEXT:    [[R1:%.*]] = call <2 x i32> @llvm.smax.v2i32(<2 x i32> [[SI_MIN:%.*]], <2 x i32> splat (i32 1))581; CHECK-NEXT:    [[R2:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[R1]], <2 x i32> splat (i32 255))582; CHECK-NEXT:    [[R:%.*]] = uitofp nneg <2 x i32> [[R2]] to <2 x float>583; CHECK-NEXT:    ret <2 x float> [[R]]584;585  %si_min_cmp = icmp sgt <2 x i32> %x, <i32 255, i32 255>586  %si_min = select <2 x i1> %si_min_cmp, <2 x i32> <i32 255, i32 255>, <2 x i32> %x587  %f_min = sitofp <2 x i32> %si_min to <2 x float>588  %f_x = sitofp <2 x i32> %x to <2 x float>589  %lo_cmp = fcmp ult <2 x float> %f_x, <float 1.0, float 1.0>590  %r = select <2 x i1> %lo_cmp, <2 x float> <float 1.0, float 1.0>, <2 x float> %f_min591  ret <2 x float> %r592}593