summaryrefslogtreecommitdiffstats
path: root/llvm/test/CodeGen/RISCV/rem.ll
diff options
context:
space:
mode:
authorAlex Bradbury <asb@lowrisc.org>2019-01-12 07:43:06 +0000
committerAlex Bradbury <asb@lowrisc.org>2019-01-12 07:43:06 +0000
commit61aa940074da0ec60a105f1ab45b45bc9815633d (patch)
treef77238ae98112692722eb4abcd9ce0cdb4a7968e /llvm/test/CodeGen/RISCV/rem.ll
parentd05eae7a7b24444c676238383037552816072052 (diff)
downloadbcm5719-llvm-61aa940074da0ec60a105f1ab45b45bc9815633d.tar.gz
bcm5719-llvm-61aa940074da0ec60a105f1ab45b45bc9815633d.zip
[RISCV] Introduce codegen patterns for RV64M-only instructions
As discussed on llvm-dev <http://lists.llvm.org/pipermail/llvm-dev/2018-December/128497.html>, we have to be careful when trying to select the *w RV64M instructions. i32 is not a legal type for RV64 in the RISC-V backend, so operations have been promoted by the time they reach instruction selection. Information about whether the operation was originally a 32-bit operations has been lost, and it's easy to write incorrect patterns. Similarly to the variable 32-bit shifts, a DAG combine on ANY_EXTEND will produce a SIGN_EXTEND if this is likely to result in sdiv/udiv/urem being selected (and so save instructions to sext/zext the input operands). Differential Revision: https://reviews.llvm.org/D53230 llvm-svn: 350993
Diffstat (limited to 'llvm/test/CodeGen/RISCV/rem.ll')
-rw-r--r--llvm/test/CodeGen/RISCV/rem.ll38
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/RISCV/rem.ll b/llvm/test/CodeGen/RISCV/rem.ll
index f37931f448e..505a351db0c 100644
--- a/llvm/test/CodeGen/RISCV/rem.ll
+++ b/llvm/test/CodeGen/RISCV/rem.ll
@@ -3,6 +3,10 @@
; RUN: | FileCheck -check-prefix=RV32I %s
; RUN: llc -mtriple=riscv32 -mattr=+m -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefix=RV32IM %s
+; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=RV64I %s
+; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
+; RUN: | FileCheck -check-prefix=RV64IM %s
define i32 @urem(i32 %a, i32 %b) nounwind {
; RV32I-LABEL: urem:
@@ -18,6 +22,24 @@ define i32 @urem(i32 %a, i32 %b) nounwind {
; RV32IM: # %bb.0:
; RV32IM-NEXT: remu a0, a0, a1
; RV32IM-NEXT: ret
+;
+; RV64I-LABEL: urem:
+; RV64I: # %bb.0:
+; RV64I-NEXT: addi sp, sp, -16
+; RV64I-NEXT: sd ra, 8(sp)
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: slli a1, a1, 32
+; RV64I-NEXT: srli a1, a1, 32
+; RV64I-NEXT: call __umoddi3
+; RV64I-NEXT: ld ra, 8(sp)
+; RV64I-NEXT: addi sp, sp, 16
+; RV64I-NEXT: ret
+;
+; RV64IM-LABEL: urem:
+; RV64IM: # %bb.0:
+; RV64IM-NEXT: remuw a0, a0, a1
+; RV64IM-NEXT: ret
%1 = urem i32 %a, %b
ret i32 %1
}
@@ -36,6 +58,22 @@ define i32 @srem(i32 %a, i32 %b) nounwind {
; RV32IM: # %bb.0:
; RV32IM-NEXT: rem a0, a0, a1
; RV32IM-NEXT: ret
+;
+; RV64I-LABEL: srem:
+; RV64I: # %bb.0:
+; RV64I-NEXT: addi sp, sp, -16
+; RV64I-NEXT: sd ra, 8(sp)
+; RV64I-NEXT: sext.w a0, a0
+; RV64I-NEXT: sext.w a1, a1
+; RV64I-NEXT: call __moddi3
+; RV64I-NEXT: ld ra, 8(sp)
+; RV64I-NEXT: addi sp, sp, 16
+; RV64I-NEXT: ret
+;
+; RV64IM-LABEL: srem:
+; RV64IM: # %bb.0:
+; RV64IM-NEXT: remw a0, a0, a1
+; RV64IM-NEXT: ret
%1 = srem i32 %a, %b
ret i32 %1
}
OpenPOWER on IntegriCloud