blob: 4358fb5a1b8ea85b9f90fa62811db705297584f3 [file] [log] [blame]
Roger Ferrer Ibanezec03fbe2018-06-19 06:45:47 +00001; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3; RUN: | FileCheck -check-prefix=RV32I %s
4
5declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
6declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
7declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
8declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
9
10define i1 @sadd(i32 %a, i32 %b, i32* %c) nounwind {
11; RV32I-LABEL: sadd:
12; RV32I: # %bb.0: # %entry
Roger Ferrer Ibanez5a2a14d2019-09-30 07:58:50 +000013; RV32I-NEXT: add a3, a0, a1
14; RV32I-NEXT: slt a0, a3, a0
15; RV32I-NEXT: slti a1, a1, 0
16; RV32I-NEXT: xor a0, a1, a0
17; RV32I-NEXT: sw a3, 0(a2)
Roger Ferrer Ibanezec03fbe2018-06-19 06:45:47 +000018; RV32I-NEXT: ret
19entry:
20 %x = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
21 %calc = extractvalue {i32, i1} %x, 0
22 %ovf = extractvalue {i32, i1} %x, 1
23 store i32 %calc, i32* %c
24 ret i1 %ovf
25}
26
27define i1 @ssub(i32 %a, i32 %b, i32* %c) nounwind {
28; RV32I-LABEL: ssub:
29; RV32I: # %bb.0: # %entry
Roger Ferrer Ibanez5a2a14d2019-09-30 07:58:50 +000030; RV32I-NEXT: sgtz a3, a1
Luis Marques3d0fbaf2019-09-17 11:15:35 +000031; RV32I-NEXT: sub a1, a0, a1
Roger Ferrer Ibanez5a2a14d2019-09-30 07:58:50 +000032; RV32I-NEXT: slt a0, a1, a0
33; RV32I-NEXT: xor a0, a3, a0
Luis Marques3d0fbaf2019-09-17 11:15:35 +000034; RV32I-NEXT: sw a1, 0(a2)
Roger Ferrer Ibanezec03fbe2018-06-19 06:45:47 +000035; RV32I-NEXT: ret
36entry:
37 %x = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
38 %calc = extractvalue {i32, i1} %x, 0
39 %ovf = extractvalue {i32, i1} %x, 1
40 store i32 %calc, i32* %c
41 ret i1 %ovf
42}
43
44define i1 @uadd(i32 %a, i32 %b, i32* %c) nounwind {
45; RV32I-LABEL: uadd:
46; RV32I: # %bb.0: # %entry
47; RV32I-NEXT: add a1, a0, a1
Luis Marques2d550d12019-09-17 10:52:09 +000048; RV32I-NEXT: sltu a0, a1, a0
Luis Marques3d0fbaf2019-09-17 11:15:35 +000049; RV32I-NEXT: sw a1, 0(a2)
Roger Ferrer Ibanezec03fbe2018-06-19 06:45:47 +000050; RV32I-NEXT: ret
51entry:
52 %x = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
53 %calc = extractvalue {i32, i1} %x, 0
54 %ovf = extractvalue {i32, i1} %x, 1
55 store i32 %calc, i32* %c
56 ret i1 %ovf
57}
58
59define i1 @usub(i32 %a, i32 %b, i32* %c) nounwind {
60; RV32I-LABEL: usub:
61; RV32I: # %bb.0: # %entry
62; RV32I-NEXT: sub a1, a0, a1
Luis Marques2d550d12019-09-17 10:52:09 +000063; RV32I-NEXT: sltu a0, a0, a1
Luis Marques3d0fbaf2019-09-17 11:15:35 +000064; RV32I-NEXT: sw a1, 0(a2)
Roger Ferrer Ibanezec03fbe2018-06-19 06:45:47 +000065; RV32I-NEXT: ret
66entry:
67 %x = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
68 %calc = extractvalue {i32, i1} %x, 0
69 %ovf = extractvalue {i32, i1} %x, 1
70 store i32 %calc, i32* %c
71 ret i1 %ovf
72}