LLVM 20.0.0git
CombinerHelperArtifacts.cpp
Go to the documentation of this file.
1//===- CombinerHelperArtifacts.cpp-----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements CombinerHelper for legalization artifacts.
10//
11//===----------------------------------------------------------------------===//
12//
13// G_MERGE_VALUES
14//
15//===----------------------------------------------------------------------===//
26
27#define DEBUG_TYPE "gi-combiner"
28
29using namespace llvm;
30
32 BuildFnTy &MatchInfo) const {
33 const GMerge *Merge = cast<GMerge>(&MI);
34
35 Register Dst = Merge->getReg(0);
36 LLT DstTy = MRI.getType(Dst);
37 LLT SrcTy = MRI.getType(Merge->getSourceReg(0));
38
39 // Otherwise, we would miscompile.
40 assert(Merge->getNumSources() == 2 && "Unexpected number of operands");
41
42 //
43 // %bits_8_15:_(s8) = G_IMPLICIT_DEF
44 // %0:_(s16) = G_MERGE_VALUES %bits_0_7:(s8), %bits_8_15:(s8)
45 //
46 // ->
47 //
48 // %0:_(s16) = G_ANYEXT %bits_0_7:(s8)
49 //
50
51 if (!isLegalOrBeforeLegalizer({TargetOpcode::G_ANYEXT, {DstTy, SrcTy}}))
52 return false;
53
54 MatchInfo = [=](MachineIRBuilder &B) {
55 B.buildAnyExt(Dst, Merge->getSourceReg(0));
56 };
57 return true;
58}
59
61 BuildFnTy &MatchInfo) const {
62 const GMerge *Merge = cast<GMerge>(&MI);
63
64 Register Dst = Merge->getReg(0);
65 LLT DstTy = MRI.getType(Dst);
66 LLT SrcTy = MRI.getType(Merge->getSourceReg(0));
67
68 // No multi-use check. It is a constant.
69
70 //
71 // %bits_8_15:_(s8) = G_CONSTANT i8 0
72 // %0:_(s16) = G_MERGE_VALUES %bits_0_7:(s8), %bits_8_15:(s8)
73 //
74 // ->
75 //
76 // %0:_(s16) = G_ZEXT %bits_0_7:(s8)
77 //
78
79 if (!isLegalOrBeforeLegalizer({TargetOpcode::G_ZEXT, {DstTy, SrcTy}}))
80 return false;
81
82 MatchInfo = [=](MachineIRBuilder &B) {
83 B.buildZExt(Dst, Merge->getSourceReg(0));
84 };
85 return true;
86}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This contains common combine transformations that may be used in a combine pass,or by the target else...
IRTranslator LLVM IR MI
Interface for Targets to specify which operations they can successfully select and how the others sho...
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
R600 Clause Merge
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool matchMergeXAndZero(const MachineInstr &MI, BuildFnTy &MatchInfo) const
bool matchMergeXAndUndef(const MachineInstr &MI, BuildFnTy &MatchInfo) const
MachineRegisterInfo & MRI
bool isLegalOrBeforeLegalizer(const LegalityQuery &Query) const
Represents a G_MERGE_VALUES.
Helper class to build MachineInstr.
Representation of each machine instruction.
Definition: MachineInstr.h:69
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::function< void(MachineIRBuilder &)> BuildFnTy