[llvm] [WebAssembly][GlobalISel] Add legalization & selection of most integer ops (PR #190234)
Demetrius Kanios via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 9 12:16:04 PDT 2026
================
@@ -25,18 +28,72 @@ WebAssemblyLegalizerInfo::WebAssemblyLegalizerInfo(
const LLT s32 = LLT::scalar(32);
const LLT s64 = LLT::scalar(64);
- getActionDefinitionsBuilder({G_CONSTANT, G_ADD, G_AND})
+ getActionDefinitionsBuilder({G_CONSTANT, G_IMPLICIT_DEF, G_ADD, G_SUB, G_MUL,
+ G_UDIV, G_SDIV, G_UREM, G_SREM, G_AND, G_OR,
+ G_XOR})
.legalFor({s32, s64})
.widenScalarToNextPow2(0)
.clampScalar(0, s32, s64);
- getActionDefinitionsBuilder({G_ASHR, G_SHL})
+ getActionDefinitionsBuilder({G_ASHR, G_LSHR, G_SHL})
.legalFor({{s32, s32}, {s64, s64}})
.widenScalarToNextPow2(0)
.clampScalar(0, s32, s64)
.scalarSameSizeAs(1, 0);
- getActionDefinitionsBuilder(G_SEXT_INREG).lower();
+ getActionDefinitionsBuilder({G_CTLZ, G_CTTZ, G_CTPOP})
+ .legalFor({{s32, s32}, {s64, s64}})
+ .widenScalarToNextPow2(1)
+ .clampScalar(1, s32, s64)
+ .scalarSameSizeAs(0, 1);
+
+ getActionDefinitionsBuilder({G_CTLZ_ZERO_UNDEF, G_CTTZ_ZERO_UNDEF}).lower();
+
+ getActionDefinitionsBuilder({G_ROTL, G_ROTR})
+ .legalFor({{s32, s32}, {s64, s64}})
+ .scalarSameSizeAs(1, 0)
+ .lower();
+
+ getActionDefinitionsBuilder({G_FSHL, G_FSHR}).lower();
+
+ getActionDefinitionsBuilder({G_ANYEXT, G_SEXT, G_ZEXT})
+ .legalFor({{s64, s32}})
+ .clampScalar(0, s64, s64)
+ .clampScalar(1, s32, s32);
+
+ getActionDefinitionsBuilder(G_TRUNC)
+ .legalFor({{s32, s64}})
+ .clampScalar(0, s32, s32)
+ .clampScalar(1, s64, s64);
+
+ getActionDefinitionsBuilder(G_SEXT_INREG)
+ .customFor(ST.hasSignExt(), {s32, s64})
+ .clampScalar(0, s32, s64)
+ .lower();
getLegacyLegalizerInfo().computeTables();
}
+
+bool WebAssemblyLegalizerInfo::legalizeCustom(
+ LegalizerHelper &Helper, MachineInstr &MI,
+ LostDebugLocObserver &LocObserver) const {
+ switch (MI.getOpcode()) {
+ case TargetOpcode::G_SEXT_INREG: {
+ assert(MI.getOperand(2).isImm() && "Expected immediate");
+
+ // Mark only 8/16/32-bit SEXT_INREG as legal
----------------
QuantumSegfault wrote:
Considering `LegalityQuery` only has Opcode, Types, and MMODescrs, I don't think it's possible to legalize based on immediates.
I'm not sure how common it is to do so, so it probably wasn't a high priority.
https://github.com/llvm/llvm-project/pull/190234
More information about the llvm-commits
mailing list