diff options
author | Roger Ferrer Ibanez <rofirrim@gmail.com> | 2018-06-19 06:45:47 +0000 |
---|---|---|
committer | Roger Ferrer Ibanez <rofirrim@gmail.com> | 2018-06-19 06:45:47 +0000 |
commit | ec03fbe8bbc4f00bd71d45cf617f9412ef984ada (patch) | |
tree | d67d9cef8477fe99b85a56f3cdcd011a1e47b20f /llvm/test/CodeGen/RISCV/arith-with-overflow.ll | |
parent | 3be68e162ffbf992c2efbc70983d27c05739a8b0 (diff) | |
download | bcm5719-llvm-ec03fbe8bbc4f00bd71d45cf617f9412ef984ada.tar.gz bcm5719-llvm-ec03fbe8bbc4f00bd71d45cf617f9412ef984ada.zip |
[RISCV] Add tests for overflow intrinsics
This is using the existing codegen so we can see the change once we custom
lower ISD::{U,S}{ADD,SUB}O nodes.
llvm-svn: 335023
Diffstat (limited to 'llvm/test/CodeGen/RISCV/arith-with-overflow.ll')
-rw-r--r-- | llvm/test/CodeGen/RISCV/arith-with-overflow.ll | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/RISCV/arith-with-overflow.ll b/llvm/test/CodeGen/RISCV/arith-with-overflow.ll new file mode 100644 index 00000000000..3fb6342133e --- /dev/null +++ b/llvm/test/CodeGen/RISCV/arith-with-overflow.ll @@ -0,0 +1,84 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \ +; RUN: | FileCheck -check-prefix=RV32I %s + +declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) +declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) +declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) +declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) + +define i1 @sadd(i32 %a, i32 %b, i32* %c) nounwind { +; RV32I-LABEL: sadd: +; RV32I: # %bb.0: # %entry +; RV32I-NEXT: add a3, a0, a1 +; RV32I-NEXT: sw a3, 0(a2) +; RV32I-NEXT: addi a2, zero, -1 +; RV32I-NEXT: slt a1, a2, a1 +; RV32I-NEXT: slt a0, a2, a0 +; RV32I-NEXT: slt a2, a2, a3 +; RV32I-NEXT: xor a2, a0, a2 +; RV32I-NEXT: xor a0, a0, a1 +; RV32I-NEXT: seqz a0, a0 +; RV32I-NEXT: snez a1, a2 +; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: ret +entry: + %x = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) + %calc = extractvalue {i32, i1} %x, 0 + %ovf = extractvalue {i32, i1} %x, 1 + store i32 %calc, i32* %c + ret i1 %ovf +} + +define i1 @ssub(i32 %a, i32 %b, i32* %c) nounwind { +; RV32I-LABEL: ssub: +; RV32I: # %bb.0: # %entry +; RV32I-NEXT: sub a3, a0, a1 +; RV32I-NEXT: sw a3, 0(a2) +; RV32I-NEXT: addi a2, zero, -1 +; RV32I-NEXT: slt a1, a2, a1 +; RV32I-NEXT: slt a0, a2, a0 +; RV32I-NEXT: slt a2, a2, a3 +; RV32I-NEXT: xor a2, a0, a2 +; RV32I-NEXT: xor a0, a0, a1 +; RV32I-NEXT: snez a0, a0 +; RV32I-NEXT: snez a1, a2 +; RV32I-NEXT: and a0, a0, a1 +; RV32I-NEXT: ret +entry: + %x = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) + %calc = extractvalue {i32, i1} %x, 0 + %ovf = extractvalue {i32, i1} %x, 1 + store i32 %calc, i32* %c + ret i1 %ovf +} + +define i1 @uadd(i32 %a, i32 %b, i32* %c) nounwind { +; RV32I-LABEL: uadd: +; RV32I: # %bb.0: # %entry +; RV32I-NEXT: add a1, a0, a1 +; RV32I-NEXT: sw a1, 0(a2) +; RV32I-NEXT: sltu a0, a1, a0 +; RV32I-NEXT: ret +entry: + %x = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) + %calc = extractvalue {i32, i1} %x, 0 + %ovf = extractvalue {i32, i1} %x, 1 + store i32 %calc, i32* %c + ret i1 %ovf +} + +define i1 @usub(i32 %a, i32 %b, i32* %c) nounwind { +; RV32I-LABEL: usub: +; RV32I: # %bb.0: # %entry +; RV32I-NEXT: sub a1, a0, a1 +; RV32I-NEXT: sw a1, 0(a2) +; RV32I-NEXT: sltu a0, a0, a1 +; RV32I-NEXT: ret +entry: + %x = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) + %calc = extractvalue {i32, i1} %x, 0 + %ovf = extractvalue {i32, i1} %x, 1 + store i32 %calc, i32* %c + ret i1 %ovf +} |