[LoongArch] Add codegen support for fneg

Reference:
https://llvm.org/docs/LangRef.html#fneg-instruction

Differential Revision: https://reviews.llvm.org/D127200
This commit is contained in:
Weining Lu 2022-06-20 09:44:38 +08:00
parent a992115545
commit efc70058d9
4 changed files with 64 additions and 0 deletions

View File

@ -113,6 +113,8 @@ def FSTLE_S : FP_STORE_3R<0b00111000011101110, "fstle.s", FPR32>;
/// Generic pattern classes
class PatFpr<SDPatternOperator OpNode, LAInst Inst, RegisterClass RegTy>
: Pat<(OpNode RegTy:$fj), (Inst $fj)>;
class PatFprFpr<SDPatternOperator OpNode, LAInst Inst, RegisterClass RegTy>
: Pat<(OpNode RegTy:$fj, RegTy:$fk), (Inst $fj, $fk)>;
@ -124,5 +126,6 @@ def : PatFprFpr<fadd, FADD_S, FPR32>;
def : PatFprFpr<fsub, FSUB_S, FPR32>;
def : PatFprFpr<fmul, FMUL_S, FPR32>;
def : PatFprFpr<fdiv, FDIV_S, FPR32>;
def : PatFpr<fneg, FNEG_S, FPR32>;
} // Predicates = [HasBasicF]

View File

@ -143,5 +143,6 @@ def : PatFprFpr<fadd, FADD_D, FPR64>;
def : PatFprFpr<fsub, FSUB_D, FPR64>;
def : PatFprFpr<fmul, FMUL_D, FPR64>;
def : PatFprFpr<fdiv, FDIV_D, FPR64>;
def : PatFpr<fneg, FNEG_D, FPR64>;
} // Predicates = [HasBasicD]

View File

@ -0,0 +1,32 @@
; RUN: llc --mtriple=loongarch32 --mattr=+d < %s | FileCheck %s --check-prefix=LA32
; RUN: llc --mtriple=loongarch64 --mattr=+d < %s | FileCheck %s --check-prefix=LA64
;; Exercise the 'fneg' LLVM IR: https://llvm.org/docs/LangRef.html#fneg-instruction
define float @fneg_s(float %x) {
; LA32-LABEL: fneg_s:
; LA32: # %bb.0:
; LA32-NEXT: fneg.s $fa0, $fa0
; LA32-NEXT: jirl $zero, $ra, 0
;
; LA64-LABEL: fneg_s:
; LA64: # %bb.0:
; LA64-NEXT: fneg.s $fa0, $fa0
; LA64-NEXT: jirl $zero, $ra, 0
%neg = fneg float %x
ret float %neg
}
define double @fneg_d(double %x) {
; LA32-LABEL: fneg_d:
; LA32: # %bb.0:
; LA32-NEXT: fneg.d $fa0, $fa0
; LA32-NEXT: jirl $zero, $ra, 0
;
; LA64-LABEL: fneg_d:
; LA64: # %bb.0:
; LA64-NEXT: fneg.d $fa0, $fa0
; LA64-NEXT: jirl $zero, $ra, 0
%neg = fneg double %x
ret double %neg
}

View File

@ -30,3 +30,31 @@ define double @fsub_d(double %x, double %y) {
%sub = fsub double %x, %y
ret double %sub
}
define float @fneg_s(float %x) {
; LA32-LABEL: fneg_s:
; LA32: # %bb.0:
; LA32-NEXT: fneg.s $fa0, $fa0
; LA32-NEXT: jirl $zero, $ra, 0
;
; LA64-LABEL: fneg_s:
; LA64: # %bb.0:
; LA64-NEXT: fneg.s $fa0, $fa0
; LA64-NEXT: jirl $zero, $ra, 0
%res = fsub float -0.0, %x
ret float %res
}
define double @fneg_d(double %x) {
; LA32-LABEL: fneg_d:
; LA32: # %bb.0:
; LA32-NEXT: fneg.d $fa0, $fa0
; LA32-NEXT: jirl $zero, $ra, 0
;
; LA64-LABEL: fneg_d:
; LA64: # %bb.0:
; LA64-NEXT: fneg.d $fa0, $fa0
; LA64-NEXT: jirl $zero, $ra, 0
%res = fsub double -0.0, %x
ret double %res
}