530 lines · plain
1; RUN: llc < %s -mtriple=ve | FileCheck %s2 3;;; Test ‘select’ instruction4;;;5;;; Syntax:6;;; <result> = select [fast-math flags] selty <cond>, <ty> <val1>, <ty> <val2>7;;; ; yields ty8;;;9;;; selty is either i1 or {<N x i1>}10;;;11;;; Overview:12;;; The ‘select’ instruction is used to choose one value based on a condition,13;;; without IR-level branching.14;;;15;;; Arguments:16;;; The ‘select’ instruction requires an ‘i1’ value or a vector of ‘i1’ values17;;; indicating the condition, and two values of the same first class type.18;;;19;;; The optional fast-math flags marker indicates that the select has one or20;;; more fast-math flags. These are optimization hints to enable otherwise21;;; unsafe floating-point optimizations. Fast-math flags are only valid for22;;; selects that return a floating-point scalar or vector type, or an array23;;; (nested to any depth) of floating-point scalar or vector types.24;;;25;;; Semantics:26;;; If the condition is an i1 and it evaluates to 1, the instruction returns27;;; the first value argument; otherwise, it returns the second value argument.28;;;29;;; If the condition is a vector of i1, then the value arguments must be30;;; vectors of the same size, and the selection is done element by element.31;;;32;;; If the condition is an i1 and the value arguments are vectors of the same33;;; size, then an entire vector is selected.34;;;35;;; Example:36;;; %X = select i1 true, i8 17, i8 42 ; yields i8:1737;;;38;;; Note:39;;; We test only i1/i8/u8/i16/u16/i32/u32/i64/u64/i128/u128/float/double/fp12840 41; Function Attrs: norecurse nounwind readnone42define zeroext i1 @select_i1_var(i1 zeroext %0, i1 zeroext %1, i1 zeroext %2) {43; CHECK-LABEL: select_i1_var:44; CHECK: # %bb.0:45; CHECK-NEXT: cmov.w.ne %s2, %s1, %s046; CHECK-NEXT: adds.w.zx %s0, %s2, (0)147; CHECK-NEXT: b.l.t (, %s10)48 %4 = select i1 %0, i1 %1, i1 %249 ret i1 %450}51 52; Function Attrs: norecurse nounwind readnone53define signext i8 @select_i8_var(i1 zeroext %0, i8 signext %1, i8 signext %2) {54; CHECK-LABEL: select_i8_var:55; CHECK: # %bb.0:56; CHECK-NEXT: cmov.w.ne %s2, %s1, %s057; CHECK-NEXT: adds.w.sx %s0, %s2, (0)158; CHECK-NEXT: b.l.t (, %s10)59 %4 = select i1 %0, i8 %1, i8 %260 ret i8 %461}62 63; Function Attrs: norecurse nounwind readnone64define zeroext i8 @select_u8_var(i1 zeroext %0, i8 zeroext %1, i8 zeroext %2) {65; CHECK-LABEL: select_u8_var:66; CHECK: # %bb.0:67; CHECK-NEXT: cmov.w.ne %s2, %s1, %s068; CHECK-NEXT: adds.w.zx %s0, %s2, (0)169; CHECK-NEXT: b.l.t (, %s10)70 %4 = select i1 %0, i8 %1, i8 %271 ret i8 %472}73 74; Function Attrs: norecurse nounwind readnone75define signext i16 @select_i16_var(i1 zeroext %0, i16 signext %1, i16 signext %2) {76; CHECK-LABEL: select_i16_var:77; CHECK: # %bb.0:78; CHECK-NEXT: cmov.w.ne %s2, %s1, %s079; CHECK-NEXT: adds.w.sx %s0, %s2, (0)180; CHECK-NEXT: b.l.t (, %s10)81 %4 = select i1 %0, i16 %1, i16 %282 ret i16 %483}84 85; Function Attrs: norecurse nounwind readnone86define zeroext i16 @select_u16_var(i1 zeroext %0, i16 zeroext %1, i16 zeroext %2) {87; CHECK-LABEL: select_u16_var:88; CHECK: # %bb.0:89; CHECK-NEXT: cmov.w.ne %s2, %s1, %s090; CHECK-NEXT: adds.w.zx %s0, %s2, (0)191; CHECK-NEXT: b.l.t (, %s10)92 %4 = select i1 %0, i16 %1, i16 %293 ret i16 %494}95 96; Function Attrs: norecurse nounwind readnone97define signext i32 @select_i32_var(i1 zeroext %0, i32 signext %1, i32 signext %2) {98; CHECK-LABEL: select_i32_var:99; CHECK: # %bb.0:100; CHECK-NEXT: cmov.w.ne %s2, %s1, %s0101; CHECK-NEXT: adds.w.sx %s0, %s2, (0)1102; CHECK-NEXT: b.l.t (, %s10)103 %4 = select i1 %0, i32 %1, i32 %2104 ret i32 %4105}106 107; Function Attrs: norecurse nounwind readnone108define zeroext i32 @select_u32_var(i1 zeroext %0, i32 zeroext %1, i32 zeroext %2) {109; CHECK-LABEL: select_u32_var:110; CHECK: # %bb.0:111; CHECK-NEXT: cmov.w.ne %s2, %s1, %s0112; CHECK-NEXT: adds.w.zx %s0, %s2, (0)1113; CHECK-NEXT: b.l.t (, %s10)114 %4 = select i1 %0, i32 %1, i32 %2115 ret i32 %4116}117 118; Function Attrs: norecurse nounwind readnone119define i64 @select_i64_var(i1 zeroext %0, i64 %1, i64 %2) {120; CHECK-LABEL: select_i64_var:121; CHECK: # %bb.0:122; CHECK-NEXT: cmov.w.ne %s2, %s1, %s0123; CHECK-NEXT: or %s0, 0, %s2124; CHECK-NEXT: b.l.t (, %s10)125 %4 = select i1 %0, i64 %1, i64 %2126 ret i64 %4127}128 129; Function Attrs: norecurse nounwind readnone130define i64 @select_u64_var(i1 zeroext %0, i64 %1, i64 %2) {131; CHECK-LABEL: select_u64_var:132; CHECK: # %bb.0:133; CHECK-NEXT: cmov.w.ne %s2, %s1, %s0134; CHECK-NEXT: or %s0, 0, %s2135; CHECK-NEXT: b.l.t (, %s10)136 %4 = select i1 %0, i64 %1, i64 %2137 ret i64 %4138}139 140; Function Attrs: norecurse nounwind readnone141define i128 @select_i128_var(i1 zeroext %0, i128 %1, i128 %2) {142; CHECK-LABEL: select_i128_var:143; CHECK: # %bb.0:144; CHECK-NEXT: cmov.w.ne %s3, %s1, %s0145; CHECK-NEXT: cmov.w.ne %s4, %s2, %s0146; CHECK-NEXT: or %s0, 0, %s3147; CHECK-NEXT: or %s1, 0, %s4148; CHECK-NEXT: b.l.t (, %s10)149 %4 = select i1 %0, i128 %1, i128 %2150 ret i128 %4151}152 153; Function Attrs: norecurse nounwind readnone154define i128 @select_u128_var(i1 zeroext %0, i128 %1, i128 %2) {155; CHECK-LABEL: select_u128_var:156; CHECK: # %bb.0:157; CHECK-NEXT: cmov.w.ne %s3, %s1, %s0158; CHECK-NEXT: cmov.w.ne %s4, %s2, %s0159; CHECK-NEXT: or %s0, 0, %s3160; CHECK-NEXT: or %s1, 0, %s4161; CHECK-NEXT: b.l.t (, %s10)162 %4 = select i1 %0, i128 %1, i128 %2163 ret i128 %4164}165 166; Function Attrs: norecurse nounwind readnone167define float @select_float_var(i1 zeroext %0, float %1, float %2) {168; CHECK-LABEL: select_float_var:169; CHECK: # %bb.0:170; CHECK-NEXT: cmov.w.ne %s2, %s1, %s0171; CHECK-NEXT: or %s0, 0, %s2172; CHECK-NEXT: b.l.t (, %s10)173 %4 = select fast i1 %0, float %1, float %2174 ret float %4175}176 177; Function Attrs: norecurse nounwind readnone178define double @select_double_var(i1 zeroext %0, double %1, double %2) {179; CHECK-LABEL: select_double_var:180; CHECK: # %bb.0:181; CHECK-NEXT: cmov.w.ne %s2, %s1, %s0182; CHECK-NEXT: or %s0, 0, %s2183; CHECK-NEXT: b.l.t (, %s10)184 %4 = select fast i1 %0, double %1, double %2185 ret double %4186}187 188; Function Attrs: norecurse nounwind readnone189define fp128 @select_quad_var(i1 zeroext %0, fp128 %1, fp128 %2) {190; CHECK-LABEL: select_quad_var:191; CHECK: # %bb.0:192; CHECK-NEXT: cmov.w.ne %s4, %s2, %s0193; CHECK-NEXT: cmov.w.ne %s5, %s3, %s0194; CHECK-NEXT: or %s0, 0, %s4195; CHECK-NEXT: or %s1, 0, %s5196; CHECK-NEXT: b.l.t (, %s10)197 %4 = select fast i1 %0, fp128 %1, fp128 %2198 ret fp128 %4199}200 201; Function Attrs: norecurse nounwind readnone202define zeroext i1 @select_i1_mimm(i1 zeroext %0, i1 zeroext %1) {203; CHECK-LABEL: select_i1_mimm:204; CHECK: # %bb.0:205; CHECK-NEXT: or %s0, %s0, %s1206; CHECK-NEXT: b.l.t (, %s10)207 %3 = or i1 %0, %1208 ret i1 %3209}210 211; Function Attrs: norecurse nounwind readnone212define signext i8 @select_i8_mimm(i1 zeroext %0, i8 signext %1) {213; CHECK-LABEL: select_i8_mimm:214; CHECK: # %bb.0:215; CHECK-NEXT: cmov.w.ne %s1, (57)1, %s0216; CHECK-NEXT: adds.w.sx %s0, %s1, (0)1217; CHECK-NEXT: b.l.t (, %s10)218 %3 = select i1 %0, i8 -128, i8 %1219 ret i8 %3220}221 222; Function Attrs: norecurse nounwind readnone223define zeroext i8 @select_u8_mimm(i1 zeroext %0, i8 zeroext %1) {224; CHECK-LABEL: select_u8_mimm:225; CHECK: # %bb.0:226; CHECK-NEXT: cmov.w.ne %s1, (57)0, %s0227; CHECK-NEXT: adds.w.zx %s0, %s1, (0)1228; CHECK-NEXT: b.l.t (, %s10)229 %3 = select i1 %0, i8 127, i8 %1230 ret i8 %3231}232 233; Function Attrs: norecurse nounwind readnone234define signext i16 @select_i16_mimm(i1 zeroext %0, i16 signext %1) {235; CHECK-LABEL: select_i16_mimm:236; CHECK: # %bb.0:237; CHECK-NEXT: cmov.w.ne %s1, (49)1, %s0238; CHECK-NEXT: adds.w.sx %s0, %s1, (0)1239; CHECK-NEXT: b.l.t (, %s10)240 %3 = select i1 %0, i16 -32768, i16 %1241 ret i16 %3242}243 244; Function Attrs: norecurse nounwind readnone245define zeroext i16 @select_u16_mimm(i1 zeroext %0, i16 zeroext %1) {246; CHECK-LABEL: select_u16_mimm:247; CHECK: # %bb.0:248; CHECK-NEXT: cmov.w.ne %s1, (49)0, %s0249; CHECK-NEXT: adds.w.zx %s0, %s1, (0)1250; CHECK-NEXT: b.l.t (, %s10)251 %3 = select i1 %0, i16 32767, i16 %1252 ret i16 %3253}254 255; Function Attrs: norecurse nounwind readnone256define signext i32 @select_i32_mimm(i1 zeroext %0, i32 signext %1) {257; CHECK-LABEL: select_i32_mimm:258; CHECK: # %bb.0:259; CHECK-NEXT: cmov.w.ne %s1, (48)0, %s0260; CHECK-NEXT: adds.w.sx %s0, %s1, (0)1261; CHECK-NEXT: b.l.t (, %s10)262 %3 = select i1 %0, i32 65535, i32 %1263 ret i32 %3264}265 266; Function Attrs: norecurse nounwind readnone267define zeroext i32 @select_u32_mimm(i1 zeroext %0, i32 zeroext %1) {268; CHECK-LABEL: select_u32_mimm:269; CHECK: # %bb.0:270; CHECK-NEXT: cmov.w.ne %s1, (48)0, %s0271; CHECK-NEXT: adds.w.zx %s0, %s1, (0)1272; CHECK-NEXT: b.l.t (, %s10)273 %3 = select i1 %0, i32 65535, i32 %1274 ret i32 %3275}276 277; Function Attrs: norecurse nounwind readnone278define i64 @select_i64_mimm(i1 zeroext %0, i64 %1) {279; CHECK-LABEL: select_i64_mimm:280; CHECK: # %bb.0:281; CHECK-NEXT: cmov.w.ne %s1, (48)0, %s0282; CHECK-NEXT: or %s0, 0, %s1283; CHECK-NEXT: b.l.t (, %s10)284 %3 = select i1 %0, i64 65535, i64 %1285 ret i64 %3286}287 288; Function Attrs: norecurse nounwind readnone289define i64 @select_u64_mimm(i1 zeroext %0, i64 %1) {290; CHECK-LABEL: select_u64_mimm:291; CHECK: # %bb.0:292; CHECK-NEXT: cmov.w.ne %s1, (48)0, %s0293; CHECK-NEXT: or %s0, 0, %s1294; CHECK-NEXT: b.l.t (, %s10)295 %3 = select i1 %0, i64 65535, i64 %1296 ret i64 %3297}298 299; Function Attrs: norecurse nounwind readnone300define i128 @select_i128_mimm(i1 zeroext %0, i128 %1) {301; CHECK-LABEL: select_i128_mimm:302; CHECK: # %bb.0:303; CHECK-NEXT: cmov.w.ne %s1, (48)0, %s0304; CHECK-NEXT: cmov.w.ne %s2, (0)1, %s0305; CHECK-NEXT: or %s0, 0, %s1306; CHECK-NEXT: or %s1, 0, %s2307; CHECK-NEXT: b.l.t (, %s10)308 %3 = select i1 %0, i128 65535, i128 %1309 ret i128 %3310}311 312; Function Attrs: norecurse nounwind readnone313define i128 @select_u128_mimm(i1 zeroext %0, i128 %1) {314; CHECK-LABEL: select_u128_mimm:315; CHECK: # %bb.0:316; CHECK-NEXT: cmov.w.ne %s1, (48)0, %s0317; CHECK-NEXT: cmov.w.ne %s2, (0)1, %s0318; CHECK-NEXT: or %s0, 0, %s1319; CHECK-NEXT: or %s1, 0, %s2320; CHECK-NEXT: b.l.t (, %s10)321 %3 = select i1 %0, i128 65535, i128 %1322 ret i128 %3323}324 325; Function Attrs: norecurse nounwind readnone326define float @select_float_mimm(i1 zeroext %0, float %1) {327; CHECK-LABEL: select_float_mimm:328; CHECK: # %bb.0:329; CHECK-NEXT: cmov.w.ne %s1, (2)1, %s0330; CHECK-NEXT: or %s0, 0, %s1331; CHECK-NEXT: b.l.t (, %s10)332 %3 = select i1 %0, float -2.000000e+00, float %1333 ret float %3334}335 336; Function Attrs: norecurse nounwind readnone337define double @select_double_mimm(i1 zeroext %0, double %1) {338; CHECK-LABEL: select_double_mimm:339; CHECK: # %bb.0:340; CHECK-NEXT: cmov.w.ne %s1, (2)1, %s0341; CHECK-NEXT: or %s0, 0, %s1342; CHECK-NEXT: b.l.t (, %s10)343 %3 = select fast i1 %0, double -2.000000e+00, double %1344 ret double %3345}346 347; Function Attrs: norecurse nounwind readnone348define fp128 @select_quad_mimm(i1 zeroext %0, fp128 %1) {349; CHECK-LABEL: select_quad_mimm:350; CHECK: # %bb.0:351; CHECK-NEXT: lea %s1, .LCPI{{[0-9]+}}_0@lo352; CHECK-NEXT: and %s1, %s1, (32)0353; CHECK-NEXT: lea.sl %s1, .LCPI{{[0-9]+}}_0@hi(, %s1)354; CHECK-NEXT: ld %s4, 8(, %s1)355; CHECK-NEXT: ld %s1, (, %s1)356; CHECK-NEXT: cmov.w.ne %s2, %s4, %s0357; CHECK-NEXT: cmov.w.ne %s3, %s1, %s0358; CHECK-NEXT: or %s0, 0, %s2359; CHECK-NEXT: or %s1, 0, %s3360; CHECK-NEXT: b.l.t (, %s10)361 %3 = select fast i1 %0, fp128 0xL0000000000000000C000000000000000, fp128 %1362 ret fp128 %3363}364 365; Function Attrs: norecurse nounwind readnone366define zeroext i1 @select_mimm_i1(i1 zeroext %0, i1 zeroext %1) {367; CHECK-LABEL: select_mimm_i1:368; CHECK: # %bb.0:369; CHECK-NEXT: xor %s0, 1, %s0370; CHECK-NEXT: or %s0, %s0, %s1371; CHECK-NEXT: b.l.t (, %s10)372 %3 = xor i1 %0, true373 %4 = or i1 %3, %1374 ret i1 %4375}376 377; Function Attrs: norecurse nounwind readnone378define signext i8 @select_mimm_i8(i1 zeroext %0, i8 signext %1) {379; CHECK-LABEL: select_mimm_i8:380; CHECK: # %bb.0:381; CHECK-NEXT: cmov.w.eq %s1, (57)1, %s0382; CHECK-NEXT: adds.w.sx %s0, %s1, (0)1383; CHECK-NEXT: b.l.t (, %s10)384 %3 = select i1 %0, i8 %1, i8 -128385 ret i8 %3386}387 388; Function Attrs: norecurse nounwind readnone389define zeroext i8 @select_mimm_u8(i1 zeroext %0, i8 zeroext %1) {390; CHECK-LABEL: select_mimm_u8:391; CHECK: # %bb.0:392; CHECK-NEXT: cmov.w.eq %s1, (57)0, %s0393; CHECK-NEXT: adds.w.zx %s0, %s1, (0)1394; CHECK-NEXT: b.l.t (, %s10)395 %3 = select i1 %0, i8 %1, i8 127396 ret i8 %3397}398 399; Function Attrs: norecurse nounwind readnone400define signext i16 @select_mimm_i16(i1 zeroext %0, i16 signext %1) {401; CHECK-LABEL: select_mimm_i16:402; CHECK: # %bb.0:403; CHECK-NEXT: cmov.w.eq %s1, (49)1, %s0404; CHECK-NEXT: adds.w.sx %s0, %s1, (0)1405; CHECK-NEXT: b.l.t (, %s10)406 %3 = select i1 %0, i16 %1, i16 -32768407 ret i16 %3408}409 410; Function Attrs: norecurse nounwind readnone411define zeroext i16 @select_mimm_u16(i1 zeroext %0, i16 zeroext %1) {412; CHECK-LABEL: select_mimm_u16:413; CHECK: # %bb.0:414; CHECK-NEXT: cmov.w.eq %s1, (49)0, %s0415; CHECK-NEXT: adds.w.zx %s0, %s1, (0)1416; CHECK-NEXT: b.l.t (, %s10)417 %3 = select i1 %0, i16 %1, i16 32767418 ret i16 %3419}420 421; Function Attrs: norecurse nounwind readnone422define signext i32 @select_mimm_i32(i1 zeroext %0, i32 signext %1) {423; CHECK-LABEL: select_mimm_i32:424; CHECK: # %bb.0:425; CHECK-NEXT: cmov.w.eq %s1, (48)0, %s0426; CHECK-NEXT: adds.w.sx %s0, %s1, (0)1427; CHECK-NEXT: b.l.t (, %s10)428 %3 = select i1 %0, i32 %1, i32 65535429 ret i32 %3430}431 432; Function Attrs: norecurse nounwind readnone433define zeroext i32 @select_mimm_u32(i1 zeroext %0, i32 zeroext %1) {434; CHECK-LABEL: select_mimm_u32:435; CHECK: # %bb.0:436; CHECK-NEXT: cmov.w.eq %s1, (48)0, %s0437; CHECK-NEXT: adds.w.zx %s0, %s1, (0)1438; CHECK-NEXT: b.l.t (, %s10)439 %3 = select i1 %0, i32 %1, i32 65535440 ret i32 %3441}442 443; Function Attrs: norecurse nounwind readnone444define i64 @select_mimm_i64(i1 zeroext %0, i64 %1) {445; CHECK-LABEL: select_mimm_i64:446; CHECK: # %bb.0:447; CHECK-NEXT: cmov.w.eq %s1, (48)0, %s0448; CHECK-NEXT: or %s0, 0, %s1449; CHECK-NEXT: b.l.t (, %s10)450 %3 = select i1 %0, i64 %1, i64 65535451 ret i64 %3452}453 454; Function Attrs: norecurse nounwind readnone455define i64 @select_mimm_u64(i1 zeroext %0, i64 %1) {456; CHECK-LABEL: select_mimm_u64:457; CHECK: # %bb.0:458; CHECK-NEXT: cmov.w.eq %s1, (48)0, %s0459; CHECK-NEXT: or %s0, 0, %s1460; CHECK-NEXT: b.l.t (, %s10)461 %3 = select i1 %0, i64 %1, i64 65535462 ret i64 %3463}464 465; Function Attrs: norecurse nounwind readnone466define i128 @select_mimm_i128(i1 zeroext %0, i128 %1) {467; CHECK-LABEL: select_mimm_i128:468; CHECK: # %bb.0:469; CHECK-NEXT: cmov.w.eq %s1, (48)0, %s0470; CHECK-NEXT: cmov.w.eq %s2, (0)1, %s0471; CHECK-NEXT: or %s0, 0, %s1472; CHECK-NEXT: or %s1, 0, %s2473; CHECK-NEXT: b.l.t (, %s10)474 %3 = select i1 %0, i128 %1, i128 65535475 ret i128 %3476}477 478; Function Attrs: norecurse nounwind readnone479define i128 @select_mimm_u128(i1 zeroext %0, i128 %1) {480; CHECK-LABEL: select_mimm_u128:481; CHECK: # %bb.0:482; CHECK-NEXT: cmov.w.eq %s1, (48)0, %s0483; CHECK-NEXT: cmov.w.eq %s2, (0)1, %s0484; CHECK-NEXT: or %s0, 0, %s1485; CHECK-NEXT: or %s1, 0, %s2486; CHECK-NEXT: b.l.t (, %s10)487 %3 = select i1 %0, i128 %1, i128 65535488 ret i128 %3489}490 491; Function Attrs: norecurse nounwind readnone492define float @select_mimm_float(i1 zeroext %0, float %1) {493; CHECK-LABEL: select_mimm_float:494; CHECK: # %bb.0:495; CHECK-NEXT: cmov.w.eq %s1, (2)1, %s0496; CHECK-NEXT: or %s0, 0, %s1497; CHECK-NEXT: b.l.t (, %s10)498 %3 = select i1 %0, float %1, float -2.000000e+00499 ret float %3500}501 502; Function Attrs: norecurse nounwind readnone503define double @select_mimm_double(i1 zeroext %0, double %1) {504; CHECK-LABEL: select_mimm_double:505; CHECK: # %bb.0:506; CHECK-NEXT: cmov.w.eq %s1, (2)1, %s0507; CHECK-NEXT: or %s0, 0, %s1508; CHECK-NEXT: b.l.t (, %s10)509 %3 = select fast i1 %0, double %1, double -2.000000e+00510 ret double %3511}512 513; Function Attrs: norecurse nounwind readnone514define fp128 @select_mimm_quad(i1 zeroext %0, fp128 %1) {515; CHECK-LABEL: select_mimm_quad:516; CHECK: # %bb.0:517; CHECK-NEXT: lea %s1, .LCPI{{[0-9]+}}_0@lo518; CHECK-NEXT: and %s1, %s1, (32)0519; CHECK-NEXT: lea.sl %s1, .LCPI{{[0-9]+}}_0@hi(, %s1)520; CHECK-NEXT: ld %s4, 8(, %s1)521; CHECK-NEXT: ld %s5, (, %s1)522; CHECK-NEXT: cmov.w.ne %s4, %s2, %s0523; CHECK-NEXT: cmov.w.ne %s5, %s3, %s0524; CHECK-NEXT: or %s0, 0, %s4525; CHECK-NEXT: or %s1, 0, %s5526; CHECK-NEXT: b.l.t (, %s10)527 %3 = select fast i1 %0, fp128 %1, fp128 0xL0000000000000000C000000000000000528 ret fp128 %3529}530