Skip to content

Commit 8c61bef

Browse files
authored
GlobalISel: Translate minimumnum and maximumnum (#139106)
1 parent c526683 commit 8c61bef

File tree

8 files changed

+100
-1
lines changed

8 files changed

+100
-1
lines changed

llvm/docs/GlobalISel/GenericOpcode.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,16 @@ NaN-propagating maximum that also treat -0.0 as less than 0.0. While
608608
FMAXNUM_IEEE follow IEEE 754-2008 semantics, FMAXIMUM follows IEEE
609609
754-2019 semantics.
610610

611+
G_FMINIMUMNUM
612+
^^^^^^^^^^^^^
613+
614+
IEEE-754 2019 minimumNumber
615+
616+
G_FMAXIMUMNUM
617+
^^^^^^^^^^^^^
618+
619+
IEEE-754 2019 maximumNumber
620+
611621
G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FREM
612622
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
613623

llvm/include/llvm/Support/TargetOpcodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ HANDLE_TARGET_OPCODE(G_FMAXNUM_IEEE)
724724
/// FP min/max matching IEEE-754 2018 draft semantics.
725725
HANDLE_TARGET_OPCODE(G_FMINIMUM)
726726
HANDLE_TARGET_OPCODE(G_FMAXIMUM)
727+
HANDLE_TARGET_OPCODE(G_FMINIMUMNUM)
728+
HANDLE_TARGET_OPCODE(G_FMAXIMUMNUM)
727729

728730
/// Access to FP environment.
729731
HANDLE_TARGET_OPCODE(G_GET_FPENV)

llvm/include/llvm/Target/GenericOpcodes.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,21 @@ def G_FMAXIMUM : GenericInstruction {
885885
let isCommutable = true;
886886
}
887887

888+
/// G_FMINIMUMNUM/G_FMAXIMUMNUM - IEEE-754 2019 minimumNumber/maximumNumber
889+
def G_FMINIMUMNUM : GenericInstruction {
890+
let OutOperandList = (outs type0:$dst);
891+
let InOperandList = (ins type0:$src1, type0:$src2);
892+
let hasSideEffects = false;
893+
let isCommutable = true;
894+
}
895+
896+
def G_FMAXIMUMNUM : GenericInstruction {
897+
let OutOperandList = (outs type0:$dst);
898+
let InOperandList = (ins type0:$src1, type0:$src2);
899+
let hasSideEffects = false;
900+
let isCommutable = true;
901+
}
902+
888903
//------------------------------------------------------------------------------
889904
// Floating Point Binary ops.
890905
//------------------------------------------------------------------------------

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,10 @@ unsigned IRTranslator::getSimpleIntrinsicOpcode(Intrinsic::ID ID) {
19291929
return TargetOpcode::G_FMINIMUM;
19301930
case Intrinsic::maximum:
19311931
return TargetOpcode::G_FMAXIMUM;
1932+
case Intrinsic::minimumnum:
1933+
return TargetOpcode::G_FMINIMUMNUM;
1934+
case Intrinsic::maximumnum:
1935+
return TargetOpcode::G_FMAXIMUMNUM;
19321936
case Intrinsic::canonicalize:
19331937
return TargetOpcode::G_FCANONICALIZE;
19341938
case Intrinsic::floor:

llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-fp-min-max-intrinsics.ll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,62 @@ define float @test_maximum(float %x, float %y) {
7979
ret float %val
8080
}
8181

82+
define float @test_minimumnum(float %x, float %y) {
83+
; CHECK-LABEL: name: test_minimumnum
84+
; CHECK: bb.1 (%ir-block.0):
85+
; CHECK-NEXT: liveins: $s0, $s1
86+
; CHECK-NEXT: {{ $}}
87+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
88+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
89+
; CHECK-NEXT: [[FMINIMUMNUM:%[0-9]+]]:_(s32) = G_FMINIMUMNUM [[COPY]], [[COPY1]]
90+
; CHECK-NEXT: $s0 = COPY [[FMINIMUMNUM]](s32)
91+
; CHECK-NEXT: RET_ReallyLR implicit $s0
92+
%val = call float @llvm.minimumnum.f32(float %x, float %y)
93+
ret float %val
94+
}
95+
96+
define float @test_minimumnum_nnan(float %x, float %y) {
97+
; CHECK-LABEL: name: test_minimumnum_nnan
98+
; CHECK: bb.1 (%ir-block.0):
99+
; CHECK-NEXT: liveins: $s0, $s1
100+
; CHECK-NEXT: {{ $}}
101+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
102+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
103+
; CHECK-NEXT: [[FMINIMUMNUM:%[0-9]+]]:_(s32) = nnan G_FMINIMUMNUM [[COPY]], [[COPY1]]
104+
; CHECK-NEXT: $s0 = COPY [[FMINIMUMNUM]](s32)
105+
; CHECK-NEXT: RET_ReallyLR implicit $s0
106+
%val = call nnan float @llvm.minimumnum.f32(float %x, float %y)
107+
ret float %val
108+
}
109+
110+
define float @test_maximumnum(float %x, float %y) {
111+
; CHECK-LABEL: name: test_maximumnum
112+
; CHECK: bb.1 (%ir-block.0):
113+
; CHECK-NEXT: liveins: $s0, $s1
114+
; CHECK-NEXT: {{ $}}
115+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
116+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
117+
; CHECK-NEXT: [[FMAXIMUMNUM:%[0-9]+]]:_(s32) = G_FMAXIMUMNUM [[COPY]], [[COPY1]]
118+
; CHECK-NEXT: $s0 = COPY [[FMAXIMUMNUM]](s32)
119+
; CHECK-NEXT: RET_ReallyLR implicit $s0
120+
%val = call float @llvm.maximumnum.f32(float %x, float %y)
121+
ret float %val
122+
}
123+
124+
define float @test_maximumnum_nnan(float %x, float %y) {
125+
; CHECK-LABEL: name: test_maximumnum_nnan
126+
; CHECK: bb.1 (%ir-block.0):
127+
; CHECK-NEXT: liveins: $s0, $s1
128+
; CHECK-NEXT: {{ $}}
129+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $s0
130+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $s1
131+
; CHECK-NEXT: [[FMAXIMUMNUM:%[0-9]+]]:_(s32) = nnan G_FMAXIMUMNUM [[COPY]], [[COPY1]]
132+
; CHECK-NEXT: $s0 = COPY [[FMAXIMUMNUM]](s32)
133+
; CHECK-NEXT: RET_ReallyLR implicit $s0
134+
%val = call nnan float @llvm.maximumnum.f32(float %x, float %y)
135+
ret float %val
136+
}
137+
82138
declare float @llvm.minnum.f32(float, float) #0
83139
declare float @llvm.maxnum.f32(float, float) #0
84140

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@
598598
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
599599
# DEBUG-NEXT: .. the first uncovered type index: 1, OK
600600
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
601+
# DEBUG-NEXT: G_FMINIMUMNUM (opcode {{[0-9]+}}): 1 type index
602+
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
603+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
604+
# DEBUG-NEXT: G_FMAXIMUMNUM (opcode {{[0-9]+}}): 1 type index
605+
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
606+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
601607
# DEBUG-NEXT: G_GET_FPENV (opcode {{[0-9]+}}): 1 type index, 0 imm indices
602608
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
603609
# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected

llvm/test/CodeGen/RISCV/GlobalISel/legalizer-info-validation.mir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@
591591
# DEBUG-NEXT: G_FMAXIMUM (opcode {{[0-9]+}}): 1 type index
592592
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
593593
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
594+
# DEBUG-NEXT: G_FMINIMUMNUM (opcode {{[0-9]+}}): 1 type index
595+
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
596+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
597+
# DEBUG-NEXT: G_FMAXIMUMNUM (opcode {{[0-9]+}}): 1 type index
598+
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
599+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
594600
# DEBUG-NEXT: G_GET_FPENV (opcode {{[0-9]+}}): 1 type index, 0 imm indices
595601
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
596602
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined

llvm/test/TableGen/GlobalISelEmitter/GlobalISelEmitter.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def : Pat<(frag GPR32:$src1, complex:$src2, complex:$src3),
513513
// R00O-NEXT: GIM_Reject,
514514
// R00O: // Label [[DEFAULT_NUM]]: @[[DEFAULT]]
515515
// R00O-NEXT: GIM_Reject,
516-
// R00O-NEXT: }; // Size: 1848 bytes
516+
// R00O-NEXT: }; // Size: 1856 bytes
517517

518518
def INSNBOB : I<(outs GPR32:$dst), (ins GPR32:$src1, GPR32:$src2, GPR32:$src3, GPR32:$src4),
519519
[(set GPR32:$dst,

0 commit comments

Comments
 (0)