aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-06-26 10:44:10 -0700
committerCraig Topper <craig.topper@sifive.com>2024-06-26 10:47:17 -0700
commit8ab66775dc885f7a99ee5f53771ce555e42085f9 (patch)
tree254cce882f086270c6cfbe130635b275711a831a /llvm/lib
parent378630b4d023e3de76a82ceb3b713f90cf308a7f (diff)
downloadllvm-8ab66775dc885f7a99ee5f53771ce555e42085f9.zip
llvm-8ab66775dc885f7a99ee5f53771ce555e42085f9.tar.gz
llvm-8ab66775dc885f7a99ee5f53771ce555e42085f9.tar.bz2
[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.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp73
1 files changed, 27 insertions, 46 deletions
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 4ce1828..fc616d0 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.