Skip to content

Commit

Permalink
[AArch64][SVE2p1] Add SVE2.1 fclamp intrinsic
Browse files Browse the repository at this point in the history
Adds an intrinsic for the following instruction:

* fclamp

Differential Revision: https://reviews.llvm.org/D141942
  • Loading branch information
david-arm committed Jan 23, 2023
1 parent 0276fa8 commit 3bd77c2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsAArch64.td
Expand Up @@ -2684,6 +2684,8 @@ let TargetPrefix = "aarch64" in {

def int_aarch64_sve_sclamp : AdvSIMD_3VectorArg_Intrinsic;
def int_aarch64_sve_uclamp : AdvSIMD_3VectorArg_Intrinsic;
def int_aarch64_sve_fclamp : AdvSIMD_3VectorArg_Intrinsic;


//
// Reversal
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
Expand Up @@ -3673,7 +3673,7 @@ defm PSEL_PPPRI : sve2_int_perm_sel_p<"psel", int_aarch64_sve_psel>;
//===----------------------------------------------------------------------===//

let Predicates = [HasSVE2p1_or_HasSME2] in {
defm FCLAMP_ZZZ : sve2p1_fclamp<"fclamp">;
defm FCLAMP_ZZZ : sve2p1_fclamp<"fclamp", int_aarch64_sve_fclamp>;
def FDOT_ZZZ_S : sve_float_dot<0b0, "fdot">;
def FDOT_ZZZI_S : sve_float_dot_indexed<0b0, "fdot">;
def BFMLSLB_ZZZ_S : sve2_fp_mla_long<0b110, "bfmlslb">;
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/AArch64/SVEInstrFormats.td
Expand Up @@ -8725,10 +8725,14 @@ class sve2p1_fclamp<string asm, bits<2> sz, ZPRRegOp zpr_ty>
let ElementSize = zpr_ty.ElementSize;
}

multiclass sve2p1_fclamp<string asm> {
multiclass sve2p1_fclamp<string asm, SDPatternOperator op> {
def _H : sve2p1_fclamp<asm, 0b01, ZPR16>;
def _S : sve2p1_fclamp<asm, 0b10, ZPR32>;
def _D : sve2p1_fclamp<asm, 0b11, ZPR64>;

def : SVE_3_Op_Pat<nxv8f16, op, nxv8f16, nxv8f16, nxv8f16, !cast<Instruction>(NAME # _H)>;
def : SVE_3_Op_Pat<nxv4f32, op, nxv4f32, nxv4f32, nxv4f32, !cast<Instruction>(NAME # _S)>;
def : SVE_3_Op_Pat<nxv2f64, op, nxv2f64, nxv2f64, nxv2f64, !cast<Instruction>(NAME # _D)>;
}

// SVE two-way dot product
Expand Down
37 changes: 37 additions & 0 deletions llvm/test/CodeGen/AArch64/sve2p1-intrinsics-fclamp.ll
@@ -0,0 +1,37 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -verify-machineinstrs < %s | FileCheck %s

target triple = "aarch64-linux-gnu"

define <vscale x 8 x half> @test_fclamp_f16(<vscale x 8 x half> %a, <vscale x 8 x half> %b, <vscale x 8 x half> %c) #0 {
; CHECK-LABEL: test_fclamp_f16:
; CHECK: // %bb.0:
; CHECK-NEXT: fclamp z0.h, z1.h, z2.h
; CHECK-NEXT: ret
%res = call <vscale x 8 x half> @llvm.aarch64.sve.fclamp.nxv8f16(<vscale x 8 x half> %a, <vscale x 8 x half> %b, <vscale x 8 x half> %c)
ret <vscale x 8 x half> %res
}

define <vscale x 4 x float> @test_fclamp_f32(<vscale x 4 x float> %a, <vscale x 4 x float> %b, <vscale x 4 x float> %c) #0 {
; CHECK-LABEL: test_fclamp_f32:
; CHECK: // %bb.0:
; CHECK-NEXT: fclamp z0.s, z1.s, z2.s
; CHECK-NEXT: ret
%res = call <vscale x 4 x float> @llvm.aarch64.sve.fclamp.nxv4f32(<vscale x 4 x float> %a, <vscale x 4 x float> %b, <vscale x 4 x float> %c)
ret <vscale x 4 x float> %res
}

define <vscale x 2 x double> @test_fclamp_f64(<vscale x 2 x double> %a, <vscale x 2 x double> %b, <vscale x 2 x double> %c) #0 {
; CHECK-LABEL: test_fclamp_f64:
; CHECK: // %bb.0:
; CHECK-NEXT: fclamp z0.d, z1.d, z2.d
; CHECK-NEXT: ret
%res = call <vscale x 2 x double> @llvm.aarch64.sve.fclamp.nxv2f64(<vscale x 2 x double> %a, <vscale x 2 x double> %b, <vscale x 2 x double> %c)
ret <vscale x 2 x double> %res
}

attributes #0 = { "target-features"="+sve2p1" }

declare <vscale x 8 x half> @llvm.aarch64.sve.fclamp.nxv8f16(<vscale x 8 x half>, <vscale x 8 x half>, <vscale x 8 x half>)
declare <vscale x 4 x float> @llvm.aarch64.sve.fclamp.nxv4f32(<vscale x 4 x float>, <vscale x 4 x float>, <vscale x 4 x float>)
declare <vscale x 2 x double> @llvm.aarch64.sve.fclamp.nxv2f64(<vscale x 2 x double>, <vscale x 2 x double>, <vscale x 2 x double>)

0 comments on commit 3bd77c2

Please sign in to comment.