Skip to content

[AArch64][NEON] Extend faminmax patterns with fminnm/fmaxnm #104766

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 3 commits into from
Aug 20, 2024
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
37 changes: 25 additions & 12 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,17 @@ def smullwithsignbits : PatFrag<(ops node:$l, node:$r), (mul node:$l, node:$r),
CurDAG->ComputeNumSignBits(N->getOperand(1)) > 32;
}]>;

// Match "nnan" flagged calls to fminnum and fmmaxnum. Then semantically equivalent
// to fmaximum/fminimum.
def fmaxnum_nnan : PatFrag<(ops node:$Rn, node:$Rm),
(fmaxnum node:$Rn, node:$Rm), [{
return N->getFlags().hasNoNaNs();
}]>;
def fminnum_nnan : PatFrag<(ops node:$Rn, node:$Rm),
(fminnum node:$Rn, node:$Rm), [{
return N->getFlags().hasNoNaNs();
}]>;

//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -10158,19 +10169,21 @@ let Uses = [FPMR, FPCR], Predicates = [HasFP8] in {
defm FSCALE : SIMDThreeSameVectorFP<0b1, 0b1, 0b111, "fscale", null_frag>;
} // End let Predicates = [HasFP8]

// fminimum(abs(a), abs(b)) -> famin(a, b)
// fminnum[nnan](abs(a), abs(b)) -> famin(a, b)
def AArch64famin : PatFrags<(ops node:$Rn, node:$Rm),
[(fminimum (fabs node:$Rn), (fabs node:$Rm)),
(fminnum_nnan (fabs node:$Rn), (fabs node:$Rm))]>;

// fmaximum(abs(a), abs(b)) -> famax(a, b)
// fmaxnum[nnan](abs(a), abs(b)) -> famax(a, b)
def AArch64famax : PatFrags<(ops node:$Rn, node:$Rm),
[(fmaximum (fabs node:$Rn), (fabs node:$Rm)),
(fmaxnum_nnan (fabs node:$Rn), (fabs node:$Rm))]>;

let Predicates = [HasNEON, HasFAMINMAX] in {
defm FAMAX : SIMDThreeSameVectorFP<0b0, 0b1, 0b011, "famax", null_frag>;
defm FAMIN : SIMDThreeSameVectorFP<0b1, 0b1, 0b011, "famin", null_frag>;

foreach Ty = [v4f16, v8f16, v2f32, v4f32, v2f64] in {
// Replace min(abs(a), abs(b)) with famin(a, b)
def : Pat<(Ty (fminimum (fabs Ty:$Rn), (fabs Ty:$Rm))),
(!cast<Instruction>("FAMIN"#Ty) Ty:$Rn, Ty:$Rm)>;

// Replace max(abs(a), abs(b)) with famax(a, b)
def : Pat<(Ty (fmaximum (fabs Ty:$Rn), (fabs Ty:$Rm))),
(!cast<Instruction>("FAMAX"#Ty) Ty:$Rn, Ty:$Rm)>;
}
defm FAMAX : SIMDThreeSameVectorFP<0b0, 0b1, 0b011, "famax", AArch64famax>;
defm FAMIN : SIMDThreeSameVectorFP<0b1, 0b1, 0b011, "famin", AArch64famin>;
} // End let Predicates = [HasNEON, HasFAMINMAX]

let Uses = [FPMR, FPCR], Predicates = [HasFP8FMA] in {
Expand Down
Loading
Loading