415 lines · plain
1; RUN: llc < %s -mtriple=ve | FileCheck %s2 3;;; Test ‘shl’ instruction4;;;5;;; Syntax:6;;; <result> = shl <ty> <op1>, <op2> ; yields ty:result7;;; <result> = shl nuw <ty> <op1>, <op2> ; yields ty:result8;;; <result> = shl nsw <ty> <op1>, <op2> ; yields ty:result9;;; <result> = shl nuw nsw <ty> <op1>, <op2> ; yields ty:result10;;;11;;; Overview:12;;; The ‘shl’ instruction returns the first operand shifted to the left13;;; a specified number of bits.14;;;15;;; Arguments:16;;; Both arguments to the ‘shl’ instruction must be the same integer or17;;; vector of integer type. ‘op2’ is treated as an unsigned value.18;;;19;;; Semantics:20;;; The value produced is op1 * 2op2 mod 2n, where n is the width of the21;;; result. If op2 is (statically or dynamically) equal to or larger than22;;; the number of bits in op1, this instruction returns a poison value.23;;; If the arguments are vectors, each vector element of op1 is shifted by24;;; the corresponding shift amount in op2.25;;;26;;; If the nuw keyword is present, then the shift produces a poison value27;;; if it shifts out any non-zero bits. If the nsw keyword is present,28;;; then the shift produces a poison value if it shifts out any bits that29;;; disagree with the resultant sign bit.30;;;31;;; Example:32;;; <result> = shl i32 4, %var ; yields i32: 4 << %var33;;; <result> = shl i32 4, 2 ; yields i32: 1634;;; <result> = shl i32 1, 10 ; yields i32: 102435;;; <result> = shl i32 1, 32 ; undefined36;;; <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2>37;;; ; yields: result=<2 x i32> < i32 2, i32 4>38;;;39;;; Note:40;;; We test only i8/i16/i32/i64/i128 and unsigned of them.41 42; Function Attrs: norecurse nounwind readnone43define signext i8 @shl_i8_var(i8 signext %0, i8 signext %1) {44; CHECK-LABEL: shl_i8_var:45; CHECK: # %bb.0:46; CHECK-NEXT: and %s1, %s1, (56)047; CHECK-NEXT: sla.w.sx %s0, %s0, %s148; CHECK-NEXT: sll %s0, %s0, 5649; CHECK-NEXT: sra.l %s0, %s0, 5650; CHECK-NEXT: b.l.t (, %s10)51 %3 = sext i8 %0 to i3252 %4 = zext i8 %1 to i3253 %5 = shl i32 %3, %454 %6 = trunc i32 %5 to i855 ret i8 %656}57 58; Function Attrs: norecurse nounwind readnone59define zeroext i8 @shl_u8_var(i8 zeroext %0, i8 zeroext %1) {60; CHECK-LABEL: shl_u8_var:61; CHECK: # %bb.0:62; CHECK-NEXT: sla.w.sx %s0, %s0, %s163; CHECK-NEXT: and %s0, %s0, (56)064; CHECK-NEXT: b.l.t (, %s10)65 %3 = zext i8 %0 to i3266 %4 = zext i8 %1 to i3267 %5 = shl i32 %3, %468 %6 = trunc i32 %5 to i869 ret i8 %670}71 72; Function Attrs: norecurse nounwind readnone73define signext i16 @shl_i16_var(i16 signext %0, i16 signext %1) {74; CHECK-LABEL: shl_i16_var:75; CHECK: # %bb.0:76; CHECK-NEXT: and %s1, %s1, (48)077; CHECK-NEXT: sla.w.sx %s0, %s0, %s178; CHECK-NEXT: sll %s0, %s0, 4879; CHECK-NEXT: sra.l %s0, %s0, 4880; CHECK-NEXT: b.l.t (, %s10)81 %3 = sext i16 %0 to i3282 %4 = zext i16 %1 to i3283 %5 = shl i32 %3, %484 %6 = trunc i32 %5 to i1685 ret i16 %686}87 88; Function Attrs: norecurse nounwind readnone89define zeroext i16 @shl_u16_var(i16 zeroext %0, i16 zeroext %1) {90; CHECK-LABEL: shl_u16_var:91; CHECK: # %bb.0:92; CHECK-NEXT: sla.w.sx %s0, %s0, %s193; CHECK-NEXT: and %s0, %s0, (48)094; CHECK-NEXT: b.l.t (, %s10)95 %3 = zext i16 %0 to i3296 %4 = zext i16 %1 to i3297 %5 = shl i32 %3, %498 %6 = trunc i32 %5 to i1699 ret i16 %6100}101 102; Function Attrs: norecurse nounwind readnone103define signext i32 @shl_i32_var(i32 signext %0, i32 signext %1) {104; CHECK-LABEL: shl_i32_var:105; CHECK: # %bb.0:106; CHECK-NEXT: sla.w.sx %s0, %s0, %s1107; CHECK-NEXT: adds.w.sx %s0, %s0, (0)1108; CHECK-NEXT: b.l.t (, %s10)109 %3 = shl i32 %0, %1110 ret i32 %3111}112 113; Function Attrs: norecurse nounwind readnone114define zeroext i32 @shl_u32_var(i32 zeroext %0, i32 zeroext %1) {115; CHECK-LABEL: shl_u32_var:116; CHECK: # %bb.0:117; CHECK-NEXT: sla.w.sx %s0, %s0, %s1118; CHECK-NEXT: adds.w.zx %s0, %s0, (0)1119; CHECK-NEXT: b.l.t (, %s10)120 %3 = shl i32 %0, %1121 ret i32 %3122}123 124; Function Attrs: norecurse nounwind readnone125define i64 @shl_i64_var(i64 %0, i64 %1) {126; CHECK-LABEL: shl_i64_var:127; CHECK: # %bb.0:128; CHECK-NEXT: sll %s0, %s0, %s1129; CHECK-NEXT: b.l.t (, %s10)130 %3 = shl i64 %0, %1131 ret i64 %3132}133 134; Function Attrs: norecurse nounwind readnone135define i64 @shl_u64_var(i64 %0, i64 %1) {136; CHECK-LABEL: shl_u64_var:137; CHECK: # %bb.0:138; CHECK-NEXT: sll %s0, %s0, %s1139; CHECK-NEXT: b.l.t (, %s10)140 %3 = shl i64 %0, %1141 ret i64 %3142}143 144; Function Attrs: norecurse nounwind readnone145define i128 @shl_i128_var(i128 %0, i128 %1) {146; CHECK-LABEL: shl_i128_var:147; CHECK: .LBB{{[0-9]+}}_2:148; CHECK-NEXT: and %s2, %s2, (32)0149; CHECK-NEXT: lea %s3, __ashlti3@lo150; CHECK-NEXT: and %s3, %s3, (32)0151; CHECK-NEXT: lea.sl %s12, __ashlti3@hi(, %s3)152; CHECK-NEXT: bsic %s10, (, %s12)153; CHECK-NEXT: or %s11, 0, %s9154 %3 = shl i128 %0, %1155 ret i128 %3156}157 158; Function Attrs: norecurse nounwind readnone159define i128 @shl_u128_var(i128 %0, i128 %1) {160; CHECK-LABEL: shl_u128_var:161; CHECK: .LBB{{[0-9]+}}_2:162; CHECK-NEXT: and %s2, %s2, (32)0163; CHECK-NEXT: lea %s3, __ashlti3@lo164; CHECK-NEXT: and %s3, %s3, (32)0165; CHECK-NEXT: lea.sl %s12, __ashlti3@hi(, %s3)166; CHECK-NEXT: bsic %s10, (, %s12)167; CHECK-NEXT: or %s11, 0, %s9168 %3 = shl i128 %0, %1169 ret i128 %3170}171 172; Function Attrs: norecurse nounwind readnone173define signext i8 @shl_const_i8(i8 signext %0) {174; CHECK-LABEL: shl_const_i8:175; CHECK: # %bb.0:176; CHECK-NEXT: and %s0, %s0, (56)0177; CHECK-NEXT: sla.w.sx %s0, (62)1, %s0178; CHECK-NEXT: sll %s0, %s0, 56179; CHECK-NEXT: sra.l %s0, %s0, 56180; CHECK-NEXT: b.l.t (, %s10)181 %2 = zext i8 %0 to i32182 %3 = shl i32 -4, %2183 %4 = trunc i32 %3 to i8184 ret i8 %4185}186 187; Function Attrs: norecurse nounwind readnone188define zeroext i8 @shl_const_u8(i8 zeroext %0) {189; CHECK-LABEL: shl_const_u8:190; CHECK: # %bb.0:191; CHECK-NEXT: sla.w.sx %s0, (62)1, %s0192; CHECK-NEXT: lea %s1, 252193; CHECK-NEXT: and %s0, %s0, %s1194; CHECK-NEXT: b.l.t (, %s10)195 %2 = zext i8 %0 to i32196 %3 = shl i32 -4, %2197 %4 = trunc i32 %3 to i8198 ret i8 %4199}200 201; Function Attrs: norecurse nounwind readnone202define signext i16 @shl_const_i16(i16 signext %0) {203; CHECK-LABEL: shl_const_i16:204; CHECK: # %bb.0:205; CHECK-NEXT: and %s0, %s0, (48)0206; CHECK-NEXT: sla.w.sx %s0, (62)1, %s0207; CHECK-NEXT: sll %s0, %s0, 48208; CHECK-NEXT: sra.l %s0, %s0, 48209; CHECK-NEXT: b.l.t (, %s10)210 %2 = zext i16 %0 to i32211 %3 = shl i32 -4, %2212 %4 = trunc i32 %3 to i16213 ret i16 %4214}215 216; Function Attrs: norecurse nounwind readnone217define zeroext i16 @shl_const_u16(i16 zeroext %0) {218; CHECK-LABEL: shl_const_u16:219; CHECK: # %bb.0:220; CHECK-NEXT: sla.w.sx %s0, (62)1, %s0221; CHECK-NEXT: lea %s1, 65532222; CHECK-NEXT: and %s0, %s0, %s1223; CHECK-NEXT: b.l.t (, %s10)224 %2 = zext i16 %0 to i32225 %3 = shl i32 -4, %2226 %4 = trunc i32 %3 to i16227 ret i16 %4228}229 230; Function Attrs: norecurse nounwind readnone231define signext i32 @shl_const_i32(i32 signext %0) {232; CHECK-LABEL: shl_const_i32:233; CHECK: # %bb.0:234; CHECK-NEXT: sla.w.sx %s0, (62)1, %s0235; CHECK-NEXT: adds.w.sx %s0, %s0, (0)1236; CHECK-NEXT: b.l.t (, %s10)237 %2 = shl i32 -4, %0238 ret i32 %2239}240 241; Function Attrs: norecurse nounwind readnone242define zeroext i32 @shl_const_u32(i32 zeroext %0) {243; CHECK-LABEL: shl_const_u32:244; CHECK: # %bb.0:245; CHECK-NEXT: sla.w.sx %s0, (62)1, %s0246; CHECK-NEXT: adds.w.zx %s0, %s0, (0)1247; CHECK-NEXT: b.l.t (, %s10)248 %2 = shl i32 -4, %0249 ret i32 %2250}251 252; Function Attrs: norecurse nounwind readnone253define i64 @shl_const_i64(i64 %0) {254; CHECK-LABEL: shl_const_i64:255; CHECK: # %bb.0:256; CHECK-NEXT: sll %s0, (62)1, %s0257; CHECK-NEXT: b.l.t (, %s10)258 %2 = shl i64 -4, %0259 ret i64 %2260}261 262; Function Attrs: norecurse nounwind readnone263define i64 @shl_const_u64(i64 %0) {264; CHECK-LABEL: shl_const_u64:265; CHECK: # %bb.0:266; CHECK-NEXT: sll %s0, (62)1, %s0267; CHECK-NEXT: b.l.t (, %s10)268 %2 = shl i64 -4, %0269 ret i64 %2270}271 272; Function Attrs: norecurse nounwind readnone273define i128 @shl_const_i128(i128 %0) {274; CHECK-LABEL: shl_const_i128:275; CHECK: .LBB{{[0-9]+}}_2:276; CHECK-NEXT: and %s2, %s0, (32)0277; CHECK-NEXT: lea %s0, __ashlti3@lo278; CHECK-NEXT: and %s0, %s0, (32)0279; CHECK-NEXT: lea.sl %s12, __ashlti3@hi(, %s0)280; CHECK-NEXT: or %s0, -4, (0)1281; CHECK-NEXT: or %s1, -1, (0)1282; CHECK-NEXT: bsic %s10, (, %s12)283; CHECK-NEXT: or %s11, 0, %s9284 %2 = shl i128 -4, %0285 ret i128 %2286}287 288; Function Attrs: norecurse nounwind readnone289define i128 @shl_const_u128(i128 %0) {290; CHECK-LABEL: shl_const_u128:291; CHECK: .LBB{{[0-9]+}}_2:292; CHECK-NEXT: and %s2, %s0, (32)0293; CHECK-NEXT: lea %s0, __ashlti3@lo294; CHECK-NEXT: and %s0, %s0, (32)0295; CHECK-NEXT: lea.sl %s12, __ashlti3@hi(, %s0)296; CHECK-NEXT: or %s0, -4, (0)1297; CHECK-NEXT: or %s1, -1, (0)1298; CHECK-NEXT: bsic %s10, (, %s12)299; CHECK-NEXT: or %s11, 0, %s9300 %2 = shl i128 -4, %0301 ret i128 %2302}303 304; Function Attrs: norecurse nounwind readnone305define signext i8 @shl_i8_const(i8 signext %0) {306; CHECK-LABEL: shl_i8_const:307; CHECK: # %bb.0:308; CHECK-NEXT: sla.w.sx %s0, %s0, 3309; CHECK-NEXT: sll %s0, %s0, 56310; CHECK-NEXT: sra.l %s0, %s0, 56311; CHECK-NEXT: b.l.t (, %s10)312 %2 = shl i8 %0, 3313 ret i8 %2314}315 316; Function Attrs: norecurse nounwind readnone317define zeroext i8 @shl_u8_const(i8 zeroext %0) {318; CHECK-LABEL: shl_u8_const:319; CHECK: # %bb.0:320; CHECK-NEXT: sla.w.sx %s0, %s0, 3321; CHECK-NEXT: lea %s1, 248322; CHECK-NEXT: and %s0, %s0, %s1323; CHECK-NEXT: b.l.t (, %s10)324 %2 = shl i8 %0, 3325 ret i8 %2326}327 328; Function Attrs: norecurse nounwind readnone329define signext i16 @shl_i16_const(i16 signext %0) {330; CHECK-LABEL: shl_i16_const:331; CHECK: # %bb.0:332; CHECK-NEXT: sla.w.sx %s0, %s0, 7333; CHECK-NEXT: sll %s0, %s0, 48334; CHECK-NEXT: sra.l %s0, %s0, 48335; CHECK-NEXT: b.l.t (, %s10)336 %2 = shl i16 %0, 7337 ret i16 %2338}339 340; Function Attrs: norecurse nounwind readnone341define zeroext i16 @shl_u16_const(i16 zeroext %0) {342; CHECK-LABEL: shl_u16_const:343; CHECK: # %bb.0:344; CHECK-NEXT: sla.w.sx %s0, %s0, 7345; CHECK-NEXT: lea %s1, 65408346; CHECK-NEXT: and %s0, %s0, %s1347; CHECK-NEXT: b.l.t (, %s10)348 %2 = shl i16 %0, 7349 ret i16 %2350}351 352; Function Attrs: norecurse nounwind readnone353define signext i32 @shl_i32_const(i32 signext %0) {354; CHECK-LABEL: shl_i32_const:355; CHECK: # %bb.0:356; CHECK-NEXT: sla.w.sx %s0, %s0, 15357; CHECK-NEXT: adds.w.sx %s0, %s0, (0)1358; CHECK-NEXT: b.l.t (, %s10)359 %2 = shl i32 %0, 15360 ret i32 %2361}362 363; Function Attrs: norecurse nounwind readnone364define zeroext i32 @shl_u32_const(i32 zeroext %0) {365; CHECK-LABEL: shl_u32_const:366; CHECK: # %bb.0:367; CHECK-NEXT: sla.w.sx %s0, %s0, 15368; CHECK-NEXT: adds.w.zx %s0, %s0, (0)1369; CHECK-NEXT: b.l.t (, %s10)370 %2 = shl i32 %0, 15371 ret i32 %2372}373 374; Function Attrs: norecurse nounwind readnone375define i64 @shl_i64_const(i64 %0) {376; CHECK-LABEL: shl_i64_const:377; CHECK: # %bb.0:378; CHECK-NEXT: sll %s0, %s0, 63379; CHECK-NEXT: b.l.t (, %s10)380 %2 = shl i64 %0, 63381 ret i64 %2382}383 384; Function Attrs: norecurse nounwind readnone385define i64 @shl_u64_const(i64 %0) {386; CHECK-LABEL: shl_u64_const:387; CHECK: # %bb.0:388; CHECK-NEXT: sll %s0, %s0, 63389; CHECK-NEXT: b.l.t (, %s10)390 %2 = shl i64 %0, 63391 ret i64 %2392}393 394; Function Attrs: norecurse nounwind readnone395define i128 @shl_i128_const(i128 %0) {396; CHECK-LABEL: shl_i128_const:397; CHECK: # %bb.0:398; CHECK-NEXT: sll %s1, %s0, 63399; CHECK-NEXT: or %s0, 0, (0)1400; CHECK-NEXT: b.l.t (, %s10)401 %2 = shl i128 %0, 127402 ret i128 %2403}404 405; Function Attrs: norecurse nounwind readnone406define i128 @shl_u128_const(i128 %0) {407; CHECK-LABEL: shl_u128_const:408; CHECK: # %bb.0:409; CHECK-NEXT: sll %s1, %s0, 63410; CHECK-NEXT: or %s0, 0, (0)1411; CHECK-NEXT: b.l.t (, %s10)412 %2 = shl i128 %0, 127413 ret i128 %2414}415