Skip to content

GlobalISel: Translate minimumnum and maximumnum #139106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/docs/GlobalISel/GenericOpcode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ NaN-propagating maximum that also treat -0.0 as less than 0.0. While
FMAXNUM_IEEE follow IEEE 754-2008 semantics, FMAXIMUM follows IEEE
754-2019 semantics.

G_FMINIMUMNUM
^^^^^^^^^^^^^

IEEE-754 2019 minimumNumber

G_FMAXIMUMNUM
^^^^^^^^^^^^^

IEEE-754 2019 maximumNumber

G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FREM
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Support/TargetOpcodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ HANDLE_TARGET_OPCODE(G_FMAXNUM_IEEE)
/// FP min/max matching IEEE-754 2018 draft semantics.
HANDLE_TARGET_OPCODE(G_FMINIMUM)
HANDLE_TARGET_OPCODE(G_FMAXIMUM)
HANDLE_TARGET_OPCODE(G_FMINIMUMNUM)
HANDLE_TARGET_OPCODE(G_FMAXIMUMNUM)

/// Access to FP environment.
HANDLE_TARGET_OPCODE(G_GET_FPENV)
Expand Down
15 changes: 15 additions & 0 deletions llvm/include/llvm/Target/GenericOpcodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,21 @@ def G_FMAXIMUM : GenericInstruction {
let isCommutable = true;
}

/// G_FMINIMUMNUM/G_FMAXIMUMNUM - IEEE-754 2019 minimumNumber/maximumNumber
def G_FMINIMUMNUM : GenericInstruction {
let OutOperandList = (outs type0:$dst);
let InOperandList = (ins type0:$src1, type0:$src2);
let hasSideEffects = false;
let isCommutable = true;
}

def G_FMAXIMUMNUM : GenericInstruction {
let OutOperandList = (outs type0:$dst);
let InOperandList = (ins type0:$src1, type0:$src2);
let hasSideEffects = false;
let isCommutable = true;
}

//------------------------------------------------------------------------------
// Floating Point Binary ops.
//------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,10 @@ unsigned IRTranslator::getSimpleIntrinsicOpcode(Intrinsic::ID ID) {
return TargetOpcode::G_FMINIMUM;
case Intrinsic::maximum:
return TargetOpcode::G_FMAXIMUM;
case Intrinsic::minimumnum:
return TargetOpcode::G_FMINIMUMNUM;
case Intrinsic::maximumnum:
return TargetOpcode::G_FMAXIMUMNUM;
case Intrinsic::canonicalize:
return TargetOpcode::G_FCANONICALIZE;
case Intrinsic::floor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,62 @@ define float @test_maximum(float %x, float %y) {
ret float %val
}

define float @test_minimumnum(float %x, float %y) {
; CHECK-LABEL: name: test_minimumnum
; CHECK: bb.1 (%ir-block.0):
; CHECK-NEXT: liveins: $s0, $s1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
; CHECK-NEXT: [[FMINIMUMNUM:%[0-9]+]]:_(s32) = G_FMINIMUMNUM [[COPY]], [[COPY1]]
; CHECK-NEXT: $s0 = COPY [[FMINIMUMNUM]](s32)
; CHECK-NEXT: RET_ReallyLR implicit $s0
%val = call float @llvm.minimumnum.f32(float %x, float %y)
ret float %val
}

define float @test_minimumnum_nnan(float %x, float %y) {
; CHECK-LABEL: name: test_minimumnum_nnan
; CHECK: bb.1 (%ir-block.0):
; CHECK-NEXT: liveins: $s0, $s1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
; CHECK-NEXT: [[FMINIMUMNUM:%[0-9]+]]:_(s32) = nnan G_FMINIMUMNUM [[COPY]], [[COPY1]]
; CHECK-NEXT: $s0 = COPY [[FMINIMUMNUM]](s32)
; CHECK-NEXT: RET_ReallyLR implicit $s0
%val = call nnan float @llvm.minimumnum.f32(float %x, float %y)
ret float %val
}

define float @test_maximumnum(float %x, float %y) {
; CHECK-LABEL: name: test_maximumnum
; CHECK: bb.1 (%ir-block.0):
; CHECK-NEXT: liveins: $s0, $s1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
; CHECK-NEXT: [[FMAXIMUMNUM:%[0-9]+]]:_(s32) = G_FMAXIMUMNUM [[COPY]], [[COPY1]]
; CHECK-NEXT: $s0 = COPY [[FMAXIMUMNUM]](s32)
; CHECK-NEXT: RET_ReallyLR implicit $s0
%val = call float @llvm.maximumnum.f32(float %x, float %y)
ret float %val
}

define float @test_maximumnum_nnan(float %x, float %y) {
; CHECK-LABEL: name: test_maximumnum_nnan
; CHECK: bb.1 (%ir-block.0):
; CHECK-NEXT: liveins: $s0, $s1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
; CHECK-NEXT: [[FMAXIMUMNUM:%[0-9]+]]:_(s32) = nnan G_FMAXIMUMNUM [[COPY]], [[COPY1]]
; CHECK-NEXT: $s0 = COPY [[FMAXIMUMNUM]](s32)
; CHECK-NEXT: RET_ReallyLR implicit $s0
%val = call nnan float @llvm.maximumnum.f32(float %x, float %y)
ret float %val
}

declare float @llvm.minnum.f32(float, float) #0
declare float @llvm.maxnum.f32(float, float) #0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
# DEBUG-NEXT: .. the first uncovered type index: 1, OK
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
# DEBUG-NEXT: G_FMINIMUMNUM (opcode {{[0-9]+}}): 1 type index
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: G_FMAXIMUMNUM (opcode {{[0-9]+}}): 1 type index
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: G_GET_FPENV (opcode {{[0-9]+}}): 1 type index, 0 imm indices
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@
# DEBUG-NEXT: G_FMAXIMUM (opcode {{[0-9]+}}): 1 type index
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: G_FMINIMUMNUM (opcode {{[0-9]+}}): 1 type index
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: G_FMAXIMUMNUM (opcode {{[0-9]+}}): 1 type index
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: G_GET_FPENV (opcode {{[0-9]+}}): 1 type index, 0 imm indices
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/TableGen/GlobalISelEmitter/GlobalISelEmitter.td
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def : Pat<(frag GPR32:$src1, complex:$src2, complex:$src3),
// R00O-NEXT: GIM_Reject,
// R00O: // Label [[DEFAULT_NUM]]: @[[DEFAULT]]
// R00O-NEXT: GIM_Reject,
// R00O-NEXT: }; // Size: 1848 bytes
// R00O-NEXT: }; // Size: 1856 bytes

def INSNBOB : I<(outs GPR32:$dst), (ins GPR32:$src1, GPR32:$src2, GPR32:$src3, GPR32:$src4),
[(set GPR32:$dst,
Expand Down
Loading