272 lines · plain
1; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck %s2 3; Test that basic 64-bit integer operations assemble as expected.4 5target triple = "wasm32-unknown-unknown"6 7declare i64 @llvm.ctlz.i64(i64, i1)8declare i64 @llvm.cttz.i64(i64, i1)9declare i64 @llvm.ctpop.i64(i64)10 11; CHECK-LABEL: add64:12; CHECK-NEXT: .functype add64 (i64, i64) -> (i64){{$}}13; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}14; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}15; CHECK-NEXT: i64.add $push0=, $pop[[L0]], $pop[[L1]]{{$}}16; CHECK-NEXT: return $pop0{{$}}17define i64 @add64(i64 %x, i64 %y) {18 %a = add i64 %x, %y19 ret i64 %a20}21 22; CHECK-LABEL: sub64:23; CHECK-NEXT: .functype sub64 (i64, i64) -> (i64){{$}}24; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}25; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}26; CHECK-NEXT: i64.sub $push0=, $pop[[L0]], $pop[[L1]]{{$}}27; CHECK-NEXT: return $pop0{{$}}28define i64 @sub64(i64 %x, i64 %y) {29 %a = sub i64 %x, %y30 ret i64 %a31}32 33; CHECK-LABEL: mul64:34; CHECK-NEXT: .functype mul64 (i64, i64) -> (i64){{$}}35; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}36; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}37; CHECK-NEXT: i64.mul $push0=, $pop[[L0]], $pop[[L1]]{{$}}38; CHECK-NEXT: return $pop0{{$}}39define i64 @mul64(i64 %x, i64 %y) {40 %a = mul i64 %x, %y41 ret i64 %a42}43 44; CHECK-LABEL: sdiv64:45; CHECK-NEXT: .functype sdiv64 (i64, i64) -> (i64){{$}}46; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}47; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}48; CHECK-NEXT: i64.div_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}49; CHECK-NEXT: return $pop0{{$}}50define i64 @sdiv64(i64 %x, i64 %y) {51 %a = sdiv i64 %x, %y52 ret i64 %a53}54 55; CHECK-LABEL: udiv64:56; CHECK-NEXT: .functype udiv64 (i64, i64) -> (i64){{$}}57; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}58; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}59; CHECK-NEXT: i64.div_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}60; CHECK-NEXT: return $pop0{{$}}61define i64 @udiv64(i64 %x, i64 %y) {62 %a = udiv i64 %x, %y63 ret i64 %a64}65 66; CHECK-LABEL: srem64:67; CHECK-NEXT: .functype srem64 (i64, i64) -> (i64){{$}}68; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}69; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}70; CHECK-NEXT: i64.rem_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}71; CHECK-NEXT: return $pop0{{$}}72define i64 @srem64(i64 %x, i64 %y) {73 %a = srem i64 %x, %y74 ret i64 %a75}76 77; CHECK-LABEL: urem64:78; CHECK-NEXT: .functype urem64 (i64, i64) -> (i64){{$}}79; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}80; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}81; CHECK-NEXT: i64.rem_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}82; CHECK-NEXT: return $pop0{{$}}83define i64 @urem64(i64 %x, i64 %y) {84 %a = urem i64 %x, %y85 ret i64 %a86}87 88; CHECK-LABEL: and64:89; CHECK-NEXT: .functype and64 (i64, i64) -> (i64){{$}}90; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}91; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}92; CHECK-NEXT: i64.and $push0=, $pop[[L0]], $pop[[L1]]{{$}}93; CHECK-NEXT: return $pop0{{$}}94define i64 @and64(i64 %x, i64 %y) {95 %a = and i64 %x, %y96 ret i64 %a97}98 99; CHECK-LABEL: or64:100; CHECK-NEXT: .functype or64 (i64, i64) -> (i64){{$}}101; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}102; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}103; CHECK-NEXT: i64.or $push0=, $pop[[L0]], $pop[[L1]]{{$}}104; CHECK-NEXT: return $pop0{{$}}105define i64 @or64(i64 %x, i64 %y) {106 %a = or i64 %x, %y107 ret i64 %a108}109 110; CHECK-LABEL: xor64:111; CHECK-NEXT: .functype xor64 (i64, i64) -> (i64){{$}}112; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}113; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}114; CHECK-NEXT: i64.xor $push0=, $pop[[L0]], $pop[[L1]]{{$}}115; CHECK-NEXT: return $pop0{{$}}116define i64 @xor64(i64 %x, i64 %y) {117 %a = xor i64 %x, %y118 ret i64 %a119}120 121; CHECK-LABEL: shl64:122; CHECK-NEXT: .functype shl64 (i64, i64) -> (i64){{$}}123; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}124; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}125; CHECK-NEXT: i64.shl $push0=, $pop[[L0]], $pop[[L1]]{{$}}126; CHECK-NEXT: return $pop0{{$}}127define i64 @shl64(i64 %x, i64 %y) {128 %a = shl i64 %x, %y129 ret i64 %a130}131 132; CHECK-LABEL: shr64:133; CHECK-NEXT: .functype shr64 (i64, i64) -> (i64){{$}}134; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}135; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}136; CHECK-NEXT: i64.shr_u $push0=, $pop[[L0]], $pop[[L1]]{{$}}137; CHECK-NEXT: return $pop0{{$}}138define i64 @shr64(i64 %x, i64 %y) {139 %a = lshr i64 %x, %y140 ret i64 %a141}142 143; CHECK-LABEL: sar64:144; CHECK-NEXT: .functype sar64 (i64, i64) -> (i64){{$}}145; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}146; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}147; CHECK-NEXT: i64.shr_s $push0=, $pop[[L0]], $pop[[L1]]{{$}}148; CHECK-NEXT: return $pop0{{$}}149define i64 @sar64(i64 %x, i64 %y) {150 %a = ashr i64 %x, %y151 ret i64 %a152}153 154; CHECK-LABEL: clz64:155; CHECK-NEXT: .functype clz64 (i64) -> (i64){{$}}156; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}157; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}158; CHECK-NEXT: return $pop0{{$}}159define i64 @clz64(i64 %x) {160 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 false)161 ret i64 %a162}163 164; CHECK-LABEL: clz64_zero_undef:165; CHECK-NEXT: .functype clz64_zero_undef (i64) -> (i64){{$}}166; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}167; CHECK-NEXT: i64.clz $push0=, $pop[[L0]]{{$}}168; CHECK-NEXT: return $pop0{{$}}169define i64 @clz64_zero_undef(i64 %x) {170 %a = call i64 @llvm.ctlz.i64(i64 %x, i1 true)171 ret i64 %a172}173 174; CHECK-LABEL: ctz64:175; CHECK-NEXT: .functype ctz64 (i64) -> (i64){{$}}176; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}177; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}178; CHECK-NEXT: return $pop0{{$}}179define i64 @ctz64(i64 %x) {180 %a = call i64 @llvm.cttz.i64(i64 %x, i1 false)181 ret i64 %a182}183 184; CHECK-LABEL: ctz64_zero_undef:185; CHECK-NEXT: .functype ctz64_zero_undef (i64) -> (i64){{$}}186; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}187; CHECK-NEXT: i64.ctz $push0=, $pop[[L0]]{{$}}188; CHECK-NEXT: return $pop0{{$}}189define i64 @ctz64_zero_undef(i64 %x) {190 %a = call i64 @llvm.cttz.i64(i64 %x, i1 true)191 ret i64 %a192}193 194; CHECK-LABEL: popcnt64:195; CHECK-NEXT: .functype popcnt64 (i64) -> (i64){{$}}196; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}197; CHECK-NEXT: i64.popcnt $push0=, $pop[[L0]]{{$}}198; CHECK-NEXT: return $pop0{{$}}199define i64 @popcnt64(i64 %x) {200 %a = call i64 @llvm.ctpop.i64(i64 %x)201 ret i64 %a202}203 204; CHECK-LABEL: eqz64:205; CHECK-NEXT: .functype eqz64 (i64) -> (i32){{$}}206; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}207; CHECK-NEXT: i64.eqz $push0=, $pop[[L0]]{{$}}208; CHECK-NEXT: return $pop0{{$}}209define i32 @eqz64(i64 %x) {210 %a = icmp eq i64 %x, 0211 %b = zext i1 %a to i32212 ret i32 %b213}214 215; CHECK-LABEL: rotl:216; CHECK-NEXT: .functype rotl (i64, i64) -> (i64){{$}}217; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}218; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}219; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]220; CHECK-NEXT: return $pop0{{$}}221define i64 @rotl(i64 %x, i64 %y) {222 %z = sub i64 64, %y223 %b = shl i64 %x, %y224 %c = lshr i64 %x, %z225 %d = or i64 %b, %c226 ret i64 %d227}228 229; CHECK-LABEL: masked_rotl:230; CHECK-NEXT: .functype masked_rotl (i64, i64) -> (i64){{$}}231; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}232; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}233; CHECK-NEXT: i64.rotl $push0=, $pop[[L0]], $pop[[L1]]234; CHECK-NEXT: return $pop0{{$}}235define i64 @masked_rotl(i64 %x, i64 %y) {236 %a = and i64 %y, 63237 %z = sub i64 64, %a238 %b = shl i64 %x, %a239 %c = lshr i64 %x, %z240 %d = or i64 %b, %c241 ret i64 %d242}243 244; CHECK-LABEL: rotr:245; CHECK-NEXT: .functype rotr (i64, i64) -> (i64){{$}}246; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}247; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}248; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]249; CHECK-NEXT: return $pop0{{$}}250define i64 @rotr(i64 %x, i64 %y) {251 %z = sub i64 64, %y252 %b = lshr i64 %x, %y253 %c = shl i64 %x, %z254 %d = or i64 %b, %c255 ret i64 %d256}257 258; CHECK-LABEL: masked_rotr:259; CHECK-NEXT: .functype masked_rotr (i64, i64) -> (i64){{$}}260; CHECK-NEXT: local.get $push[[L0:[0-9]+]]=, 0{{$}}261; CHECK-NEXT: local.get $push[[L1:[0-9]+]]=, 1{{$}}262; CHECK-NEXT: i64.rotr $push0=, $pop[[L0]], $pop[[L1]]263; CHECK-NEXT: return $pop0{{$}}264define i64 @masked_rotr(i64 %x, i64 %y) {265 %a = and i64 %y, 63266 %z = sub i64 64, %a267 %b = lshr i64 %x, %a268 %c = shl i64 %x, %z269 %d = or i64 %b, %c270 ret i64 %d271}272