diff --git a/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td --- a/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td @@ -113,6 +113,8 @@ /// Generic pattern classes +class PatFpr + : Pat<(OpNode RegTy:$fj), (Inst $fj)>; class PatFprFpr : Pat<(OpNode RegTy:$fj, RegTy:$fk), (Inst $fj, $fk)>; @@ -124,5 +126,6 @@ def : PatFprFpr; def : PatFprFpr; def : PatFprFpr; +def : PatFpr; } // Predicates = [HasBasicF] diff --git a/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td --- a/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchFloat64InstrInfo.td @@ -143,5 +143,6 @@ def : PatFprFpr; def : PatFprFpr; def : PatFprFpr; +def : PatFpr; } // Predicates = [HasBasicD] diff --git a/llvm/test/CodeGen/LoongArch/ir-instruction/fneg.ll b/llvm/test/CodeGen/LoongArch/ir-instruction/fneg.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/LoongArch/ir-instruction/fneg.ll @@ -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 +} diff --git a/llvm/test/CodeGen/LoongArch/ir-instruction/fsub.ll b/llvm/test/CodeGen/LoongArch/ir-instruction/fsub.ll --- a/llvm/test/CodeGen/LoongArch/ir-instruction/fsub.ll +++ b/llvm/test/CodeGen/LoongArch/ir-instruction/fsub.ll @@ -30,3 +30,31 @@ %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 +}