[llvm] 8ab6677 - [RISCV] Add Zfh to typeIsScalarFPArith and simplify code. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 10:47:26 PDT 2024
Author: Craig Topper
Date: 2024-06-26T10:47:17-07:00
New Revision: 8ab66775dc885f7a99ee5f53771ce555e42085f9
URL: https://github.com/llvm/llvm-project/commit/8ab66775dc885f7a99ee5f53771ce555e42085f9
DIFF: https://github.com/llvm/llvm-project/commit/8ab66775dc885f7a99ee5f53771ce555e42085f9.diff
LOG: [RISCV] Add Zfh to typeIsScalarFPArith and simplify code. NFC
Now that we have Zfh supported and tested for every opcode that uses
typeIsScalarFPArith, we can fold Zfh into it.
Added:
Modified:
llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 4ce182809db13..fc616d0b4a80f 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -35,7 +35,8 @@ static LegalityPredicate typeIsScalarFPArith(unsigned TypeIdx,
const RISCVSubtarget &ST) {
return [=, &ST](const LegalityQuery &Query) {
return Query.Types[TypeIdx].isScalar() &&
- ((ST.hasStdExtF() && Query.Types[TypeIdx].getSizeInBits() == 32) ||
+ ((ST.hasStdExtZfh() && Query.Types[TypeIdx].getSizeInBits() == 16) ||
+ (ST.hasStdExtF() && Query.Types[TypeIdx].getSizeInBits() == 32) ||
(ST.hasStdExtD() && Query.Types[TypeIdx].getSizeInBits() == 64));
};
}
@@ -371,25 +372,17 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
// FP Operations
- auto &FPArithActions = getActionDefinitionsBuilder(
- {G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FMA, G_FNEG,
- G_FABS, G_FSQRT, G_FMAXNUM, G_FMINNUM})
- .legalIf(typeIsScalarFPArith(0, ST));
- // TODO: Fold this into typeIsScalarFPArith.
- if (ST.hasStdExtZfh())
- FPArithActions.legalFor({s16});
+ getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FMA, G_FNEG,
+ G_FABS, G_FSQRT, G_FMAXNUM, G_FMINNUM})
+ .legalIf(typeIsScalarFPArith(0, ST));
getActionDefinitionsBuilder(G_FREM)
.libcallFor({s32, s64})
.minScalar(0, s32)
.scalarize(0);
- auto &CopySignActions =
- getActionDefinitionsBuilder(G_FCOPYSIGN)
- .legalIf(all(typeIsScalarFPArith(0, ST), typeIsScalarFPArith(1, ST)));
- // TODO: Fold this into typeIsScalarFPArith.
- if (ST.hasStdExtZfh())
- CopySignActions.legalFor({s16, s16});
+ getActionDefinitionsBuilder(G_FCOPYSIGN)
+ .legalIf(all(typeIsScalarFPArith(0, ST), typeIsScalarFPArith(1, ST)));
getActionDefinitionsBuilder(G_FPTRUNC).legalIf(
[=, &ST](const LegalityQuery &Query) -> bool {
@@ -402,40 +395,28 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
typeIs(1, s32)(Query));
});
- auto &FCmpActions = getActionDefinitionsBuilder(G_FCMP).legalIf(
- all(typeIs(0, sXLen), typeIsScalarFPArith(1, ST)));
- // TODO: Fold this into typeIsScalarFPArith.
- if (ST.hasStdExtZfh())
- FCmpActions.legalFor({sXLen, s16});
- FCmpActions.clampScalar(0, sXLen, sXLen);
+ getActionDefinitionsBuilder(G_FCMP)
+ .legalIf(all(typeIs(0, sXLen), typeIsScalarFPArith(1, ST)))
+ .clampScalar(0, sXLen, sXLen);
// TODO: Support vector version of G_IS_FPCLASS.
- auto &FClassActions =
- getActionDefinitionsBuilder(G_IS_FPCLASS)
- .customIf(all(typeIs(0, s1), typeIsScalarFPArith(1, ST)));
- // TODO: Fold this into typeIsScalarFPArith.
- if (ST.hasStdExtZfh())
- FClassActions.customFor({s1, s16});
-
- auto &FConstantActions = getActionDefinitionsBuilder(G_FCONSTANT)
- .legalIf(typeIsScalarFPArith(0, ST));
- if (ST.hasStdExtZfh())
- FConstantActions.legalFor({s16});
- FConstantActions.lowerFor({s32, s64});
-
- auto &FPToIActions =
- getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
- .legalIf(all(typeInSet(0, {s32, sXLen}), typeIsScalarFPArith(1, ST)));
- if (ST.hasStdExtZfh())
- FPToIActions.legalFor({{s32, s16}, {sXLen, s16}});
- FPToIActions.widenScalarToNextPow2(0).clampScalar(0, s32, sXLen).libcall();
-
- auto &IToFPActions =
- getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
- .legalIf(all(typeIsScalarFPArith(0, ST), typeInSet(1, {s32, sXLen})));
- if (ST.hasStdExtZfh())
- IToFPActions.legalFor({{s16, s32}, {s16, sXLen}});
- IToFPActions.widenScalarToNextPow2(1).clampScalar(1, s32, sXLen);
+ getActionDefinitionsBuilder(G_IS_FPCLASS)
+ .customIf(all(typeIs(0, s1), typeIsScalarFPArith(1, ST)));
+
+ getActionDefinitionsBuilder(G_FCONSTANT)
+ .legalIf(typeIsScalarFPArith(0, ST))
+ .lowerFor({s32, s64});
+
+ getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
+ .legalIf(all(typeInSet(0, {s32, sXLen}), typeIsScalarFPArith(1, ST)))
+ .widenScalarToNextPow2(0)
+ .clampScalar(0, s32, sXLen)
+ .libcall();
+
+ getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
+ .legalIf(all(typeIsScalarFPArith(0, ST), typeInSet(1, {s32, sXLen})))
+ .widenScalarToNextPow2(1)
+ .clampScalar(1, s32, sXLen);
// FIXME: We can do custom inline expansion like SelectionDAG.
// FIXME: Legal with Zfa.
More information about the llvm-commits
mailing list