[llvm] [GlobalISel] Remove LegacyLegalizerInfo (PR #197308)

David Green via llvm-commits llvm-commits at lists.llvm.org
Tue May 12 14:47:55 PDT 2026


https://github.com/davemgreen created https://github.com/llvm/llvm-project/pull/197308

None

>From a82ac9a32a4f39e716ed6110855e93f69a1554c3 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 17:58:11 +0100
Subject: [PATCH 1/9] [AArch64][GlobalISel] Add always legal action builders.

This defined some always legal actions, removing our dependency on the Legacy
ruleset in aarch64.
---
 .../AArch64/GISel/AArch64LegalizerInfo.cpp      |  5 +++++
 .../GlobalISel/legalizer-info-validation.mir    | 17 +++++++++--------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index 4c7abbfb871af..0db0c937e7c8a 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -1509,6 +1509,11 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
 
   getActionDefinitionsBuilder({G_SCMP, G_UCMP}).lower();
 
+  getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS})
+      .alwaysLegal();
+  getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
+  getActionDefinitionsBuilder(G_INVOKE_REGION_START).alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
index 70dbeb7d49f65..bd7681542a0fc 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
@@ -319,8 +319,8 @@
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: G_FENCE (opcode {{[0-9]+}}): 0 type indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_PREFETCH (opcode {{[0-9]+}}): 1 type index, 0 imm indices
 # DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
@@ -331,14 +331,15 @@
 # DEBUG-NEXT: .. the first uncovered type index: 1, OK
 # DEBUG-NEXT: .. the first uncovered imm index: 0, OK
 # DEBUG-NEXT: G_INVOKE_REGION_START (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT:  .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT:  .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_INTRINSIC (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_INTRINSIC_W_SIDE_EFFECTS (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_INTRINSIC_CONVERGENT (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined

>From a1e78f016d6f7f3ea76878f376b6c04504522f50 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 17:27:04 +0100
Subject: [PATCH 2/9] [ARM][GlobalISel] Remove dependency on legal ruleset.

This might make some differences but it looks like i64 zext / sext are not well
supported at the moment
---
 llvm/lib/Target/ARM/ARMLegalizerInfo.cpp      |  4 +++
 .../ARM/GlobalISel/arm-regbankselect.mir      | 25 ---------------
 .../test/CodeGen/ARM/GlobalISel/select-fp.mir | 32 -------------------
 3 files changed, 4 insertions(+), 57 deletions(-)

diff --git a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
index 8b334fe84be45..ae1f8572a0ef7 100644
--- a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
@@ -51,6 +51,9 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(ST) {
   getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT})
       .legalForCartesianProduct({s8, s16, s32}, {s1, s8, s16});
 
+  getActionDefinitionsBuilder(G_TRUNC)
+      .legalForCartesianProduct({s1, s8, s16}, {s8, s16, s32});
+
   getActionDefinitionsBuilder(G_SEXT_INREG).lower();
 
   getActionDefinitionsBuilder({G_MUL, G_AND, G_OR, G_XOR})
@@ -133,6 +136,7 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(ST) {
       .legalFor({{p0, s32}})
       .minScalar(1, s32);
 
+  getActionDefinitionsBuilder(G_BR).alwaysLegal();
   getActionDefinitionsBuilder(G_BRCOND).legalFor({s1});
 
   if (!ST.useSoftFloat() && ST.hasVFP2Base()) {
diff --git a/llvm/test/CodeGen/ARM/GlobalISel/arm-regbankselect.mir b/llvm/test/CodeGen/ARM/GlobalISel/arm-regbankselect.mir
index 87d1785809b90..7b530cef67ebc 100644
--- a/llvm/test/CodeGen/ARM/GlobalISel/arm-regbankselect.mir
+++ b/llvm/test/CodeGen/ARM/GlobalISel/arm-regbankselect.mir
@@ -37,7 +37,6 @@
   define void @test_anyext_s16_32() { ret void }
 
   define void @test_trunc_s32_16() { ret void }
-  define void @test_trunc_s64_32() #0 { ret void }
 
   define void @test_icmp_eq_s32() { ret void }
   define void @test_fcmp_one_s32() #0 { ret void }
@@ -677,30 +676,6 @@ body:             |
     BX_RET 14, $noreg
 ...
 ---
-name:            test_trunc_s64_32
-# CHECK-LABEL: name: test_trunc_s64_32
-legalized:       true
-regBankSelected: false
-selected:        false
-# CHECK: registers:
-# CHECK: - { id: 0, class: fprb, preferred-register: '', flags: [  ] }
-# CHECK: - { id: 1, class: gprb, preferred-register: '', flags: [  ] }
-# CHECK: - { id: 2, class: gprb, preferred-register: '', flags: [  ] }
-registers:
-  - { id: 0, class: _ }
-  - { id: 1, class: _ }
-  - { id: 2, class: _ }
-body:             |
-  bb.0:
-    liveins: $r0, $d0
-
-    %0(s64) = COPY $d0
-    %2(p0) = COPY $r0
-    %1(s32) = G_TRUNC %0(s64)
-    G_STORE %1(s32), %2 :: (store (s32))
-    BX_RET 14, $noreg
-...
----
 name:            test_icmp_eq_s32
 # CHECK-LABEL: name: test_icmp_eq_s32
 legalized:       true
diff --git a/llvm/test/CodeGen/ARM/GlobalISel/select-fp.mir b/llvm/test/CodeGen/ARM/GlobalISel/select-fp.mir
index 4517fe6dd4f13..cc49e2c57f7f1 100644
--- a/llvm/test/CodeGen/ARM/GlobalISel/select-fp.mir
+++ b/llvm/test/CodeGen/ARM/GlobalISel/select-fp.mir
@@ -2,8 +2,6 @@
 # RUN: llc -O0 -mtriple arm-- -mattr=+vfp4,-neonfp -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
 # RUN: llc -O0 -mtriple thumb-- -mattr=+v6t2,+vfp4,-neonfp -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
 --- |
-  define void @test_trunc_s64() { ret void }
-
   define void @test_fadd_s32() { ret void }
   define void @test_fadd_s64() { ret void }
 
@@ -46,36 +44,6 @@
 
 ...
 ---
-name:            test_trunc_s64
-# CHECK-LABEL: name: test_trunc_s64
-legalized:       true
-regBankSelected: true
-selected:        false
-# CHECK: selected: true
-registers:
-  - { id: 0, class: fprb }
-  - { id: 1, class: gprb }
-  - { id: 2, class: gprb }
-body:             |
-  bb.0:
-    liveins: $r0, $d0
-
-    %0(s64) = COPY $d0
-    ; CHECK: [[VREG:%[0-9]+]]:dpr = COPY $d0
-
-    %2(p0) = COPY $r0
-    ; CHECK: [[PTR:%[0-9]+]]:gpr = COPY $r0
-
-    %1(s32) = G_TRUNC %0(s64)
-    ; CHECK: [[VREGTRUNC:%[0-9]+]]:gpr, [[UNINTERESTING:%[0-9]+]]:gpr = VMOVRRD [[VREG]]
-
-    G_STORE %1(s32), %2 :: (store (s32))
-    ; CHECK: STRi12 [[VREGTRUNC]], [[PTR]], 0, 14 /* CC::al */, $noreg
-
-    BX_RET 14, $noreg
-    ; CHECK: BX_RET 14 /* CC::al */, $noreg
-...
----
 name:            test_fadd_s32
 legalized:       true
 regBankSelected: true

>From c625e0120f13eb55f16dda3f4ebaf5dda6aae4ff Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 17:41:25 +0100
Subject: [PATCH 3/9] [AMDGPU][GlobalISel] Remove dependency on legal ruleset

This fills in always legal rules, to remove the dependency on the legacy ruleset.
---
 llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
index 43db1ead84c80..b543cc90b9f11 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
@@ -2229,6 +2229,12 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
       .scalarize(1)
       .lower();
 
+  getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS,
+                               G_INTRINSIC_CONVERGENT,
+                               G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS})
+      .alwaysLegal();
+  getActionDefinitionsBuilder(G_BR).alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }

>From dabacd5d7f730578815100c1381858a25d148074 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 17:49:16 +0100
Subject: [PATCH 4/9] [X86][GlobalISel] Remove dependency on legal ruleset

This fills in always legal rules, to remove the dependency on the legacy
ruleset. I'm not sure about the truncate rule but all tests pass.
---
 llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index ce922538cfdc9..6e0605c089b74 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -314,6 +314,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
       .clampScalar(1, s16, sMaxScalar)
       .scalarSameSizeAs(0, 1);
 
+  getActionDefinitionsBuilder(G_BR).alwaysLegal();
   getActionDefinitionsBuilder(G_BRCOND).legalFor({s1});
 
   // pointer handling
@@ -425,6 +426,9 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
       .clampScalar(1, s8, sMaxScalar)
       .scalarize(0);
 
+  getActionDefinitionsBuilder(G_TRUNC)
+      .alwaysLegal();
+
   getActionDefinitionsBuilder(G_SEXT_INREG).lower();
 
   // fp constants
@@ -615,6 +619,10 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
       .minScalar(0, LLT::scalar(32))
       .libcall();
 
+  getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS})
+      .alwaysLegal();
+  getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
   verify(*STI.getInstrInfo());
 }

>From e5f81607b89a2ab8de7256e962302400043b2d84 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 18:01:46 +0100
Subject: [PATCH 5/9] [RISCV][GlobalISel] Remove dependency on legal ruleset

This fills in always legal rules, to remove the dependency on the legacy
ruleset. I'm really not sure about the truncate rule but all tests pass.
---
 .../Target/RISCV/GISel/RISCVLegalizerInfo.cpp | 11 ++++++
 .../GlobalISel/legalizer-info-validation.mir  | 35 ++++++++++---------
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 6a690402696e6..0a08db88699b8 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -176,6 +176,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
       .customIf(typeIsLegalBoolVec(1, BoolVecTys, ST))
       .maxScalar(0, sXLen);
 
+  getActionDefinitionsBuilder(G_TRUNC).alwaysLegal();
+
   getActionDefinitionsBuilder(G_SEXT_INREG)
       .customFor({sXLen})
       .clampScalar(0, sXLen, sXLen)
@@ -433,6 +435,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
       .legalFor({{p0, sXLen}})
       .clampScalar(1, sXLen, sXLen);
 
+  getActionDefinitionsBuilder(G_BR).alwaysLegal();
+
   getActionDefinitionsBuilder(G_BRCOND).legalFor({sXLen}).minScalar(0, sXLen);
 
   getActionDefinitionsBuilder(G_BRJT).customFor({{p0, sXLen}});
@@ -751,6 +755,13 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
       .legalIf(all(typeIsLegalBoolVec(0, BoolVecTys, ST), InsertVectorEltPred,
                    typeIs(2, sXLen)));
 
+  getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS})
+      .alwaysLegal();
+
+  getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
+
+  getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer-info-validation.mir b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer-info-validation.mir
index edc8bb70ef21e..ff60bcd0f2c58 100644
--- a/llvm/test/CodeGen/RISCV/GlobalISel/legalizer-info-validation.mir
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/legalizer-info-validation.mir
@@ -311,8 +311,8 @@
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: G_FENCE (opcode {{[0-9]+}}): 0 type indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_PREFETCH (opcode {{[0-9]+}}): 1 type index, 0 imm indices
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
@@ -326,11 +326,12 @@
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT:  .. imm index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: G_INTRINSIC (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_INTRINSIC_W_SIDE_EFFECTS (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_INTRINSIC_CONVERGENT (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
@@ -342,8 +343,8 @@
 # DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_TRUNC (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_TRUNC_SSAT_S (opcode {{[0-9]+}}): 2 type indices, 0 imm indices
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
@@ -701,8 +702,8 @@
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: G_BR (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_BRJT (opcode {{[0-9]+}}): 2 type indices
 # DEBUG-NEXT: .. the first uncovered type index: 2, OK
 # DEBUG-NEXT: .. the first uncovered imm index: 0, OK
@@ -897,14 +898,16 @@
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: G_TRAP (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_DEBUGTRAP (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_UBSANTRAP (opcode {{[0-9]+}}): 0 type indices, 0 imm indices
-# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
-# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
+# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
+# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected
+# DEBUG-NEXT: .. imm index coverage check SKIPPED: user-defined predicate detected
 # DEBUG-NEXT: G_VECREDUCE_SEQ_FADD (opcode {{[0-9]+}}): 3 type indices, 0 imm indices
 # DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
 # DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined

>From 95e85ad34d6d6d133fcc5a7fb2033bd47ddaa76b Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 21:39:21 +0100
Subject: [PATCH 6/9] [PowerPC][GlobalISel] Remove dependency on legal ruleset

This fills in always legal rules, to remove the dependency on the legacy ruleset.
---
 llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp b/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
index afc8f6bbde1b7..68061818a46bf 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
+++ b/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
@@ -84,5 +84,8 @@ PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) {
   getActionDefinitionsBuilder(G_FCONSTANT).lowerFor({S32, S64});
   getActionDefinitionsBuilder(G_CONSTANT_POOL).legalFor({P0});
 
+  getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS})
+      .alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
 }

>From 0b7dc54b004f4885e7282ac5a36f57b4635f5164 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 21:41:41 +0100
Subject: [PATCH 7/9] [SPIRV][GlobalISel] Remove dependency on legal ruleset

This fills in always legal rules, to remove the dependency on the legacy
ruleset.
---
 llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index 378b0846fb106..70490823d945d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -447,6 +447,7 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
   getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor(allPtrs);
 
   // Control-flow. In some cases (e.g. constants) s1 may be promoted to s32.
+  getActionDefinitionsBuilder(G_BR).alwaysLegal();
   getActionDefinitionsBuilder(G_BRCOND).legalFor({s1, s32});
 
   getActionDefinitionsBuilder(G_FFREXP).legalForCartesianProduct(
@@ -512,6 +513,12 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
 
   getActionDefinitionsBuilder(G_IS_FPCLASS).custom();
 
+  getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_CONVERGENT,
+                               G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS})
+      .alwaysLegal();
+  getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
+  getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }

>From f7caf9630fcd4389d321f891b31bf2fc6a279e4c Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 21:47:18 +0100
Subject: [PATCH 8/9] [MIPS][GlobalISel] Remove dependency on legal ruleset

This fills in always legal rules, to remove the dependency on the legacy
ruleset.
---
 llvm/lib/Target/Mips/MipsLegalizerInfo.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
index 95074a1efc2ef..e1c77849bbb72 100644
--- a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
@@ -177,6 +177,8 @@ MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) {
       .minScalar(0, s32)
       .minScalar(1, s32);
 
+  getActionDefinitionsBuilder(G_BR).alwaysLegal();
+
   getActionDefinitionsBuilder(G_BRCOND)
       .legalFor({s32})
       .minScalar(0, s32);
@@ -326,6 +328,9 @@ MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) {
 
   getActionDefinitionsBuilder({G_MEMCPY, G_MEMMOVE, G_MEMSET}).libcall();
 
+  getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
+  getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
+
   getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }

>From d543cd8caa1ad0ae2bd814cf8c7beaa7c7582226 Mon Sep 17 00:00:00 2001
From: David Green <david.green at arm.com>
Date: Tue, 12 May 2026 22:43:20 +0100
Subject: [PATCH 9/9] Remove LegacyLegalizerInfo

---
 llvm/docs/GlobalISel/Legalizer.rst            |   3 -
 .../CodeGen/GlobalISel/LegacyLegalizerInfo.h  | 467 ------------------
 .../llvm/CodeGen/GlobalISel/LegalizerInfo.h   |  57 ---
 llvm/lib/CodeGen/GlobalISel/CMakeLists.txt    |   1 -
 .../GlobalISel/LegacyLegalizerInfo.cpp        | 385 ---------------
 llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp |  14 +-
 .../AArch64/GISel/AArch64LegalizerInfo.cpp    |   5 +-
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |   1 -
 llvm/lib/Target/ARM/ARMLegalizerInfo.cpp      |   3 -
 .../lib/Target/BPF/GISel/BPFLegalizerInfo.cpp |   1 -
 .../Target/M68k/GISel/M68kLegalizerInfo.cpp   |   2 -
 llvm/lib/Target/Mips/MipsLegalizerInfo.cpp    |   1 -
 .../Target/PowerPC/GISel/PPCLegalizerInfo.cpp |   2 -
 .../Target/RISCV/GISel/RISCVLegalizerInfo.cpp |   1 -
 llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp  |   1 -
 .../GISel/WebAssemblyLegalizerInfo.cpp        |   2 -
 .../lib/Target/X86/GISel/X86LegalizerInfo.cpp |   1 -
 .../CodeGen/GlobalISel/GISelMITest.h          |   1 -
 .../GlobalISel/LegalizerHelperTest.cpp        |   2 -
 .../CodeGen/GlobalISel/LegalizerInfoTest.cpp  | 198 --------
 .../llvm/lib/CodeGen/GlobalISel/BUILD.gn      |   1 -
 21 files changed, 2 insertions(+), 1147 deletions(-)
 delete mode 100644 llvm/include/llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h
 delete mode 100644 llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp

diff --git a/llvm/docs/GlobalISel/Legalizer.rst b/llvm/docs/GlobalISel/Legalizer.rst
index 74e83aef80ab2..0f35574b441ab 100644
--- a/llvm/docs/GlobalISel/Legalizer.rst
+++ b/llvm/docs/GlobalISel/Legalizer.rst
@@ -196,9 +196,6 @@ few actions in common:
   if the predicate is satisfied and indicates that there is no way to make it
   legal and the compiler should fail.
 
-* ``fallback()`` falls back on an older API and should only be used while porting
-  existing code from that API.
-
 Rule Predicates
 """""""""""""""
 
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h
deleted file mode 100644
index e6d593e4f6d49..0000000000000
--- a/llvm/include/llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h
+++ /dev/null
@@ -1,467 +0,0 @@
-//===- llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h ------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-/// \file
-/// Interface for Targets to specify which operations they can successfully
-/// select and how the others should be expanded most efficiently.
-/// This implementation has been deprecated for a long time but it still in use
-/// in a few places.
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CODEGEN_GLOBALISEL_LEGACYLEGALIZERINFO_H
-#define LLVM_CODEGEN_GLOBALISEL_LEGACYLEGALIZERINFO_H
-
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/CodeGen/TargetOpcodes.h"
-#include "llvm/CodeGenTypes/LowLevelType.h"
-#include "llvm/Support/Compiler.h"
-#include <unordered_map>
-#include <vector>
-
-namespace llvm {
-struct LegalityQuery;
-
-namespace LegacyLegalizeActions {
-enum LegacyLegalizeAction : std::uint8_t {
-  /// The operation is expected to be selectable directly by the target, and
-  /// no transformation is necessary.
-  Legal,
-
-  /// The operation should be synthesized from multiple instructions acting on
-  /// a narrower scalar base-type. For example a 64-bit add might be
-  /// implemented in terms of 32-bit add-with-carry.
-  NarrowScalar,
-
-  /// The operation should be implemented in terms of a wider scalar
-  /// base-type. For example a <2 x s8> add could be implemented as a <2
-  /// x s32> add (ignoring the high bits).
-  WidenScalar,
-
-  /// The (vector) operation should be implemented by splitting it into
-  /// sub-vectors where the operation is legal. For example a <8 x s64> add
-  /// might be implemented as 4 separate <2 x s64> adds.
-  FewerElements,
-
-  /// The (vector) operation should be implemented by widening the input
-  /// vector and ignoring the lanes added by doing so. For example <2 x i8> is
-  /// rarely legal, but you might perform an <8 x i8> and then only look at
-  /// the first two results.
-  MoreElements,
-
-  /// Perform the operation on a different, but equivalently sized type.
-  Bitcast,
-
-  /// The operation itself must be expressed in terms of simpler actions on
-  /// this target. E.g. a SREM replaced by an SDIV and subtraction.
-  Lower,
-
-  /// The operation should be implemented as a call to some kind of runtime
-  /// support library. For example this usually happens on machines that don't
-  /// support floating-point operations natively.
-  Libcall,
-
-  /// The target wants to do something special with this combination of
-  /// operand and type. A callback will be issued when it is needed.
-  Custom,
-
-  /// This operation is completely unsupported on the target. A programming
-  /// error has occurred.
-  Unsupported,
-
-  /// Sentinel value for when no action was found in the specified table.
-  NotFound,
-};
-} // end namespace LegacyLegalizeActions
-LLVM_ABI raw_ostream &
-operator<<(raw_ostream &OS, LegacyLegalizeActions::LegacyLegalizeAction Action);
-
-/// Legalization is decided based on an instruction's opcode, which type slot
-/// we're considering, and what the existing type is. These aspects are gathered
-/// together for convenience in the InstrAspect class.
-struct InstrAspect {
-  unsigned Opcode;
-  unsigned Idx = 0;
-  LLT Type;
-
-  InstrAspect(unsigned Opcode, LLT Type) : Opcode(Opcode), Type(Type) {}
-  InstrAspect(unsigned Opcode, unsigned Idx, LLT Type)
-      : Opcode(Opcode), Idx(Idx), Type(Type) {}
-
-  bool operator==(const InstrAspect &RHS) const {
-    return Opcode == RHS.Opcode && Idx == RHS.Idx && Type == RHS.Type;
-  }
-};
-
-/// The result of a query. It either indicates a final answer of Legal or
-/// Unsupported or describes an action that must be taken to make an operation
-/// more legal.
-struct LegacyLegalizeActionStep {
-  /// The action to take or the final answer.
-  LegacyLegalizeActions::LegacyLegalizeAction Action;
-  /// If describing an action, the type index to change. Otherwise zero.
-  unsigned TypeIdx;
-  /// If describing an action, the new type for TypeIdx. Otherwise LLT{}.
-  LLT NewType;
-
-  LegacyLegalizeActionStep(LegacyLegalizeActions::LegacyLegalizeAction Action,
-                           unsigned TypeIdx, const LLT NewType)
-      : Action(Action), TypeIdx(TypeIdx), NewType(NewType) {}
-
-  bool operator==(const LegacyLegalizeActionStep &RHS) const {
-    return std::tie(Action, TypeIdx, NewType) ==
-        std::tie(RHS.Action, RHS.TypeIdx, RHS.NewType);
-  }
-};
-
-
-class LegacyLegalizerInfo {
-public:
-  using SizeAndAction =
-      std::pair<uint16_t, LegacyLegalizeActions::LegacyLegalizeAction>;
-  using SizeAndActionsVec = std::vector<SizeAndAction>;
-  using SizeChangeStrategy =
-      std::function<SizeAndActionsVec(const SizeAndActionsVec &v)>;
-
-  LLVM_ABI LegacyLegalizerInfo();
-
-  static bool needsLegalizingToDifferentSize(
-      const LegacyLegalizeActions::LegacyLegalizeAction Action) {
-    using namespace LegacyLegalizeActions;
-    switch (Action) {
-    case NarrowScalar:
-    case WidenScalar:
-    case FewerElements:
-    case MoreElements:
-    case Unsupported:
-      return true;
-    default:
-      return false;
-    }
-  }
-
-  /// Compute any ancillary tables needed to quickly decide how an operation
-  /// should be handled. This must be called after all "set*Action"methods but
-  /// before any query is made or incorrect results may be returned.
-  LLVM_ABI void computeTables();
-
-  /// More friendly way to set an action for common types that have an LLT
-  /// representation.
-  /// The LegacyLegalizeAction must be one for which
-  /// NeedsLegalizingToDifferentSize returns false.
-  void setAction(const InstrAspect &Aspect,
-                 LegacyLegalizeActions::LegacyLegalizeAction Action) {
-    assert(!needsLegalizingToDifferentSize(Action));
-    TablesInitialized = false;
-    const unsigned OpcodeIdx = Aspect.Opcode - FirstOp;
-    if (SpecifiedActions[OpcodeIdx].size() <= Aspect.Idx)
-      SpecifiedActions[OpcodeIdx].resize(Aspect.Idx + 1);
-    SpecifiedActions[OpcodeIdx][Aspect.Idx][Aspect.Type] = Action;
-  }
-
-  /// The setAction calls record the non-size-changing legalization actions
-  /// to take on specificly-sized types. The SizeChangeStrategy defines what
-  /// to do when the size of the type needs to be changed to reach a legally
-  /// sized type (i.e., one that was defined through a setAction call).
-  /// e.g.
-  /// setAction ({G_ADD, 0, LLT::scalar(32)}, Legal);
-  /// setLegalizeScalarToDifferentSizeStrategy(
-  ///   G_ADD, 0, widenToLargerTypesAndNarrowToLargest);
-  /// will end up defining getAction({G_ADD, 0, T}) to return the following
-  /// actions for different scalar types T:
-  ///  LLT::scalar(1)..LLT::scalar(31): {WidenScalar, 0, LLT::scalar(32)}
-  ///  LLT::scalar(32):                 {Legal, 0, LLT::scalar(32)}
-  ///  LLT::scalar(33)..:               {NarrowScalar, 0, LLT::scalar(32)}
-  ///
-  /// If no SizeChangeAction gets defined, through this function,
-  /// the default is unsupportedForDifferentSizes.
-  void setLegalizeScalarToDifferentSizeStrategy(const unsigned Opcode,
-                                                const unsigned TypeIdx,
-                                                SizeChangeStrategy S) {
-    const unsigned OpcodeIdx = Opcode - FirstOp;
-    if (ScalarSizeChangeStrategies[OpcodeIdx].size() <= TypeIdx)
-      ScalarSizeChangeStrategies[OpcodeIdx].resize(TypeIdx + 1);
-    ScalarSizeChangeStrategies[OpcodeIdx][TypeIdx] = S;
-  }
-
-  /// See also setLegalizeScalarToDifferentSizeStrategy.
-  /// This function allows to set the SizeChangeStrategy for vector elements.
-  void setLegalizeVectorElementToDifferentSizeStrategy(const unsigned Opcode,
-                                                       const unsigned TypeIdx,
-                                                       SizeChangeStrategy S) {
-    const unsigned OpcodeIdx = Opcode - FirstOp;
-    if (VectorElementSizeChangeStrategies[OpcodeIdx].size() <= TypeIdx)
-      VectorElementSizeChangeStrategies[OpcodeIdx].resize(TypeIdx + 1);
-    VectorElementSizeChangeStrategies[OpcodeIdx][TypeIdx] = S;
-  }
-
-  /// A SizeChangeStrategy for the common case where legalization for a
-  /// particular operation consists of only supporting a specific set of type
-  /// sizes. E.g.
-  ///   setAction ({G_DIV, 0, LLT::scalar(32)}, Legal);
-  ///   setAction ({G_DIV, 0, LLT::scalar(64)}, Legal);
-  ///   setLegalizeScalarToDifferentSizeStrategy(
-  ///     G_DIV, 0, unsupportedForDifferentSizes);
-  /// will result in getAction({G_DIV, 0, T}) to return Legal for s32 and s64,
-  /// and Unsupported for all other scalar types T.
-  static SizeAndActionsVec
-  unsupportedForDifferentSizes(const SizeAndActionsVec &v) {
-    using namespace LegacyLegalizeActions;
-    return increaseToLargerTypesAndDecreaseToLargest(v, Unsupported,
-                                                     Unsupported);
-  }
-
-  /// A SizeChangeStrategy for the common case where legalization for a
-  /// particular operation consists of widening the type to a large legal type,
-  /// unless there is no such type and then instead it should be narrowed to the
-  /// largest legal type.
-  static SizeAndActionsVec
-  widenToLargerTypesAndNarrowToLargest(const SizeAndActionsVec &v) {
-    using namespace LegacyLegalizeActions;
-    assert(v.size() > 0 &&
-           "At least one size that can be legalized towards is needed"
-           " for this SizeChangeStrategy");
-    return increaseToLargerTypesAndDecreaseToLargest(v, WidenScalar,
-                                                     NarrowScalar);
-  }
-
-  static SizeAndActionsVec
-  widenToLargerTypesUnsupportedOtherwise(const SizeAndActionsVec &v) {
-    using namespace LegacyLegalizeActions;
-    return increaseToLargerTypesAndDecreaseToLargest(v, WidenScalar,
-                                                     Unsupported);
-  }
-
-  static SizeAndActionsVec
-  narrowToSmallerAndUnsupportedIfTooSmall(const SizeAndActionsVec &v) {
-    using namespace LegacyLegalizeActions;
-    return decreaseToSmallerTypesAndIncreaseToSmallest(v, NarrowScalar,
-                                                       Unsupported);
-  }
-
-  /// A SizeChangeStrategy for the common case where legalization for a
-  /// particular vector operation consists of having more elements in the
-  /// vector, to a type that is legal. Unless there is no such type and then
-  /// instead it should be legalized towards the widest vector that's still
-  /// legal. E.g.
-  ///   setAction({G_ADD, LLT::vector(8, 8)}, Legal);
-  ///   setAction({G_ADD, LLT::vector(16, 8)}, Legal);
-  ///   setAction({G_ADD, LLT::vector(2, 32)}, Legal);
-  ///   setAction({G_ADD, LLT::vector(4, 32)}, Legal);
-  ///   setLegalizeVectorElementToDifferentSizeStrategy(
-  ///     G_ADD, 0, moreToWiderTypesAndLessToWidest);
-  /// will result in the following getAction results:
-  ///   * getAction({G_ADD, LLT::vector(8,8)}) returns
-  ///       (Legal, vector(8,8)).
-  ///   * getAction({G_ADD, LLT::vector(9,8)}) returns
-  ///       (MoreElements, vector(16,8)).
-  ///   * getAction({G_ADD, LLT::vector(8,32)}) returns
-  ///       (FewerElements, vector(4,32)).
-  static SizeAndActionsVec
-  moreToWiderTypesAndLessToWidest(const SizeAndActionsVec &v) {
-    using namespace LegacyLegalizeActions;
-    return increaseToLargerTypesAndDecreaseToLargest(v, MoreElements,
-                                                     FewerElements);
-  }
-
-  /// Helper function to implement many typical SizeChangeStrategy functions.
-  LLVM_ABI static SizeAndActionsVec increaseToLargerTypesAndDecreaseToLargest(
-      const SizeAndActionsVec &v,
-      LegacyLegalizeActions::LegacyLegalizeAction IncreaseAction,
-      LegacyLegalizeActions::LegacyLegalizeAction DecreaseAction);
-  /// Helper function to implement many typical SizeChangeStrategy functions.
-  LLVM_ABI static SizeAndActionsVec decreaseToSmallerTypesAndIncreaseToSmallest(
-      const SizeAndActionsVec &v,
-      LegacyLegalizeActions::LegacyLegalizeAction DecreaseAction,
-      LegacyLegalizeActions::LegacyLegalizeAction IncreaseAction);
-
-  LLVM_ABI LegacyLegalizeActionStep getAction(const LegalityQuery &Query) const;
-
-  LLVM_ABI unsigned getOpcodeIdxForOpcode(unsigned Opcode) const;
-
-private:
-  /// Determine what action should be taken to legalize the given generic
-  /// instruction opcode, type-index and type. Requires computeTables to have
-  /// been called.
-  ///
-  /// \returns a pair consisting of the kind of legalization that should be
-  /// performed and the destination type.
-  std::pair<LegacyLegalizeActions::LegacyLegalizeAction, LLT>
-  getAspectAction(const InstrAspect &Aspect) const;
-
-  /// The SizeAndActionsVec is a representation mapping between all natural
-  /// numbers and an Action. The natural number represents the bit size of
-  /// the InstrAspect. For example, for a target with native support for 32-bit
-  /// and 64-bit additions, you'd express that as:
-  /// setScalarAction(G_ADD, 0,
-  ///           {{1, WidenScalar},  // bit sizes [ 1, 31[
-  ///            {32, Legal},       // bit sizes [32, 33[
-  ///            {33, WidenScalar}, // bit sizes [33, 64[
-  ///            {64, Legal},       // bit sizes [64, 65[
-  ///            {65, NarrowScalar} // bit sizes [65, +inf[
-  ///           });
-  /// It may be that only 64-bit pointers are supported on your target:
-  /// setPointerAction(G_PTR_ADD, 0, LLT:pointer(1),
-  ///           {{1, Unsupported},  // bit sizes [ 1, 63[
-  ///            {64, Legal},       // bit sizes [64, 65[
-  ///            {65, Unsupported}, // bit sizes [65, +inf[
-  ///           });
-  void setScalarAction(const unsigned Opcode, const unsigned TypeIndex,
-                       const SizeAndActionsVec &SizeAndActions) {
-    const unsigned OpcodeIdx = Opcode - FirstOp;
-    SmallVector<SizeAndActionsVec, 1> &Actions = ScalarActions[OpcodeIdx];
-    setActions(TypeIndex, Actions, SizeAndActions);
-  }
-  void setPointerAction(const unsigned Opcode, const unsigned TypeIndex,
-                        const unsigned AddressSpace,
-                        const SizeAndActionsVec &SizeAndActions) {
-    const unsigned OpcodeIdx = Opcode - FirstOp;
-    SmallVector<SizeAndActionsVec, 1> &Actions =
-        AddrSpace2PointerActions[OpcodeIdx][AddressSpace];
-    setActions(TypeIndex, Actions, SizeAndActions);
-  }
-
-  /// If an operation on a given vector type (say <M x iN>) isn't explicitly
-  /// specified, we proceed in 2 stages. First we legalize the underlying scalar
-  /// (so that there's at least one legal vector with that scalar), then we
-  /// adjust the number of elements in the vector so that it is legal. The
-  /// desired action in the first step is controlled by this function.
-  void setScalarInVectorAction(const unsigned Opcode, const unsigned TypeIndex,
-                               const SizeAndActionsVec &SizeAndActions) {
-    unsigned OpcodeIdx = Opcode - FirstOp;
-    SmallVector<SizeAndActionsVec, 1> &Actions =
-        ScalarInVectorActions[OpcodeIdx];
-    setActions(TypeIndex, Actions, SizeAndActions);
-  }
-
-  /// See also setScalarInVectorAction.
-  /// This function let's you specify the number of elements in a vector that
-  /// are legal for a legal element size.
-  void setVectorNumElementAction(const unsigned Opcode,
-                                 const unsigned TypeIndex,
-                                 const unsigned ElementSize,
-                                 const SizeAndActionsVec &SizeAndActions) {
-    const unsigned OpcodeIdx = Opcode - FirstOp;
-    SmallVector<SizeAndActionsVec, 1> &Actions =
-        NumElements2Actions[OpcodeIdx][ElementSize];
-    setActions(TypeIndex, Actions, SizeAndActions);
-  }
-
-  /// A partial SizeAndActionsVec potentially doesn't cover all bit sizes,
-  /// i.e. it's OK if it doesn't start from size 1.
-  static void checkPartialSizeAndActionsVector(const SizeAndActionsVec& v) {
-    using namespace LegacyLegalizeActions;
-#ifndef NDEBUG
-    // The sizes should be in increasing order
-    int prev_size = -1;
-    for(auto SizeAndAction: v) {
-      assert(SizeAndAction.first > prev_size);
-      prev_size = SizeAndAction.first;
-    }
-    // - for every Widen action, there should be a larger bitsize that
-    //   can be legalized towards (e.g. Legal, Lower, Libcall or Custom
-    //   action).
-    // - for every Narrow action, there should be a smaller bitsize that
-    //   can be legalized towards.
-    int SmallestNarrowIdx = -1;
-    int LargestWidenIdx = -1;
-    int SmallestLegalizableToSameSizeIdx = -1;
-    int LargestLegalizableToSameSizeIdx = -1;
-    for(size_t i=0; i<v.size(); ++i) {
-      switch (v[i].second) {
-        case FewerElements:
-        case NarrowScalar:
-          if (SmallestNarrowIdx == -1)
-            SmallestNarrowIdx = i;
-          break;
-        case WidenScalar:
-        case MoreElements:
-          LargestWidenIdx = i;
-          break;
-        case Unsupported:
-          break;
-        default:
-          if (SmallestLegalizableToSameSizeIdx == -1)
-            SmallestLegalizableToSameSizeIdx = i;
-          LargestLegalizableToSameSizeIdx = i;
-      }
-    }
-    if (SmallestNarrowIdx != -1) {
-      assert(SmallestLegalizableToSameSizeIdx != -1);
-      assert(SmallestNarrowIdx > SmallestLegalizableToSameSizeIdx);
-    }
-    if (LargestWidenIdx != -1)
-      assert(LargestWidenIdx < LargestLegalizableToSameSizeIdx);
-#endif
-  }
-
-  /// A full SizeAndActionsVec must cover all bit sizes, i.e. must start with
-  /// from size 1.
-  static void checkFullSizeAndActionsVector(const SizeAndActionsVec& v) {
-#ifndef NDEBUG
-    // Data structure invariant: The first bit size must be size 1.
-    assert(v.size() >= 1);
-    assert(v[0].first == 1);
-    checkPartialSizeAndActionsVector(v);
-#endif
-  }
-
-  /// Sets actions for all bit sizes on a particular generic opcode, type
-  /// index and scalar or pointer type.
-  void setActions(unsigned TypeIndex,
-                  SmallVector<SizeAndActionsVec, 1> &Actions,
-                  const SizeAndActionsVec &SizeAndActions) {
-    checkFullSizeAndActionsVector(SizeAndActions);
-    if (Actions.size() <= TypeIndex)
-      Actions.resize(TypeIndex + 1);
-    Actions[TypeIndex] = SizeAndActions;
-  }
-
-  static SizeAndAction findAction(const SizeAndActionsVec &Vec,
-                                  const uint32_t Size);
-
-  /// Returns the next action needed to get the scalar or pointer type closer
-  /// to being legal
-  /// E.g. findLegalAction({G_REM, 13}) should return
-  /// (WidenScalar, 32). After that, findLegalAction({G_REM, 32}) will
-  /// probably be called, which should return (Lower, 32).
-  /// This is assuming the setScalarAction on G_REM was something like:
-  /// setScalarAction(G_REM, 0,
-  ///           {{1, WidenScalar},  // bit sizes [ 1, 31[
-  ///            {32, Lower},       // bit sizes [32, 33[
-  ///            {33, NarrowScalar} // bit sizes [65, +inf[
-  ///           });
-  std::pair<LegacyLegalizeActions::LegacyLegalizeAction, LLT>
-  findScalarLegalAction(const InstrAspect &Aspect) const;
-
-  /// Returns the next action needed towards legalizing the vector type.
-  std::pair<LegacyLegalizeActions::LegacyLegalizeAction, LLT>
-  findVectorLegalAction(const InstrAspect &Aspect) const;
-
-  static const int FirstOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_START;
-  static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
-
-  // Data structures used temporarily during construction of legality data:
-  using TypeMap = DenseMap<LLT, LegacyLegalizeActions::LegacyLegalizeAction>;
-  SmallVector<TypeMap, 1> SpecifiedActions[LastOp - FirstOp + 1];
-  SmallVector<SizeChangeStrategy, 1>
-      ScalarSizeChangeStrategies[LastOp - FirstOp + 1];
-  SmallVector<SizeChangeStrategy, 1>
-      VectorElementSizeChangeStrategies[LastOp - FirstOp + 1];
-  bool TablesInitialized = false;
-
-  // Data structures used by getAction:
-  SmallVector<SizeAndActionsVec, 1> ScalarActions[LastOp - FirstOp + 1];
-  SmallVector<SizeAndActionsVec, 1> ScalarInVectorActions[LastOp - FirstOp + 1];
-  std::unordered_map<uint16_t, SmallVector<SizeAndActionsVec, 1>>
-      AddrSpace2PointerActions[LastOp - FirstOp + 1];
-  std::unordered_map<uint16_t, SmallVector<SizeAndActionsVec, 1>>
-      NumElements2Actions[LastOp - FirstOp + 1];
-};
-
-} // end namespace llvm
-
-#endif // LLVM_CODEGEN_GLOBALISEL_LEGACYLEGALIZERINFO_H
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
index 1d6a6cfb15a50..e2d845057390e 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
@@ -16,7 +16,6 @@
 
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h"
 #include "llvm/CodeGen/MachineMemOperand.h"
 #include "llvm/CodeGen/TargetOpcodes.h"
 #include "llvm/CodeGenTypes/LowLevelType.h"
@@ -93,10 +92,6 @@ enum LegalizeAction : std::uint8_t {
 
   /// Sentinel value for when no action was found in the specified table.
   NotFound,
-
-  /// Fall back onto the old rules.
-  /// TODO: Remove this once we've migrated
-  UseLegacyRules,
 };
 } // end namespace LegalizeActions
 LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
@@ -154,45 +149,6 @@ struct LegalizeActionStep {
                      const LLT NewType)
       : Action(Action), TypeIdx(TypeIdx), NewType(NewType) {}
 
-  LegalizeActionStep(LegacyLegalizeActionStep Step)
-      : TypeIdx(Step.TypeIdx), NewType(Step.NewType) {
-    switch (Step.Action) {
-    case LegacyLegalizeActions::Legal:
-      Action = LegalizeActions::Legal;
-      break;
-    case LegacyLegalizeActions::NarrowScalar:
-      Action = LegalizeActions::NarrowScalar;
-      break;
-    case LegacyLegalizeActions::WidenScalar:
-      Action = LegalizeActions::WidenScalar;
-      break;
-    case LegacyLegalizeActions::FewerElements:
-      Action = LegalizeActions::FewerElements;
-      break;
-    case LegacyLegalizeActions::MoreElements:
-      Action = LegalizeActions::MoreElements;
-      break;
-    case LegacyLegalizeActions::Bitcast:
-      Action = LegalizeActions::Bitcast;
-      break;
-    case LegacyLegalizeActions::Lower:
-      Action = LegalizeActions::Lower;
-      break;
-    case LegacyLegalizeActions::Libcall:
-      Action = LegalizeActions::Libcall;
-      break;
-    case LegacyLegalizeActions::Custom:
-      Action = LegalizeActions::Custom;
-      break;
-    case LegacyLegalizeActions::Unsupported:
-      Action = LegalizeActions::Unsupported;
-      break;
-    case LegacyLegalizeActions::NotFound:
-      Action = LegalizeActions::NotFound;
-      break;
-    }
-  }
-
   bool operator==(const LegalizeActionStep &RHS) const {
     return std::tie(Action, TypeIdx, NewType) ==
         std::tie(RHS.Action, RHS.TypeIdx, RHS.NewType);
@@ -1348,13 +1304,6 @@ class LegalizeRuleSet {
         .clampMaxNumElements(TypeIdx, EltTy, NumElts);
   }
 
-  /// Fallback on the previous implementation. This should only be used while
-  /// porting a rule.
-  LegalizeRuleSet &fallback() {
-    add({always, LegalizeAction::UseLegacyRules});
-    return *this;
-  }
-
   /// Check if there is no type index which is obviously not handled by the
   /// LegalizeRuleSet in any way at all.
   /// \pre Type indices of the opcode form a dense [0, \p NumTypeIdxs) set.
@@ -1372,11 +1321,6 @@ class LLVM_ABI LegalizerInfo {
 public:
   virtual ~LegalizerInfo() = default;
 
-  const LegacyLegalizerInfo &getLegacyLegalizerInfo() const {
-    return LegacyInfo;
-  }
-  LegacyLegalizerInfo &getLegacyLegalizerInfo() { return LegacyInfo; }
-
   unsigned getOpcodeIdxForOpcode(unsigned Opcode) const;
   unsigned getActionDefinitionsIdx(unsigned Opcode) const;
 
@@ -1464,7 +1408,6 @@ class LLVM_ABI LegalizerInfo {
   static const int LastOp = TargetOpcode::PRE_ISEL_GENERIC_OPCODE_END;
 
   LegalizeRuleSet RulesForOpcode[LastOp - FirstOp + 1];
-  LegacyLegalizerInfo LegacyInfo;
 };
 
 #ifndef NDEBUG
diff --git a/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt b/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt
index 27b6ea745921a..e28dc010816c4 100644
--- a/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt
+++ b/llvm/lib/CodeGen/GlobalISel/CMakeLists.txt
@@ -21,7 +21,6 @@ add_llvm_component_library(LLVMGlobalISel
   Legalizer.cpp
   LegalizerHelper.cpp
   LegalizerInfo.cpp
-  LegacyLegalizerInfo.cpp
   LoadStoreOpt.cpp
   Localizer.cpp
   LostDebugLocObserver.cpp
diff --git a/llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp b/llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp
deleted file mode 100644
index 05923e5fc97cc..0000000000000
--- a/llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp
+++ /dev/null
@@ -1,385 +0,0 @@
-//===- lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp - Legalizer ---------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Implement an interface to specify and query how an illegal operation on a
-// given type should be expanded.
-//
-// Issues to be resolved:
-//   + Make it fast.
-//   + Support weird types like i3, <7 x i3>, ...
-//   + Operations with more than one type (ICMP, CMPXCHG, intrinsics, ...)
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/GlobalISel/LegacyLegalizerInfo.h"
-#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
-#include <map>
-
-using namespace llvm;
-using namespace LegacyLegalizeActions;
-
-#define DEBUG_TYPE "legalizer-info"
-
-raw_ostream &llvm::operator<<(raw_ostream &OS, LegacyLegalizeAction Action) {
-  switch (Action) {
-  case Legal:
-    OS << "Legal";
-    break;
-  case NarrowScalar:
-    OS << "NarrowScalar";
-    break;
-  case WidenScalar:
-    OS << "WidenScalar";
-    break;
-  case FewerElements:
-    OS << "FewerElements";
-    break;
-  case MoreElements:
-    OS << "MoreElements";
-    break;
-  case Bitcast:
-    OS << "Bitcast";
-    break;
-  case Lower:
-    OS << "Lower";
-    break;
-  case Libcall:
-    OS << "Libcall";
-    break;
-  case Custom:
-    OS << "Custom";
-    break;
-  case Unsupported:
-    OS << "Unsupported";
-    break;
-  case NotFound:
-    OS << "NotFound";
-    break;
-  }
-  return OS;
-}
-
-LegacyLegalizerInfo::LegacyLegalizerInfo() {
-  // Set defaults.
-  // FIXME: these two (G_ANYEXT and G_TRUNC?) can be legalized to the
-  // fundamental load/store Jakob proposed. Once loads & stores are supported.
-  setScalarAction(TargetOpcode::G_ANYEXT, 1, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_ZEXT, 1, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_SEXT, 1, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_TRUNC, 0, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_TRUNC, 1, {{1, Legal}});
-
-  setScalarAction(TargetOpcode::G_INTRINSIC, 0, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS, 0, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_INTRINSIC_CONVERGENT, 0, {{1, Legal}});
-  setScalarAction(TargetOpcode::G_INTRINSIC_CONVERGENT_W_SIDE_EFFECTS, 0,
-                  {{1, Legal}});
-
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_IMPLICIT_DEF, 0, narrowToSmallerAndUnsupportedIfTooSmall);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_ADD, 0, widenToLargerTypesAndNarrowToLargest);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_OR, 0, widenToLargerTypesAndNarrowToLargest);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_LOAD, 0, narrowToSmallerAndUnsupportedIfTooSmall);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_STORE, 0, narrowToSmallerAndUnsupportedIfTooSmall);
-
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_BRCOND, 0, widenToLargerTypesUnsupportedOtherwise);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_INSERT, 0, narrowToSmallerAndUnsupportedIfTooSmall);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_EXTRACT, 0, narrowToSmallerAndUnsupportedIfTooSmall);
-  setLegalizeScalarToDifferentSizeStrategy(
-      TargetOpcode::G_EXTRACT, 1, narrowToSmallerAndUnsupportedIfTooSmall);
-  setScalarAction(TargetOpcode::G_FNEG, 0, {{1, Lower}});
-}
-
-void LegacyLegalizerInfo::computeTables() {
-  assert(TablesInitialized == false);
-
-  for (unsigned OpcodeIdx = 0; OpcodeIdx <= LastOp - FirstOp; ++OpcodeIdx) {
-    const unsigned Opcode = FirstOp + OpcodeIdx;
-    for (unsigned TypeIdx = 0; TypeIdx != SpecifiedActions[OpcodeIdx].size();
-         ++TypeIdx) {
-      // 0. Collect information specified through the setAction API, i.e.
-      // for specific bit sizes.
-      // For scalar types:
-      SizeAndActionsVec ScalarSpecifiedActions;
-      // For pointer types:
-      std::map<uint16_t, SizeAndActionsVec> AddressSpace2SpecifiedActions;
-      // For vector types:
-      std::map<uint16_t, SizeAndActionsVec> ElemSize2SpecifiedActions;
-      for (auto LLT2Action : SpecifiedActions[OpcodeIdx][TypeIdx]) {
-        const LLT Type = LLT2Action.first;
-        const LegacyLegalizeAction Action = LLT2Action.second;
-
-        auto SizeAction = std::make_pair(Type.getSizeInBits(), Action);
-        if (Type.isPointer())
-          AddressSpace2SpecifiedActions[Type.getAddressSpace()].push_back(
-              SizeAction);
-        else if (Type.isVector())
-          ElemSize2SpecifiedActions[Type.getElementType().getSizeInBits()]
-              .push_back(SizeAction);
-        else
-          ScalarSpecifiedActions.push_back(SizeAction);
-      }
-
-      // 1. Handle scalar types
-      {
-        // Decide how to handle bit sizes for which no explicit specification
-        // was given.
-        SizeChangeStrategy S = &unsupportedForDifferentSizes;
-        if (TypeIdx < ScalarSizeChangeStrategies[OpcodeIdx].size() &&
-            ScalarSizeChangeStrategies[OpcodeIdx][TypeIdx] != nullptr)
-          S = ScalarSizeChangeStrategies[OpcodeIdx][TypeIdx];
-        llvm::sort(ScalarSpecifiedActions);
-        checkPartialSizeAndActionsVector(ScalarSpecifiedActions);
-        setScalarAction(Opcode, TypeIdx, S(ScalarSpecifiedActions));
-      }
-
-      // 2. Handle pointer types
-      for (auto PointerSpecifiedActions : AddressSpace2SpecifiedActions) {
-        llvm::sort(PointerSpecifiedActions.second);
-        checkPartialSizeAndActionsVector(PointerSpecifiedActions.second);
-        // For pointer types, we assume that there isn't a meaningfull way
-        // to change the number of bits used in the pointer.
-        setPointerAction(
-            Opcode, TypeIdx, PointerSpecifiedActions.first,
-            unsupportedForDifferentSizes(PointerSpecifiedActions.second));
-      }
-
-      // 3. Handle vector types
-      SizeAndActionsVec ElementSizesSeen;
-      for (auto VectorSpecifiedActions : ElemSize2SpecifiedActions) {
-        llvm::sort(VectorSpecifiedActions.second);
-        const uint16_t ElementSize = VectorSpecifiedActions.first;
-        ElementSizesSeen.push_back({ElementSize, Legal});
-        checkPartialSizeAndActionsVector(VectorSpecifiedActions.second);
-        // For vector types, we assume that the best way to adapt the number
-        // of elements is to the next larger number of elements type for which
-        // the vector type is legal, unless there is no such type. In that case,
-        // legalize towards a vector type with a smaller number of elements.
-        SizeAndActionsVec NumElementsActions;
-        for (SizeAndAction BitsizeAndAction : VectorSpecifiedActions.second) {
-          assert(BitsizeAndAction.first % ElementSize == 0);
-          const uint16_t NumElements = BitsizeAndAction.first / ElementSize;
-          NumElementsActions.push_back({NumElements, BitsizeAndAction.second});
-        }
-        setVectorNumElementAction(
-            Opcode, TypeIdx, ElementSize,
-            moreToWiderTypesAndLessToWidest(NumElementsActions));
-      }
-      llvm::sort(ElementSizesSeen);
-      SizeChangeStrategy VectorElementSizeChangeStrategy =
-          &unsupportedForDifferentSizes;
-      if (TypeIdx < VectorElementSizeChangeStrategies[OpcodeIdx].size() &&
-          VectorElementSizeChangeStrategies[OpcodeIdx][TypeIdx] != nullptr)
-        VectorElementSizeChangeStrategy =
-            VectorElementSizeChangeStrategies[OpcodeIdx][TypeIdx];
-      setScalarInVectorAction(
-          Opcode, TypeIdx, VectorElementSizeChangeStrategy(ElementSizesSeen));
-    }
-  }
-
-  TablesInitialized = true;
-}
-
-// FIXME: inefficient implementation for now. Without ComputeValueVTs we're
-// probably going to need specialized lookup structures for various types before
-// we have any hope of doing well with something like <13 x i3>. Even the common
-// cases should do better than what we have now.
-std::pair<LegacyLegalizeAction, LLT>
-LegacyLegalizerInfo::getAspectAction(const InstrAspect &Aspect) const {
-  assert(TablesInitialized && "backend forgot to call computeTables");
-  // These *have* to be implemented for now, they're the fundamental basis of
-  // how everything else is transformed.
-  if (Aspect.Type.isScalar() || Aspect.Type.isPointer())
-    return findScalarLegalAction(Aspect);
-  assert(Aspect.Type.isVector());
-  return findVectorLegalAction(Aspect);
-}
-
-LegacyLegalizerInfo::SizeAndActionsVec
-LegacyLegalizerInfo::increaseToLargerTypesAndDecreaseToLargest(
-    const SizeAndActionsVec &v, LegacyLegalizeAction IncreaseAction,
-    LegacyLegalizeAction DecreaseAction) {
-  SizeAndActionsVec result;
-  unsigned LargestSizeSoFar = 0;
-  if (v.size() >= 1 && v[0].first != 1)
-    result.push_back({1, IncreaseAction});
-  for (size_t i = 0; i < v.size(); ++i) {
-    result.push_back(v[i]);
-    LargestSizeSoFar = v[i].first;
-    if (i + 1 < v.size() && v[i + 1].first != v[i].first + 1) {
-      result.push_back({LargestSizeSoFar + 1, IncreaseAction});
-      LargestSizeSoFar = v[i].first + 1;
-    }
-  }
-  result.push_back({LargestSizeSoFar + 1, DecreaseAction});
-  return result;
-}
-
-LegacyLegalizerInfo::SizeAndActionsVec
-LegacyLegalizerInfo::decreaseToSmallerTypesAndIncreaseToSmallest(
-    const SizeAndActionsVec &v, LegacyLegalizeAction DecreaseAction,
-    LegacyLegalizeAction IncreaseAction) {
-  SizeAndActionsVec result;
-  if (v.size() == 0 || v[0].first != 1)
-    result.push_back({1, IncreaseAction});
-  for (size_t i = 0; i < v.size(); ++i) {
-    result.push_back(v[i]);
-    if (i + 1 == v.size() || v[i + 1].first != v[i].first + 1) {
-      result.push_back({v[i].first + 1, DecreaseAction});
-    }
-  }
-  return result;
-}
-
-LegacyLegalizerInfo::SizeAndAction
-LegacyLegalizerInfo::findAction(const SizeAndActionsVec &Vec, const uint32_t Size) {
-  assert(Size >= 1);
-  // Find the last element in Vec that has a bitsize equal to or smaller than
-  // the requested bit size.
-  // That is the element just before the first element that is bigger than Size.
-  auto It = partition_point(
-      Vec, [=](const SizeAndAction &A) { return A.first <= Size; });
-  assert(It != Vec.begin() && "Does Vec not start with size 1?");
-  int VecIdx = It - Vec.begin() - 1;
-
-  LegacyLegalizeAction Action = Vec[VecIdx].second;
-  switch (Action) {
-  case Legal:
-  case Bitcast:
-  case Lower:
-  case Libcall:
-  case Custom:
-    return {Size, Action};
-  case FewerElements:
-    // FIXME: is this special case still needed and correct?
-    // Special case for scalarization:
-    if (Vec == SizeAndActionsVec({{1, FewerElements}}))
-      return {1, FewerElements};
-    [[fallthrough]];
-  case NarrowScalar: {
-    // The following needs to be a loop, as for now, we do allow needing to
-    // go over "Unsupported" bit sizes before finding a legalizable bit size.
-    // e.g. (s8, WidenScalar), (s9, Unsupported), (s32, Legal). if Size==8,
-    // we need to iterate over s9, and then to s32 to return (s32, Legal).
-    // If we want to get rid of the below loop, we should have stronger asserts
-    // when building the SizeAndActionsVecs, probably not allowing
-    // "Unsupported" unless at the ends of the vector.
-    for (int i = VecIdx - 1; i >= 0; --i)
-      if (!needsLegalizingToDifferentSize(Vec[i].second) &&
-          Vec[i].second != Unsupported)
-        return {Vec[i].first, Action};
-    llvm_unreachable("");
-  }
-  case WidenScalar:
-  case MoreElements: {
-    // See above, the following needs to be a loop, at least for now.
-    for (std::size_t i = VecIdx + 1; i < Vec.size(); ++i)
-      if (!needsLegalizingToDifferentSize(Vec[i].second) &&
-          Vec[i].second != Unsupported)
-        return {Vec[i].first, Action};
-    llvm_unreachable("");
-  }
-  case Unsupported:
-    return {Size, Unsupported};
-  case NotFound:
-    llvm_unreachable("NotFound");
-  }
-  llvm_unreachable("Action has an unknown enum value");
-}
-
-std::pair<LegacyLegalizeAction, LLT>
-LegacyLegalizerInfo::findScalarLegalAction(const InstrAspect &Aspect) const {
-  assert(Aspect.Type.isScalar() || Aspect.Type.isPointer());
-  if (Aspect.Opcode < FirstOp || Aspect.Opcode > LastOp)
-    return {NotFound, LLT()};
-  const unsigned OpcodeIdx = getOpcodeIdxForOpcode(Aspect.Opcode);
-  ArrayRef<SizeAndActionsVec> Actions;
-  if (Aspect.Type.isPointer()) {
-    auto &PA = AddrSpace2PointerActions[OpcodeIdx];
-    auto It = PA.find(Aspect.Type.getAddressSpace());
-    if (It == PA.end())
-      return {NotFound, LLT()};
-    Actions = It->second;
-  } else {
-    Actions = ScalarActions[OpcodeIdx];
-  }
-  if (Aspect.Idx >= Actions.size())
-    return {NotFound, LLT()};
-  const SizeAndActionsVec &Vec = Actions[Aspect.Idx];
-  // FIXME: speed up this search, e.g. by using a results cache for repeated
-  // queries?
-  auto SizeAndAction = findAction(Vec, Aspect.Type.getSizeInBits());
-  return {SizeAndAction.second,
-          Aspect.Type.isScalar() ? LLT::scalar(SizeAndAction.first)
-                                 : LLT::pointer(Aspect.Type.getAddressSpace(),
-                                                SizeAndAction.first)};
-}
-
-std::pair<LegacyLegalizeAction, LLT>
-LegacyLegalizerInfo::findVectorLegalAction(const InstrAspect &Aspect) const {
-  assert(Aspect.Type.isVector());
-  // First legalize the vector element size, then legalize the number of
-  // lanes in the vector.
-  if (Aspect.Opcode < FirstOp || Aspect.Opcode > LastOp)
-    return {NotFound, Aspect.Type};
-  const unsigned OpcodeIdx = getOpcodeIdxForOpcode(Aspect.Opcode);
-  const unsigned TypeIdx = Aspect.Idx;
-  if (TypeIdx >= ScalarInVectorActions[OpcodeIdx].size())
-    return {NotFound, Aspect.Type};
-  const SizeAndActionsVec &ElemSizeVec =
-      ScalarInVectorActions[OpcodeIdx][TypeIdx];
-
-  LLT IntermediateType;
-  auto ElementSizeAndAction =
-      findAction(ElemSizeVec, Aspect.Type.getScalarSizeInBits());
-  IntermediateType = LLT::fixed_vector(Aspect.Type.getNumElements(),
-                                       ElementSizeAndAction.first);
-  if (ElementSizeAndAction.second != Legal)
-    return {ElementSizeAndAction.second, IntermediateType};
-
-  auto i = NumElements2Actions[OpcodeIdx].find(
-      IntermediateType.getScalarSizeInBits());
-  if (i == NumElements2Actions[OpcodeIdx].end()) {
-    return {NotFound, IntermediateType};
-  }
-  const SizeAndActionsVec &NumElementsVec = (*i).second[TypeIdx];
-  auto NumElementsAndAction =
-      findAction(NumElementsVec, IntermediateType.getNumElements());
-  return {NumElementsAndAction.second,
-          LLT::fixed_vector(NumElementsAndAction.first,
-                            IntermediateType.getScalarSizeInBits())};
-}
-
-unsigned LegacyLegalizerInfo::getOpcodeIdxForOpcode(unsigned Opcode) const {
-  assert(Opcode >= FirstOp && Opcode <= LastOp && "Unsupported opcode");
-  return Opcode - FirstOp;
-}
-
-
-LegacyLegalizeActionStep
-LegacyLegalizerInfo::getAction(const LegalityQuery &Query) const {
-  for (unsigned i = 0; i < Query.Types.size(); ++i) {
-    auto Action = getAspectAction({Query.Opcode, i, Query.Types[i]});
-    if (Action.first != Legal) {
-      LLVM_DEBUG(dbgs() << ".. (legacy) Type " << i << " Action="
-                        << Action.first << ", " << Action.second << "\n");
-      return {Action.first, i, Action.second};
-    } else
-      LLVM_DEBUG(dbgs() << ".. (legacy) Type " << i << " Legal\n");
-  }
-  LLVM_DEBUG(dbgs() << ".. (legacy) Legal\n");
-  return {Legal, 0, LLT{}};
-}
-
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
index c2d474fdde696..3e5bbbcf853e8 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp
@@ -75,9 +75,6 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, LegalizeAction Action) {
   case NotFound:
     OS << "NotFound";
     break;
-  case UseLegacyRules:
-    OS << "UseLegacyRules";
-    break;
   }
   return OS;
 }
@@ -193,10 +190,6 @@ static bool mutationIsSane(const LegalizeRule &Rule,
 LegalizeActionStep LegalizeRuleSet::apply(const LegalityQuery &Query) const {
   LLVM_DEBUG(dbgs() << "Applying legalizer ruleset to: "; Query.print(dbgs());
              dbgs() << "\n");
-  if (Rules.empty()) {
-    LLVM_DEBUG(dbgs() << ".. fallback to legacy rules (no rules defined)\n");
-    return {LegalizeAction::UseLegacyRules, 0, LLT{}};
-  }
   for (const LegalizeRule &Rule : Rules) {
     if (Rule.match(Query)) {
       LLVM_DEBUG(dbgs() << ".. match\n");
@@ -343,12 +336,7 @@ void LegalizerInfo::aliasActionDefinitions(unsigned OpcodeTo,
 
 LegalizeActionStep
 LegalizerInfo::getAction(const LegalityQuery &Query) const {
-  LegalizeActionStep Step = getActionDefinitions(Query.Opcode).apply(Query);
-  if (Step.Action != LegalizeAction::UseLegacyRules) {
-    return Step;
-  }
-
-  return getLegacyLegalizerInfo().getAction(Query);
+  return getActionDefinitions(Query.Opcode).apply(Query);
 }
 
 LegalizeActionStep
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index 0db0c937e7c8a..d27447e883593 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -116,10 +116,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
   const TargetMachine &TM = ST.getTargetLowering()->getTargetMachine();
 
   // FIXME: support subtargets which have neon/fp-armv8 disabled.
-  if (!ST.hasNEON() || !ST.hasFPARMv8()) {
-    getLegacyLegalizerInfo().computeTables();
+  if (!ST.hasNEON() || !ST.hasFPARMv8())
     return;
-  }
 
   // Some instructions only support s16 if the subtarget has full 16-bit FP
   // support.
@@ -1514,7 +1512,6 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
   getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
   getActionDefinitionsBuilder(G_INVOKE_REGION_START).alwaysLegal();
 
-  getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
index b543cc90b9f11..4193b7329d27f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
@@ -2235,7 +2235,6 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
       .alwaysLegal();
   getActionDefinitionsBuilder(G_BR).alwaysLegal();
 
-  getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
 
diff --git a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
index ae1f8572a0ef7..ba82c01805532 100644
--- a/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMLegalizerInfo.cpp
@@ -40,10 +40,8 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(ST) {
   const LLT s32 = LLT::scalar(32);
   const LLT s64 = LLT::scalar(64);
 
-  auto &LegacyInfo = getLegacyLegalizerInfo();
   if (ST.isThumb1Only()) {
     // Thumb1 is not supported yet.
-    LegacyInfo.computeTables();
     verify(*ST.getInstrInfo());
     return;
   }
@@ -230,7 +228,6 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(ST) {
         .clampScalar(0, s32, s32);
   }
 
-  LegacyInfo.computeTables();
   verify(*ST.getInstrInfo());
 }
 
diff --git a/llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.cpp b/llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.cpp
index 7c95ecc075f36..92e86fb142253 100644
--- a/llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.cpp
+++ b/llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.cpp
@@ -17,5 +17,4 @@ using namespace llvm;
 using namespace LegalizeActions;
 
 BPFLegalizerInfo::BPFLegalizerInfo(const BPFSubtarget &ST) {
-  getLegacyLegalizerInfo().computeTables();
 }
diff --git a/llvm/lib/Target/M68k/GISel/M68kLegalizerInfo.cpp b/llvm/lib/Target/M68k/GISel/M68kLegalizerInfo.cpp
index 79e9ad4dd1d2a..6e712c3825d50 100644
--- a/llvm/lib/Target/M68k/GISel/M68kLegalizerInfo.cpp
+++ b/llvm/lib/Target/M68k/GISel/M68kLegalizerInfo.cpp
@@ -47,6 +47,4 @@ M68kLegalizerInfo::M68kLegalizerInfo(const M68kSubtarget &ST) {
       .clampScalar(0, s8, s32);
 
   getActionDefinitionsBuilder(G_PTR_ADD).legalFor({{p0, s32}});
-
-  getLegacyLegalizerInfo().computeTables();
 }
diff --git a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
index e1c77849bbb72..b697ca827daa8 100644
--- a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp
@@ -331,7 +331,6 @@ MipsLegalizerInfo::MipsLegalizerInfo(const MipsSubtarget &ST) {
   getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
   getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
 
-  getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
 
diff --git a/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp b/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
index 68061818a46bf..126ba4bb98331 100644
--- a/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
+++ b/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
@@ -86,6 +86,4 @@ PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) {
 
   getActionDefinitionsBuilder({G_INTRINSIC, G_INTRINSIC_W_SIDE_EFFECTS})
       .alwaysLegal();
-
-  getLegacyLegalizerInfo().computeTables();
 }
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 0a08db88699b8..8a4e5d02ec4ea 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -762,7 +762,6 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
 
   getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
 
-  getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
 
diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index 70490823d945d..01a57d64fb4ec 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -519,7 +519,6 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
   getActionDefinitionsBuilder(G_FENCE).alwaysLegal();
   getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
 
-  getLegacyLegalizerInfo().computeTables();
   verify(*ST.getInstrInfo());
 }
 
diff --git a/llvm/lib/Target/WebAssembly/GISel/WebAssemblyLegalizerInfo.cpp b/llvm/lib/Target/WebAssembly/GISel/WebAssemblyLegalizerInfo.cpp
index fb499d0db1733..6bfba8a548981 100644
--- a/llvm/lib/Target/WebAssembly/GISel/WebAssemblyLegalizerInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/GISel/WebAssemblyLegalizerInfo.cpp
@@ -102,8 +102,6 @@ WebAssemblyLegalizerInfo::WebAssemblyLegalizerInfo(
       .legalFor({{f32, f64}})
       .clampScalar(0, s32, s32)
       .clampScalar(1, s64, s64);
-
-  getLegacyLegalizerInfo().computeTables();
 }
 
 bool WebAssemblyLegalizerInfo::legalizeCustom(
diff --git a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
index 6e0605c089b74..77aaa73100845 100644
--- a/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
@@ -623,7 +623,6 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
       .alwaysLegal();
   getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).alwaysLegal();
 
-  getLegacyLegalizerInfo().computeTables();
   verify(*STI.getInstrInfo());
 }
 
diff --git a/llvm/unittests/CodeGen/GlobalISel/GISelMITest.h b/llvm/unittests/CodeGen/GlobalISel/GISelMITest.h
index dbea3f608a881..dcb0ae1d6766e 100644
--- a/llvm/unittests/CodeGen/GlobalISel/GISelMITest.h
+++ b/llvm/unittests/CodeGen/GlobalISel/GISelMITest.h
@@ -170,7 +170,6 @@ class AMDGPUGISelMITest : public GISelMITest {
       (void)s128;                                                              \
       do                                                                       \
         SettingUpActionsBlock while (0);                                       \
-      getLegacyLegalizerInfo().computeTables();                                \
       verify(*ST.getInstrInfo());                                              \
     }                                                                          \
   };
diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
index 809d8880faaed..cdb1283853a20 100644
--- a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
@@ -1435,7 +1435,6 @@ TEST_F(AArch64GISelMITest, MoreElementsAnd) {
   LI.getActionDefinitionsBuilder(TargetOpcode::G_AND)
     .legalFor({v6s32})
     .clampMinNumElements(0, s32, 6);
-  LI.getLegacyLegalizerInfo().computeTables();
 
   DummyGISelObserver Observer;
   LegalizerHelper Helper(*MF, LI, Observer, B);
@@ -1487,7 +1486,6 @@ TEST_F(AArch64GISelMITest, FewerElementsPhi) {
   LI.getActionDefinitionsBuilder(TargetOpcode::G_PHI)
     .legalFor({v2s32})
     .clampMinNumElements(0, s32, 2);
-  LI.getLegacyLegalizerInfo().computeTables();
 
   LLT PhiTy = v5s32;
   DummyGISelObserver Observer;
diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
index 04cd66c7acb2a..578be1c7e247d 100644
--- a/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
+++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
@@ -32,7 +32,6 @@ operator<<(std::ostream &OS, const LegalizeAction Act) {
   case Bitcast: OS << "Bitcast"; break;
   case Unsupported: OS << "Unsupported"; break;
   case NotFound: OS << "NotFound"; break;
-  case UseLegacyRules: OS << "UseLegacyRules"; break;
   }
   return OS;
 }
@@ -44,175 +43,6 @@ std::ostream &operator<<(std::ostream &OS, const llvm::LegalizeActionStep Ty) {
 }
 }
 
-namespace {
-
-
-TEST(LegalizerInfoTest, ScalarRISC) {
-  using namespace TargetOpcode;
-  LegalizerInfo L;
-  auto &LegacyInfo = L.getLegacyLegalizerInfo();
-  // Typical RISCy set of operations based on AArch64.
-  for (unsigned Op : {G_ADD, G_SUB}) {
-    for (unsigned Size : {32, 64})
-      LegacyInfo.setAction({Op, 0, LLT::scalar(Size)},
-                           LegacyLegalizeActions::Legal);
-    LegacyInfo.setLegalizeScalarToDifferentSizeStrategy(
-        Op, 0, LegacyLegalizerInfo::widenToLargerTypesAndNarrowToLargest);
-  }
-
-  LegacyInfo.computeTables();
-
-  for (unsigned opcode : {G_ADD, G_SUB}) {
-    // Check we infer the correct types and actually do what we're told.
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(8)}}),
-              LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(16)}}),
-              LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(32)}}),
-              LegalizeActionStep(Legal, 0, LLT{}));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(64)}}),
-              LegalizeActionStep(Legal, 0, LLT{}));
-
-    // Make sure the default for over-sized types applies.
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(128)}}),
-              LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64)));
-    // Make sure we also handle unusual sizes
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(1)}}),
-              LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(31)}}),
-              LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(33)}}),
-              LegalizeActionStep(WidenScalar, 0, LLT::scalar(64)));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(63)}}),
-              LegalizeActionStep(WidenScalar, 0, LLT::scalar(64)));
-    EXPECT_EQ(L.getAction({opcode, {LLT::scalar(65)}}),
-              LegalizeActionStep(NarrowScalar, 0, LLT::scalar(64)));
-  }
-}
-
-TEST(LegalizerInfoTest, VectorRISC) {
-  using namespace TargetOpcode;
-  LegalizerInfo L;
-  auto &LegacyInfo = L.getLegacyLegalizerInfo();
-  // Typical RISCy set of operations based on ARM.
-  LegacyInfo.setAction({G_ADD, LLT::fixed_vector(8, 8)},
-                       LegacyLegalizeActions::Legal);
-  LegacyInfo.setAction({G_ADD, LLT::fixed_vector(16, 8)},
-                       LegacyLegalizeActions::Legal);
-  LegacyInfo.setAction({G_ADD, LLT::fixed_vector(4, 16)},
-                       LegacyLegalizeActions::Legal);
-  LegacyInfo.setAction({G_ADD, LLT::fixed_vector(8, 16)},
-                       LegacyLegalizeActions::Legal);
-  LegacyInfo.setAction({G_ADD, LLT::fixed_vector(2, 32)},
-                       LegacyLegalizeActions::Legal);
-  LegacyInfo.setAction({G_ADD, LLT::fixed_vector(4, 32)},
-                       LegacyLegalizeActions::Legal);
-
-  LegacyInfo.setLegalizeVectorElementToDifferentSizeStrategy(
-      G_ADD, 0, LegacyLegalizerInfo::widenToLargerTypesUnsupportedOtherwise);
-
-  LegacyInfo.setAction({G_ADD, 0, LLT::scalar(32)},
-                       LegacyLegalizeActions::Legal);
-
-  LegacyInfo.computeTables();
-
-  // Check we infer the correct types and actually do what we're told for some
-  // simple cases.
-  EXPECT_EQ(L.getAction({G_ADD, {LLT::fixed_vector(8, 8)}}),
-            LegalizeActionStep(Legal, 0, LLT{}));
-  EXPECT_EQ(L.getAction({G_ADD, {LLT::fixed_vector(8, 7)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::fixed_vector(8, 8)));
-  EXPECT_EQ(L.getAction({G_ADD, {LLT::fixed_vector(2, 8)}}),
-            LegalizeActionStep(MoreElements, 0, LLT::fixed_vector(8, 8)));
-  EXPECT_EQ(L.getAction({G_ADD, {LLT::fixed_vector(8, 32)}}),
-            LegalizeActionStep(FewerElements, 0, LLT::fixed_vector(4, 32)));
-  // Check a few non-power-of-2 sizes:
-  EXPECT_EQ(L.getAction({G_ADD, {LLT::fixed_vector(3, 3)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::fixed_vector(3, 8)));
-  EXPECT_EQ(L.getAction({G_ADD, {LLT::fixed_vector(3, 8)}}),
-            LegalizeActionStep(MoreElements, 0, LLT::fixed_vector(8, 8)));
-}
-
-TEST(LegalizerInfoTest, MultipleTypes) {
-  using namespace TargetOpcode;
-  LegalizerInfo L;
-  auto &LegacyInfo = L.getLegacyLegalizerInfo();
-  LLT p0 = LLT::pointer(0, 64);
-  LLT s64 = LLT::scalar(64);
-
-  // Typical RISCy set of operations based on AArch64.
-  LegacyInfo.setAction({G_PTRTOINT, 0, s64}, LegacyLegalizeActions::Legal);
-  LegacyInfo.setAction({G_PTRTOINT, 1, p0}, LegacyLegalizeActions::Legal);
-
-  LegacyInfo.setLegalizeScalarToDifferentSizeStrategy(
-      G_PTRTOINT, 0, LegacyLegalizerInfo::widenToLargerTypesAndNarrowToLargest);
-
-  LegacyInfo.computeTables();
-
-  // Check we infer the correct types and actually do what we're told.
-  EXPECT_EQ(L.getAction({G_PTRTOINT, {s64, p0}}),
-            LegalizeActionStep(Legal, 0, LLT{}));
-
-  // Make sure we also handle unusual sizes
-  EXPECT_EQ(
-      L.getAction({G_PTRTOINT, {LLT::scalar(65), s64}}),
-      LegalizeActionStep(NarrowScalar, 0, s64));
-  EXPECT_EQ(
-      L.getAction({G_PTRTOINT, {s64, LLT::pointer(0, 32)}}),
-      LegalizeActionStep(Unsupported, 1, LLT::pointer(0, 32)));
-}
-
-TEST(LegalizerInfoTest, MultipleSteps) {
-  using namespace TargetOpcode;
-  LegalizerInfo L;
-  auto &LegacyInfo = L.getLegacyLegalizerInfo();
-  LLT s32 = LLT::scalar(32);
-  LLT s64 = LLT::scalar(64);
-
-  LegacyInfo.setLegalizeScalarToDifferentSizeStrategy(
-      G_UREM, 0, LegacyLegalizerInfo::widenToLargerTypesUnsupportedOtherwise);
-  LegacyInfo.setAction({G_UREM, 0, s32}, LegacyLegalizeActions::Lower);
-  LegacyInfo.setAction({G_UREM, 0, s64}, LegacyLegalizeActions::Lower);
-
-  LegacyInfo.computeTables();
-
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(16)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(32)}}),
-            LegalizeActionStep(Lower, 0, LLT::scalar(32)));
-}
-
-TEST(LegalizerInfoTest, SizeChangeStrategy) {
-  using namespace TargetOpcode;
-  LegalizerInfo L;
-  auto &LegacyInfo = L.getLegacyLegalizerInfo();
-  for (unsigned Size : {1, 8, 16, 32})
-    LegacyInfo.setAction({G_UREM, 0, LLT::scalar(Size)},
-                         LegacyLegalizeActions::Legal);
-
-  LegacyInfo.setLegalizeScalarToDifferentSizeStrategy(
-      G_UREM, 0, LegacyLegalizerInfo::widenToLargerTypesUnsupportedOtherwise);
-  LegacyInfo.computeTables();
-
-  // Check we infer the correct types and actually do what we're told.
-  for (unsigned Size : {1, 8, 16, 32}) {
-    EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(Size)}}),
-              LegalizeActionStep(Legal, 0, LLT{}));
-  }
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(2)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::scalar(8)));
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(7)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::scalar(8)));
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(9)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::scalar(16)));
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(17)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(31)}}),
-            LegalizeActionStep(WidenScalar, 0, LLT::scalar(32)));
-  EXPECT_EQ(L.getAction({G_UREM, {LLT::scalar(33)}}),
-            LegalizeActionStep(Unsupported, 0, LLT::scalar(33)));
-}
-}
 
 #define EXPECT_ACTION(Action, Index, Type, Query)                              \
   do {                                                                         \
@@ -251,12 +81,10 @@ TEST(LegalizerInfoTest, RuleSets) {
 
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
 
     LI.getActionDefinitionsBuilder(G_IMPLICIT_DEF)
       .legalFor({v4s32, v4p0})
       .moreElementsToNextPow2(0);
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_IMPLICIT_DEF, {s32}));
     EXPECT_ACTION(Unsupported, 0, LLT(), LegalityQuery(G_IMPLICIT_DEF, {v2s32}));
@@ -267,11 +95,9 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test minScalarOrElt
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_OR)
       .legalFor({s32})
       .minScalarOrElt(0, s32);
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(WidenScalar, 0, s32, LegalityQuery(G_OR, {s16}));
     EXPECT_ACTION(WidenScalar, 0, v2s32, LegalityQuery(G_OR, {v2s16}));
@@ -280,11 +106,9 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test maxScalarOrELt
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_AND)
       .legalFor({s16})
       .maxScalarOrElt(0, s16);
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(NarrowScalar, 0, s16, LegalityQuery(G_AND, {s32}));
     EXPECT_ACTION(NarrowScalar, 0, v2s16, LegalityQuery(G_AND, {v2s32}));
@@ -293,11 +117,9 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test clampScalarOrElt
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_XOR)
       .legalFor({s16})
       .clampScalarOrElt(0, s16, s32);
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(NarrowScalar, 0, s32, LegalityQuery(G_XOR, {s64}));
     EXPECT_ACTION(WidenScalar, 0, s16, LegalityQuery(G_XOR, {s8}));
@@ -310,11 +132,9 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test minScalar
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_OR)
       .legalFor({s32})
       .minScalar(0, s32);
-    LegacyInfo.computeTables();
 
     // Only handle scalars, ignore vectors.
     EXPECT_ACTION(WidenScalar, 0, s32, LegalityQuery(G_OR, {s16}));
@@ -325,13 +145,11 @@ TEST(LegalizerInfoTest, RuleSets) {
   {
     bool IfCond = true;
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_OR)
       .legalFor({s32})
       .minScalarIf([&](const LegalityQuery &Query) {
                      return IfCond;
                    }, 0, s32);
-    LegacyInfo.computeTables();
 
     // Only handle scalars, ignore vectors.
     EXPECT_ACTION(WidenScalar, 0, s32, LegalityQuery(G_OR, {s16}));
@@ -345,11 +163,9 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test maxScalar
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_AND)
       .legalFor({s16})
       .maxScalar(0, s16);
-    LegacyInfo.computeTables();
 
     // Only handle scalars, ignore vectors.
     EXPECT_ACTION(NarrowScalar, 0, s16, LegalityQuery(G_AND, {s32}));
@@ -359,12 +175,10 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test clampScalar
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
 
     LI.getActionDefinitionsBuilder(G_XOR)
       .legalFor({s16})
       .clampScalar(0, s16, s32);
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(NarrowScalar, 0, s32, LegalityQuery(G_XOR, {s64}));
     EXPECT_ACTION(WidenScalar, 0, s16, LegalityQuery(G_XOR, {s8}));
@@ -377,12 +191,10 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test widenScalarOrEltToNextPow2
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
 
     LI.getActionDefinitionsBuilder(G_AND)
       .legalFor({s32})
       .widenScalarOrEltToNextPow2(0, 32);
-    LegacyInfo.computeTables();
 
     // Handle scalars and vectors
     EXPECT_ACTION(WidenScalar, 0, s32, LegalityQuery(G_AND, {s5}));
@@ -394,12 +206,10 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test widenScalarToNextPow2
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
 
     LI.getActionDefinitionsBuilder(G_AND)
       .legalFor({s32})
       .widenScalarToNextPow2(0, 32);
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(WidenScalar, 0, s32, LegalityQuery(G_AND, {s5}));
     EXPECT_ACTION(WidenScalar, 0, s64, LegalityQuery(G_AND, {s33}));
@@ -412,7 +222,6 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test changeElementCountTo
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
 
     // Type index form
     LI.getActionDefinitionsBuilder(G_SELECT)
@@ -429,7 +238,6 @@ TEST(LegalizerInfoTest, RuleSets) {
         .fewerElementsIf(typeIs(0, LLT::scalable_vector(8, s16)),
                          changeElementCountTo(0, ElementCount::getFixed(1)));
 
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(MoreElements, 1, v4s1, LegalityQuery(G_SELECT, {v4s32, s1}));
     EXPECT_ACTION(MoreElements, 1, v2s1, LegalityQuery(G_SELECT, {v2s32, s1}));
@@ -455,11 +263,9 @@ TEST(LegalizerInfoTest, RuleSets) {
   // Test minScalarEltSameAsIf
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
 
     LI.getActionDefinitionsBuilder(G_SELECT).minScalarEltSameAsIf(
         all(isVector(0), isVector(1)), 1, 0);
-    LegacyInfo.computeTables();
     LLT p1 = LLT::pointer(1, 32);
     LLT v2p1 = LLT::fixed_vector(2, p1);
 
@@ -476,11 +282,9 @@ TEST(LegalizerInfoTest, MMOAlignment) {
 
   {
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_LOAD)
       .legalForTypesWithMemDesc({{s32, p0, s32, 32}});
 
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(
         Legal, 0, LLT(),
@@ -505,11 +309,9 @@ TEST(LegalizerInfoTest, MMOAlignment) {
     const uint64_t MaxAlignment = UINT64_C(1) << 29;
     const uint64_t MaxAlignInBits = 8 * MaxAlignment;
     LegalizerInfo LI;
-    auto &LegacyInfo = LI.getLegacyLegalizerInfo();
     LI.getActionDefinitionsBuilder(G_LOAD)
       .legalForTypesWithMemDesc({{s32, p0, s32, MaxAlignInBits}});
 
-    LegacyInfo.computeTables();
 
     EXPECT_ACTION(
         Legal, 0, LLT(),
diff --git a/llvm/utils/gn/secondary/llvm/lib/CodeGen/GlobalISel/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/CodeGen/GlobalISel/BUILD.gn
index cf66738e3ad06..5f86839bb90d1 100644
--- a/llvm/utils/gn/secondary/llvm/lib/CodeGen/GlobalISel/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/CodeGen/GlobalISel/BUILD.gn
@@ -29,7 +29,6 @@ static_library("GlobalISel") {
     "InlineAsmLowering.cpp",
     "InstructionSelect.cpp",
     "InstructionSelector.cpp",
-    "LegacyLegalizerInfo.cpp",
     "LegalityPredicates.cpp",
     "LegalizeMutations.cpp",
     "Legalizer.cpp",



More information about the llvm-commits mailing list