Files
llvm/test/CodeGen/ARM/GlobalISel/arm-isel-fp.ll
T
Diana Picus a479e53b55 [ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
  with the MOVi, or move 1 into the result register, based on the values
  of the flags

As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.

Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.

Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307365 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-07 08:39:04 +00:00

82 lines
2.4 KiB
LLVM

; RUN: llc -mtriple arm-linux-gnueabihf -mattr=+vfp2 -float-abi=hard -global-isel %s -o - | FileCheck %s -check-prefix CHECK -check-prefix HARD
; RUN: llc -mtriple arm-linux-gnueabi -mattr=+vfp2,+soft-float -float-abi=soft -global-isel %s -o - | FileCheck %s -check-prefix CHECK -check-prefix SOFT-AEABI
; RUN: llc -mtriple arm-linux-gnu- -mattr=+vfp2,+soft-float -float-abi=soft -global-isel %s -o - | FileCheck %s -check-prefix CHECK -check-prefix SOFT-DEFAULT
define arm_aapcscc float @test_frem_float(float %x, float %y) {
; CHECK-LABEL: test_frem_float:
; CHECK: blx fmodf
%r = frem float %x, %y
ret float %r
}
define arm_aapcscc double @test_frem_double(double %x, double %y) {
; CHECK-LABEL: test_frem_double:
; CHECK: blx fmod
%r = frem double %x, %y
ret double %r
}
declare float @llvm.pow.f32(float %x, float %y)
define arm_aapcscc float @test_fpow_float(float %x, float %y) {
; CHECK-LABEL: test_fpow_float:
; CHECK: blx powf
%r = call float @llvm.pow.f32(float %x, float %y)
ret float %r
}
declare double @llvm.pow.f64(double %x, double %y)
define arm_aapcscc double @test_fpow_double(double %x, double %y) {
; CHECK-LABEL: test_fpow_double:
; CHECK: blx pow
%r = call double @llvm.pow.f64(double %x, double %y)
ret double %r
}
define arm_aapcscc float @test_add_float(float %x, float %y) {
; CHECK-LABEL: test_add_float:
; HARD: vadd.f32
; SOFT-AEABI: blx __aeabi_fadd
; SOFT-DEFAULT: blx __addsf3
%r = fadd float %x, %y
ret float %r
}
define arm_aapcscc double @test_add_double(double %x, double %y) {
; CHECK-LABEL: test_add_double:
; HARD: vadd.f64
; SOFT-AEABI: blx __aeabi_dadd
; SOFT-DEFAULT: blx __adddf3
%r = fadd double %x, %y
ret double %r
}
define arm_aapcs_vfpcc i32 @test_cmp_float_ogt(float %x, float %y) {
; CHECK-LABEL: test_cmp_float_ogt
; HARD: vcmp.f32
; HARD: vmrs APSR_nzcv, fpscr
; HARD-NEXT: movgt
; SOFT-AEABI: blx __aeabi_fcmpgt
; SOFT-DEFAULT: blx __gtsf2
entry:
%v = fcmp ogt float %x, %y
%r = zext i1 %v to i32
ret i32 %r
}
define arm_aapcs_vfpcc i32 @test_cmp_float_one(float %x, float %y) {
; CHECK-LABEL: test_cmp_float_one
; HARD: vcmp.f32
; HARD: vmrs APSR_nzcv, fpscr
; HARD: movgt
; HARD-NOT: vcmp
; HARD: movmi
; SOFT-AEABI-DAG: blx __aeabi_fcmpgt
; SOFT-AEABI-DAG: blx __aeabi_fcmplt
; SOFT-DEFAULT-DAG: blx __gtsf2
; SOFT-DEFAULT-DAG: blx __ltsf2
entry:
%v = fcmp one float %x, %y
%r = zext i1 %v to i32
ret i32 %r
}