[llvm] [RISCV][GISel] Use boolean predicated legalization action methods to simplify code. NFC (PR #115063)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 12:42:11 PST 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/115063
These allow us to pass a subtarget feature to conditionally enable the legalization action.
These were added by a3010c77910c706be4c51ce4a95d51211e335a1f and are used by AArch64.
>From 080412549cc80313429a6fb9f00dd2defe3fd2d2 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 5 Nov 2024 12:37:53 -0800
Subject: [PATCH] [RISCV][GISel] Use boolean predicated legalization action
methods to simplify code. NFC
These allow us to pass a subtarget feature to conditionally enable
the legalization action.
These were added by a3010c77910c706be4c51ce4a95d51211e335a1f and
are used by AArch64.
---
.../Target/RISCV/GISel/RISCVLegalizerInfo.cpp | 53 +++++++++----------
1 file changed, 25 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 50d95d7695e0ff..f2a51a7ea0d426 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -157,8 +157,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
getActionDefinitionsBuilder({G_UADDSAT, G_SADDSAT, G_USUBSAT, G_SSUBSAT})
.lower();
- auto &ShiftActions = getActionDefinitionsBuilder({G_ASHR, G_LSHR, G_SHL});
- ShiftActions.legalFor({{s32, s32}, {sXLen, sXLen}})
+ getActionDefinitionsBuilder({G_ASHR, G_LSHR, G_SHL})
+ .legalFor({{s32, s32}, {sXLen, sXLen}})
.widenScalarToNextPow2(0)
.clampScalar(1, s32, sXLen)
.clampScalar(0, s32, sXLen)
@@ -201,10 +201,10 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
getActionDefinitionsBuilder({G_FSHL, G_FSHR}).lower();
- auto &RotateActions = getActionDefinitionsBuilder({G_ROTL, G_ROTR});
- if (ST.hasStdExtZbb() || ST.hasStdExtZbkb())
- RotateActions.legalFor({{s32, s32}, {sXLen, sXLen}});
- RotateActions.lower();
+ getActionDefinitionsBuilder({G_ROTL, G_ROTR})
+ .legalFor(ST.hasStdExtZbb() || ST.hasStdExtZbkb(),
+ {{s32, s32}, {sXLen, sXLen}})
+ .lower();
getActionDefinitionsBuilder(G_BITREVERSE).maxScalar(0, sXLen).lower();
@@ -244,11 +244,11 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
CTPOPActions.maxScalar(0, sXLen).scalarSameSizeAs(1, 0).lower();
}
- auto &ConstantActions = getActionDefinitionsBuilder(G_CONSTANT);
- ConstantActions.legalFor({s32, p0});
- if (ST.is64Bit())
- ConstantActions.customFor({s64});
- ConstantActions.widenScalarToNextPow2(0).clampScalar(0, s32, sXLen);
+ getActionDefinitionsBuilder(G_CONSTANT)
+ .legalFor({s32, p0})
+ .customFor(ST.is64Bit(), {s64})
+ .widenScalarToNextPow2(0)
+ .clampScalar(0, s32, sXLen);
// TODO: transform illegal vector types into legal vector type
getActionDefinitionsBuilder(
@@ -267,14 +267,12 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
.clampScalar(1, sXLen, sXLen)
.clampScalar(0, sXLen, sXLen);
- auto &SelectActions =
- getActionDefinitionsBuilder(G_SELECT)
- .legalFor({{s32, sXLen}, {p0, sXLen}})
- .legalIf(all(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
- typeIsLegalBoolVec(1, BoolVecTys, ST)));
- if (XLen == 64 || ST.hasStdExtD())
- SelectActions.legalFor({{s64, sXLen}});
- SelectActions.widenScalarToNextPow2(0)
+ getActionDefinitionsBuilder(G_SELECT)
+ .legalFor({{s32, sXLen}, {p0, sXLen}})
+ .legalIf(all(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST),
+ typeIsLegalBoolVec(1, BoolVecTys, ST)))
+ .legalFor(XLen == 64 || ST.hasStdExtD(), {{s64, sXLen}})
+ .widenScalarToNextPow2(0)
.clampScalar(0, s32, (XLen == 64 || ST.hasStdExtD()) ? s64 : s32)
.clampScalar(1, sXLen, sXLen);
@@ -471,16 +469,15 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
// TODO: Use libcall for sDoubleXLen.
getActionDefinitionsBuilder({G_UDIVREM, G_SDIVREM}).lower();
- auto &AbsActions = getActionDefinitionsBuilder(G_ABS);
- if (ST.hasStdExtZbb())
- AbsActions.customFor({sXLen}).minScalar(0, sXLen);
- AbsActions.lower();
+ getActionDefinitionsBuilder(G_ABS)
+ .customFor(ST.hasStdExtZbb(), {sXLen})
+ .minScalar(ST.hasStdExtZbb(), 0, sXLen)
+ .lower();
- auto &MinMaxActions =
- getActionDefinitionsBuilder({G_UMAX, G_UMIN, G_SMAX, G_SMIN});
- if (ST.hasStdExtZbb())
- MinMaxActions.legalFor({sXLen}).minScalar(0, sXLen);
- MinMaxActions.lower();
+ getActionDefinitionsBuilder({G_UMAX, G_UMIN, G_SMAX, G_SMIN})
+ .legalFor(ST.hasStdExtZbb(), {sXLen})
+ .minScalar(ST.hasStdExtZbb(), 0, sXLen)
+ .lower();
getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({p0});
More information about the llvm-commits
mailing list