[llvm] [AArch64][SPIRV][GlobalISel] Migrate wip_match_opcode combines to MIR-pattern (PR #222903)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 02:51:46 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Vikash Gupta (vg0204)
<details>
<summary>Changes</summary>
It replaces the `wip_match_opcode` with declarative MIR-pattern match roots across the AArch64 and SPIRV target-specific GICombines.
Some important points to consider :
- **shuffle_vector_lowering:** these `G_SHUFFLE_VECTOR` rules are order- sensitive. `fullrev` previously gained priority through a nested `G_IMPLICIT_DEF` match; that predicate is relocated to C++ so all rules are equal-priority and `fullrev` is ordered last, preserving the original dispatch sequence and codegen.
- **SPIRV intrinsic roots:** the matrix/length/distance rules match and apply on target intrinsics (`int_spv_*`, `int_matrix_*`), requiring the `IntrinsicsSPIRV` enum in the combiner translation unit.
- **Deferred:** `vector_unmerge_lowering` and `unmerge_ext_to_unmerge` remain on `wip_match_opcode`; their `G_UNMERGE_VALUES` variadic-def roots are not yet expressible as MIR patterns.
---
Patch is 58.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/222903.diff
10 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64Combine.td (+45-32)
- (modified) llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp (-63)
- (modified) llvm/lib/Target/SPIRV/SPIRVCombine.td (+8-11)
- (modified) llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp (-33)
- (modified) llvm/lib/Target/SPIRV/SPIRVCombinerHelper.h (-2)
- (modified) llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp (+1)
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-anyext-to-zext.mir (+1-1)
- (modified) llvm/test/CodeGen/AArch64/arm64-extract-insert-varidx.ll (+3-7)
- (modified) llvm/test/CodeGen/AArch64/insertextract.ll (+4-12)
- (modified) llvm/test/CodeGen/AArch64/neon-shuffle-vector-tbl.ll (+234-397)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64Combine.td b/llvm/lib/Target/AArch64/AArch64Combine.td
index 7a8083e3ceb448..af3675264e7d58 100644
--- a/llvm/lib/Target/AArch64/AArch64Combine.td
+++ b/llvm/lib/Target/AArch64/AArch64Combine.td
@@ -21,7 +21,7 @@ def icmp_redundant_trunc : GICombineRule<
def fold_global_offset_matchdata : GIDefMatchData<"std::pair<uint64_t, uint64_t>">;
def fold_global_offset : GICombineRule<
(defs root:$root, fold_global_offset_matchdata:$matchinfo),
- (match (wip_match_opcode G_GLOBAL_VALUE):$root,
+ (match (G_GLOBAL_VALUE $dst, $gv):$root,
[{ return matchFoldGlobalOffset(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyFoldGlobalOffset(*${root}, MRI, B, Observer, ${matchinfo});}])
>;
@@ -31,7 +31,7 @@ def ext_addv_to_udot_addv_matchinfo : GIDefMatchData<"std::tuple<Register, Regis
let Predicates = [HasDotProd] in {
def ext_addv_to_udot_addv : GICombineRule<
(defs root:$root, ext_addv_to_udot_addv_matchinfo:$matchinfo),
- (match (wip_match_opcode G_VECREDUCE_ADD):$root,
+ (match (G_VECREDUCE_ADD $dst, $src):$root,
[{ return matchExtAddvToDotAddv(*${root}, MRI, STI, ${matchinfo}); }]),
(apply [{ applyExtAddvToDotAddv(*${root}, MRI, B, Observer, STI, ${matchinfo}); }])
>;
@@ -40,7 +40,7 @@ def ext_addv_to_udot_addv : GICombineRule<
def ext_uaddv_to_uaddlv_matchinfo : GIDefMatchData<"std::pair<Register, bool>">;
def ext_uaddv_to_uaddlv : GICombineRule<
(defs root:$root, ext_uaddv_to_uaddlv_matchinfo:$matchinfo),
- (match (wip_match_opcode G_VECREDUCE_ADD):$root,
+ (match (G_VECREDUCE_ADD $dst, $src):$root,
[{ return matchExtUaddvToUaddlv(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyExtUaddvToUaddlv(*${root}, MRI, B, Observer, ${matchinfo}); }])
>;
@@ -110,58 +110,60 @@ def shuffle_matchdata : GIDefMatchData<"ShuffleVectorPseudo">;
def rev : GICombineRule<
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchREV(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyShuffleVectorPseudo(*${root}, MRI, ${matchinfo}); }])
>;
def zip : GICombineRule<
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchZip(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyShuffleVectorPseudo(*${root}, MRI, ${matchinfo}); }])
>;
def uzp : GICombineRule<
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchUZP(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyShuffleVectorPseudo(*${root}, MRI, ${matchinfo}); }])
>;
def dup: GICombineRule <
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchDup(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyShuffleVectorPseudo(*${root}, MRI, ${matchinfo}); }])
>;
def trn : GICombineRule<
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchTRN(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyShuffleVectorPseudo(*${root}, MRI, ${matchinfo}); }])
>;
def ext: GICombineRule <
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchEXT(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyEXT(*${root}, ${matchinfo}); }])
>;
+// src2 == G_IMPLICIT_DEF is checked in C++, not as a nested operand match, to
+// keep fullrev equal-priority with the other shuffle rules (so it stays last).
def fullrev: GICombineRule <
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (G_IMPLICIT_DEF $src2),
- (G_SHUFFLE_VECTOR $src, $src1, $src2, $mask):$root,
- [{ return ShuffleVectorInst::isReverseMask(${mask}.getShuffleMask(),
+ (match (G_SHUFFLE_VECTOR $src, $src1, $src2, $mask):$root,
+ [{ return mi_match(${src2}.getReg(), MRI, m_GImplicitDef()) &&
+ ShuffleVectorInst::isReverseMask(${mask}.getShuffleMask(),
${mask}.getShuffleMask().size()); }]),
(apply [{ applyFullRev(*${root}, MRI); }])
>;
def insertelt_nonconst: GICombineRule <
(defs root:$root, shuffle_matchdata:$matchinfo),
- (match (wip_match_opcode G_INSERT_VECTOR_ELT):$root,
+ (match (G_INSERT_VECTOR_ELT $dst, $src, $elt, $idx):$root,
[{ return matchNonConstInsert(*${root}, MRI); }]),
(apply [{ applyNonConstInsert(*${root}, MRI, B); }])
>;
@@ -169,23 +171,26 @@ def insertelt_nonconst: GICombineRule <
def shuf_to_ins_matchdata : GIDefMatchData<"std::tuple<Register, int, Register, int>">;
def shuf_to_ins: GICombineRule <
(defs root:$root, shuf_to_ins_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchINS(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyINS(*${root}, MRI, B, ${matchinfo}); }])
>;
+def vashr_vlshr_imm_frags : GICombinePatFrag<
+ (outs root:$dst), (ins),
+ !foreach(op, [G_ASHR, G_LSHR], (pattern (op $dst, $src, $amt)))>;
def vashr_vlshr_imm : GICombineRule<
(defs root:$root, int64_matchinfo:$matchinfo),
- (match (wip_match_opcode G_ASHR, G_LSHR):$root,
- [{ return matchVAshrLshrImm(*${root}, MRI, ${matchinfo}); }]),
- (apply [{ applyVAshrLshrImm(*${root}, MRI, ${matchinfo}); }])
+ (match (vashr_vlshr_imm_frags $root):$mi,
+ [{ return matchVAshrLshrImm(*${mi}, MRI, ${matchinfo}); }]),
+ (apply [{ applyVAshrLshrImm(*${mi}, MRI, ${matchinfo}); }])
>;
def form_duplane_matchdata :
GIDefMatchData<"std::pair<unsigned, int>">;
def form_duplane : GICombineRule <
(defs root:$root, form_duplane_matchdata:$matchinfo),
- (match (wip_match_opcode G_SHUFFLE_VECTOR):$root,
+ (match (G_SHUFFLE_VECTOR $dst, $src1, $src2, $mask):$root,
[{ return matchDupLane(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyDupLane(*${root}, MRI, B, ${matchinfo}); }])
>;
@@ -220,7 +225,7 @@ def unmerge_duplanes : GICombineGroup<[unmerge_duplane8, unmerge_duplane16,
extract_duplane16, extract_duplane32]>;
def shuffle_vector_lowering : GICombineGroup<[dup, form_duplane, rev, ext, zip,
- uzp, trn, fullrev, shuf_to_ins]>;
+ uzp, trn, shuf_to_ins, fullrev]>;
// Turn G_UNMERGE_VALUES -> G_EXTRACT_VECTOR_ELT's
def vector_unmerge_lowering : GICombineRule <
@@ -251,7 +256,7 @@ def icmp_lowering : GICombineGroup<[adjust_icmp_imm, swap_icmp_operands]>;
def extractvecelt_pairwise_add_matchdata : GIDefMatchData<"std::tuple<unsigned, LLT, Register>">;
def extractvecelt_pairwise_add : GICombineRule<
(defs root:$root, extractvecelt_pairwise_add_matchdata:$matchinfo),
- (match (wip_match_opcode G_EXTRACT_VECTOR_ELT):$root,
+ (match (G_EXTRACT_VECTOR_ELT $dst, $src, $idx):$root,
[{ return matchExtractVecEltPairwiseAdd(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyExtractVecEltPairwiseAdd(*${root}, MRI, B, ${matchinfo}); }])
>;
@@ -259,7 +264,7 @@ def extractvecelt_pairwise_add : GICombineRule<
def mul_const_matchdata : GIDefMatchData<"std::function<void(MachineIRBuilder&, Register)>">;
def mul_const : GICombineRule<
(defs root:$root, mul_const_matchdata:$matchinfo),
- (match (wip_match_opcode G_MUL):$root,
+ (match (G_MUL $dst, $src1, $src2):$root,
[{ return matchAArch64MulConstCombine(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyAArch64MulConstCombine(*${root}, MRI, B, ${matchinfo}); }])
>;
@@ -274,13 +279,14 @@ def extmultomull : GICombineRule<
// The mid end will reassociate sub(sub(x, m1), m2) to sub(x, add(m1, m2))
// This reassociates it back to allow the creation of more mls instructions.
+// src3 - (src1 + src2) -> (src3 - src1) - src2, when src1/src2 are muls.
def subaddmulreassoc : GICombineRule<
(defs root:$dst),
(match (G_ADD $tmp, $src1, $src2):$sub,
(G_SUB $dst, $src3, $tmp):$root,
[{ return matchSubAddMulReassoc(${src1}.getReg(), ${src2}.getReg(),
${tmp}.getReg(), ${src3}.getReg(), MRI); }]),
- (apply [{ applySubAddMulReassoc(*${root}, *${sub}, MRI, B, Observer); }])>;
+ (apply (G_SUB $t, $src3, $src1), (G_SUB $dst, $t, $src2))>;
def lower_mulv2s64 : GICombineRule<
(defs root:$root),
@@ -291,7 +297,7 @@ def lower_mulv2s64 : GICombineRule<
def build_vector_to_dup : GICombineRule<
(defs root:$root, register_matchinfo:$matchinfo),
- (match (wip_match_opcode G_BUILD_VECTOR):$root,
+ (match (G_BUILD_VECTOR $dst, GIVariadic<>:$unused):$root,
[{ return matchBuildVectorToDup(*${root}, ${matchinfo}, MRI); }]),
(apply [{ applyBuildVectorToDup(*${root}, ${matchinfo}, MRI, B); }])
>;
@@ -321,17 +327,24 @@ def form_truncstore : GICombineRule<
def fold_merge_to_zext : GICombineRule<
(defs root:$d),
- (match (wip_match_opcode G_MERGE_VALUES):$d,
- [{ return matchFoldMergeToZext(*${d}, MRI); }]),
- (apply [{ applyFoldMergeToZext(*${d}, MRI, B, Observer); }])
+ (match (G_CONSTANT $zero, 0),
+ (G_MERGE_VALUES $dst, $x, $zero):$d,
+ [{ return MRI.getType(${x}.getReg()) == LLT::scalar(32); }]),
+ (apply (G_ZEXT $dst, $x))
>;
-def mutate_anyext_to_zext : GICombineRule<
+// G_ANYEXT of a scalar compare (0/1) -> G_ZEXT, to expose more KnownBits combines.
+class mutate_anyext_to_zext_cmp<Instruction cmpOpc> : GICombineRule<
(defs root:$d),
- (match (wip_match_opcode G_ANYEXT):$d,
- [{ return matchMutateAnyExtToZExt(*${d}, MRI); }]),
- (apply [{ applyMutateAnyExtToZExt(*${d}, MRI, B, Observer); }])
+ (match (cmpOpc $cmp, $p, $a, $b),
+ (G_ANYEXT $dst, $cmp):$d,
+ [{ return MRI.getType(${dst}.getReg()).isScalar(); }]),
+ (apply (G_ZEXT $dst, $cmp))
>;
+def mutate_anyext_to_zext_icmp : mutate_anyext_to_zext_cmp<G_ICMP>;
+def mutate_anyext_to_zext_fcmp : mutate_anyext_to_zext_cmp<G_FCMP>;
+def mutate_anyext_to_zext : GICombineGroup<[mutate_anyext_to_zext_icmp,
+ mutate_anyext_to_zext_fcmp]>;
def split_store_zero_128 : GICombineRule<
(defs root:$d),
@@ -342,7 +355,7 @@ def split_store_zero_128 : GICombineRule<
def vector_sext_inreg_to_shift : GICombineRule<
(defs root:$d),
- (match (wip_match_opcode G_SEXT_INREG):$d,
+ (match (G_SEXT_INREG $dst, $src, $imm):$d,
[{ return matchVectorSextInReg(*${d}, MRI); }]),
(apply [{ applyVectorSextInReg(*${d}, MRI, B, Observer); }])
>;
@@ -375,7 +388,7 @@ def trunc_or_to_addhn : GICombineRule <
// Combines Mul(And(Srl(X, 15), 0x10001), 0xffff) into CMLTz
def combine_mul_cmlt : GICombineRule<
(defs root:$root, register_matchinfo:$matchinfo),
- (match (wip_match_opcode G_MUL):$root,
+ (match (G_MUL $dst, $src1, $src2):$root,
[{ return matchCombineMulCMLT(*${root}, MRI, ${matchinfo}); }]),
(apply [{ applyCombineMulCMLT(*${root}, MRI, B, ${matchinfo}); }])
>;
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
index 6ba25ac4ffa0a7..c0f54356a4fcaf 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
@@ -257,54 +257,6 @@ void applyAArch64MulConstCombine(
MI.eraseFromParent();
}
-/// Try to fold a G_MERGE_VALUES of 2 s32 sources, where the second source
-/// is a zero, into a G_ZEXT of the first.
-bool matchFoldMergeToZext(MachineInstr &MI, MachineRegisterInfo &MRI) {
- auto &Merge = cast<GMerge>(MI);
- LLT SrcTy = MRI.getType(Merge.getSourceReg(0));
- if (SrcTy != LLT::scalar(32) || Merge.getNumSources() != 2)
- return false;
- return mi_match(Merge.getSourceReg(1), MRI, m_SpecificICst(0));
-}
-
-void applyFoldMergeToZext(MachineInstr &MI, MachineRegisterInfo &MRI,
- MachineIRBuilder &B, GISelChangeObserver &Observer) {
- // Mutate %d(s64) = G_MERGE_VALUES %a(s32), 0(s32)
- // ->
- // %d(s64) = G_ZEXT %a(s32)
- Observer.changingInstr(MI);
- MI.setDesc(B.getTII().get(TargetOpcode::G_ZEXT));
- MI.removeOperand(2);
- Observer.changedInstr(MI);
-}
-
-/// \returns True if a G_ANYEXT instruction \p MI should be mutated to a G_ZEXT
-/// instruction.
-bool matchMutateAnyExtToZExt(MachineInstr &MI, MachineRegisterInfo &MRI) {
- // If this is coming from a scalar compare then we can use a G_ZEXT instead of
- // a G_ANYEXT:
- //
- // %cmp:_(s32) = G_[I|F]CMP ... <-- produces 0/1.
- // %ext:_(s64) = G_ANYEXT %cmp(s32)
- //
- // By doing this, we can leverage more KnownBits combines.
- assert(MI.getOpcode() == TargetOpcode::G_ANYEXT);
- Register Dst = MI.getOperand(0).getReg();
- Register Src = MI.getOperand(1).getReg();
- return MRI.getType(Dst).isScalar() &&
- mi_match(Src, MRI,
- m_any_of(m_GICmp(m_Pred(), m_Reg(), m_Reg()),
- m_GFCmp(m_Pred(), m_Reg(), m_Reg())));
-}
-
-void applyMutateAnyExtToZExt(MachineInstr &MI, MachineRegisterInfo &MRI,
- MachineIRBuilder &B,
- GISelChangeObserver &Observer) {
- Observer.changingInstr(MI);
- MI.setDesc(B.getTII().get(TargetOpcode::G_ZEXT));
- Observer.changedInstr(MI);
-}
-
/// Match a 128b store of zero and split it into two 64 bit stores, for
/// size/performance reasons.
bool matchSplitStoreZero128(MachineInstr &MI, MachineRegisterInfo &MRI) {
@@ -608,21 +560,6 @@ static bool matchSubAddMulReassoc(Register Mul1, Register Mul2, Register Sub,
return true;
}
-static void applySubAddMulReassoc(MachineInstr &MI, MachineInstr &Sub,
- MachineRegisterInfo &MRI, MachineIRBuilder &B,
- GISelChangeObserver &Observer) {
- Register Src = MI.getOperand(1).getReg();
- Register Tmp = MI.getOperand(2).getReg();
- Register Mul1 = Sub.getOperand(1).getReg();
- Register Mul2 = Sub.getOperand(2).getReg();
- Observer.changingInstr(MI);
- B.buildInstr(AArch64::G_SUB, {Tmp}, {Src, Mul1});
- MI.getOperand(1).setReg(Tmp);
- MI.getOperand(2).setReg(Mul2);
- Sub.eraseFromParent();
- Observer.changedInstr(MI);
-}
-
class AArch64PostLegalizerCombinerImpl : public Combiner {
protected:
const CombinerHelper Helper;
diff --git a/llvm/lib/Target/SPIRV/SPIRVCombine.td b/llvm/lib/Target/SPIRV/SPIRVCombine.td
index 44512229a8ff19..cfab5ec26b4e1d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCombine.td
+++ b/llvm/lib/Target/SPIRV/SPIRVCombine.td
@@ -8,23 +8,24 @@
include "llvm/Target/GlobalISel/Combine.td"
+// length(x - y) -> distance(x, y)
def vector_length_sub_to_distance_lowering : GICombineRule <
(defs root:$root),
- (match (wip_match_opcode G_INTRINSIC):$root,
- [{ return Helper.matchLengthToDistance(*${root}); }]),
- (apply [{ Helper.applySPIRVDistance(*${root}); }])
+ (match (G_FSUB $sub, $x, $y),
+ (int_spv_length $dst, $sub):$root),
+ (apply (int_spv_distance $dst, $x, $y))
>;
def vector_fdiv_length_to_normalize_lowering : GICombineRule <
(defs root:$root),
- (match (wip_match_opcode G_FDIV):$root,
+ (match (G_FDIV $dst, $src1, $src2):$root,
[{ return Helper.matchFDivToNormalize(*${root}); }]),
(apply [{ Helper.applySPIRVNormalize(*${root}); }])
>;
def vector_select_to_faceforward_lowering : GICombineRule <
(defs root:$root),
- (match (wip_match_opcode G_SELECT):$root,
+ (match (G_SELECT $dst, $cond, $t, $f):$root,
[{ return Helper.matchSelectToFaceForward(*${root}); }]),
(apply [{ Helper.applySPIRVFaceForward(*${root}); }])
>;
@@ -32,17 +33,13 @@ def vector_select_to_faceforward_lowering : GICombineRule <
def matrix_transpose_lowering
: GICombineRule<
(defs root:$root),
- (match (wip_match_opcode G_INTRINSIC):$root,
- [{ return mi_match(*${root}, MRI,
- m_GIntrinsic<Intrinsic::matrix_transpose>()); }]),
+ (match (int_matrix_transpose $dst, $matrix, $rows, $cols):$root),
(apply [{ Helper.applyMatrixTranspose(*${root}); }])>;
def matrix_multiply_lowering
: GICombineRule<
(defs root:$root),
- (match (wip_match_opcode G_INTRINSIC):$root,
- [{ return mi_match(*${root}, MRI,
- m_GIntrinsic<Intrinsic::matrix_multiply>()); }]),
+ (match (int_matrix_multiply $dst, $a, $b, $m, $n, $k):$root),
(apply [{ Helper.applyMatrixMultiply(*${root}); }])>;
def SPIRVPreLegalizerCombiner
diff --git a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
index 63fe8688359fd7..d8fbfb87a01156 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
@@ -24,39 +24,6 @@ SPIRVCombinerHelper::SPIRVCombinerHelper(
const SPIRVSubtarget &STI)
: CombinerHelper(Observer, B, IsPreLegalize, VT, MDT, LI), STI(STI) {}
-/// This match is part of a combine that
-/// rewrites length(X - Y) to distance(X, Y)
-/// (f32 (g_intrinsic length
-/// (g_fsub (vXf32 X) (vXf32 Y))))
-/// ->
-/// (f32 (g_intrinsic distance
-/// (vXf32 X) (vXf32 Y)))
-///
-bool SPIRVCombinerHelper::matchLengthToDistance(MachineInstr &MI) const {
- if (!mi_match(MI, MRI, m_GIntrinsic<Intrinsic::spv_length>()))
- return false;
-
- // First operand of MI is `G_INTRINSIC` so start at operand 2.
- Register SubReg = MI.getOperand(2).getReg();
- return mi_match(SubReg, MRI, m_GFSub(m_Reg(), m_Reg()));
-}
-
-void SPIRVCombinerHelper::applySPIRVDistance(MachineInstr &MI) const {
- // Extract the operands for X and Y from the match criteria.
- Register SubDestReg = MI.getOperand(2).getReg();
- MachineInstr *SubInstr = MRI.getVRegDef(SubDestReg);
- Register SubOperand1 = SubInstr->getOperand(1).getReg();
- Register SubOperand2 = SubInstr->getOperand(2).getReg();
- Register ResultReg = MI.getOperand(0).getReg();
-
- Builder.setInstrAndDebugLoc(MI);
- Builder.buildIntrinsic(Intrinsic::spv_distance, ResultReg)
- .addUse(SubOperand1)
- .addUse(SubOperand2);
-
- MI.eraseFromParent();
-}
-
/// This match is part of a combine that
/// rewrites X / length(X) to normalize(X)
/// (vXf32 (g_fdiv
diff --git a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.h b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.h
index af9bcd73479801..3912f4608cf2fd 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.h
+++ b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.h
@@ -29,8 +29,6 @@ class SPIRVCombinerHelper : public CombinerHelper {
MachineDominatorTree *MDT, const LegalizerInfo *LI,
const SPIRVSubtarget &STI);
- bool matchLengthToDistance(MachineInstr &MI) const;
- void applySPIRVDistance(MachineInstr &MI) const;
bool matchFDivToNormalize(MachineInstr &MI) const;
void applySPIRVNormalize(MachineInstr &MI) const;
bool matchSelectToFaceForward(MachineInstr &MI) const;
diff --git a/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp b/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
index 1e1fbe75f53c2a..cc4ee20ceee7d3 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
@@ -26,6 +26,7 @@
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/Analysis.h"
+#include "llvm/IR/IntrinsicsSPIRV.h"
#define GET_GICOMBINER_DEPS
#include "SPIRVGenPreLegalizeGICombiner.inc"
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-anyext-to-zext.mir b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-anyext-to-zext.mir
index 69d2f9f0cd3bb4..bab7c192da084e 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-anyext-to-zext.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/postlegalizer-combiner-anyext-to-zext.mir
@@ -1,...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/222903
More information about the llvm-commits
mailing list