Skip to content

Commit bba8956

Browse files
committed
rebased and resolved comments
1 parent 69af41f commit bba8956

File tree

10 files changed

+229
-984
lines changed

10 files changed

+229
-984
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,9 @@ class CombinerHelper {
740740

741741
// Combine trunc(umin(x, C)) -> truncusat_u(x).
742742
bool matchTruncUSatU(MachineInstr &MI, MachineInstr &MinMI) const;
743-
void applyTruncUSatU(MachineInstr &MI, MachineInstr &MinMI) const;
744743

745744
// Combine truncusat_u(fptoui(x)) -> fptoui_sat(x)
746745
bool matchTruncUSatUToFPTOUISat(MachineInstr &MI, MachineInstr &SrcMI) const;
747-
void applyTruncUSatUToFPTOUISat(MachineInstr &MI, MachineInstr &SrcMI) const;
748746

749747
/// Try to transform \p MI by using all of the above
750748
/// combine functions. Returns true if changed.

llvm/include/llvm/CodeGen/GlobalISel/GenericMachineInstrs.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -919,30 +919,6 @@ class GTrunc : public GCastOp {
919919
};
920920
};
921921

922-
/// Represents a saturated trunc from a signed input to a signed result.
923-
class GTruncSSatS : public GCastOp {
924-
public:
925-
static bool classof(const MachineInstr *MI) {
926-
return MI->getOpcode() == TargetOpcode::G_TRUNC_SSAT_S;
927-
};
928-
};
929-
930-
/// Represents a saturated trunc from a signed input to an unsigned result.
931-
class GTruncSSatU : public GCastOp {
932-
public:
933-
static bool classof(const MachineInstr *MI) {
934-
return MI->getOpcode() == TargetOpcode::G_TRUNC_SSAT_U;
935-
};
936-
};
937-
938-
/// Represents a saturated trunc from an unsigned input to an unsigned result.
939-
class GTruncUSatU : public GCastOp {
940-
public:
941-
static bool classof(const MachineInstr *MI) {
942-
return MI->getOpcode() == TargetOpcode::G_TRUNC_USAT_U;
943-
};
944-
};
945-
946922
/// Represents a vscale.
947923
class GVScale : public GenericMachineInstr {
948924
public:

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -740,18 +740,6 @@ m_GFPTrunc(const SrcTy &Src) {
740740
return UnaryOp_match<SrcTy, TargetOpcode::G_FPTRUNC>(Src);
741741
}
742742

743-
template <typename SrcTy>
744-
inline UnaryOp_match<SrcTy, TargetOpcode::G_FPTOSI>
745-
m_GFPToSI(const SrcTy &Src) {
746-
return UnaryOp_match<SrcTy, TargetOpcode::G_FPTOSI>(Src);
747-
}
748-
749-
template <typename SrcTy>
750-
inline UnaryOp_match<SrcTy, TargetOpcode::G_FPTOUI>
751-
m_GFPToUI(const SrcTy &Src) {
752-
return UnaryOp_match<SrcTy, TargetOpcode::G_FPTOUI>(Src);
753-
}
754-
755743
template <typename SrcTy>
756744
inline UnaryOp_match<SrcTy, TargetOpcode::G_FABS> m_GFabs(const SrcTy &Src) {
757745
return UnaryOp_match<SrcTy, TargetOpcode::G_FABS>(Src);

llvm/include/llvm/Target/GlobalISel/Combine.td

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,18 +1256,19 @@ def trunc_ssatu : GICombineRule<
12561256
(apply [{ Helper.applyTruncSSatU(*${root}, ${matchinfo}); }])>;
12571257

12581258
def trunc_usatu : GICombineRule<
1259-
(defs root:$root, register_matchinfo:$matchinfo),
1259+
(defs root:$root),
12601260
(match (G_UMIN $min, $x, $y):$Min,
12611261
(G_TRUNC $dst, $min):$root,
12621262
[{ return Helper.matchTruncUSatU(*${root}, *${Min}); }]),
1263-
(apply [{ Helper.applyTruncUSatU(*${root}, *${Min}); }])>;
1263+
(apply (G_TRUNC_USAT_U $dst, $x))>;
12641264

12651265
def truncusatu_to_fptouisat : GICombineRule<
1266-
(defs root:$root, register_matchinfo:$matchinfo),
1266+
(defs root:$root),
12671267
(match (G_FPTOUI $src, $x):$Src,
12681268
(G_TRUNC_USAT_U $dst, $src):$root,
12691269
[{ return Helper.matchTruncUSatUToFPTOUISat(*${root}, *${Src}); }]),
1270-
(apply [{ Helper.applyTruncUSatUToFPTOUISat(*${root}, *${Src}); }])>;
1270+
(apply (G_FPTOUI_SAT $dst, $x))
1271+
>;
12711272

12721273
def truncsat_combines : GICombineGroup<[trunc_ssats, trunc_ssatu, trunc_usatu, truncusatu_to_fptouisat]>;
12731274

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6004,41 +6004,20 @@ bool CombinerHelper::matchTruncUSatU(MachineInstr &MI,
60046004
unsigned NumSrcBits = SrcTy.getScalarSizeInBits();
60056005
assert(NumSrcBits > NumDstBits && "Unexpected types for truncate operation");
60066006

6007+
if (!LI || !isLegal({TargetOpcode::G_TRUNC_SSAT_U, {DstTy, SrcTy}}))
6008+
return false;
60076009
APInt UnsignedMax = APInt::getMaxValue(NumDstBits).zext(NumSrcBits);
6008-
if (LI && isLegal({TargetOpcode::G_TRUNC_SSAT_U, {DstTy, SrcTy}})) {
6009-
if (mi_match(Min, MRI, m_SpecificICstOrSplat(UnsignedMax)) &&
6010-
!mi_match(Val, MRI, m_GSMax(m_Reg(), m_Reg())))
6011-
return true;
6012-
}
6013-
return false;
6014-
}
6015-
6016-
void CombinerHelper::applyTruncUSatU(MachineInstr &MI,
6017-
MachineInstr &MinMI) const {
6018-
Register Dst = MI.getOperand(0).getReg();
6019-
Register Src = MinMI.getOperand(1).getReg();
6020-
Builder.buildTruncUSatU(Dst, Src);
6021-
MI.eraseFromParent();
6010+
return mi_match(Min, MRI, m_SpecificICstOrSplat(UnsignedMax)) &&
6011+
!mi_match(Val, MRI, m_GSMax(m_Reg(), m_Reg()));
60226012
}
60236013

60246014
bool CombinerHelper::matchTruncUSatUToFPTOUISat(MachineInstr &MI,
60256015
MachineInstr &SrcMI) const {
60266016
LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
60276017
LLT SrcTy = MRI.getType(SrcMI.getOperand(1).getReg());
60286018

6029-
if (LI &&
6030-
isLegalOrBeforeLegalizer({TargetOpcode::G_FPTOUI_SAT, {DstTy, SrcTy}})) {
6031-
return true;
6032-
}
6033-
return false;
6034-
}
6035-
6036-
void CombinerHelper::applyTruncUSatUToFPTOUISat(MachineInstr &MI,
6037-
MachineInstr &SrcMI) const {
6038-
Register Dst = MI.getOperand(0).getReg();
6039-
Register Src = SrcMI.getOperand(1).getReg();
6040-
Builder.buildFPTOUI_SAT(Dst, Src);
6041-
MI.eraseFromParent();
6019+
return LI &&
6020+
isLegalOrBeforeLegalizer({TargetOpcode::G_FPTOUI_SAT, {DstTy, SrcTy}});
60426021
}
60436022

60446023
bool CombinerHelper::matchRedundantNegOperands(MachineInstr &MI,

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,11 +1647,6 @@ bool AArch64LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
16471647
MachineIRBuilder &MIB = Helper.MIRBuilder;
16481648
MachineRegisterInfo &MRI = *MIB.getMRI();
16491649

1650-
auto LowerUnaryOp = [&MI, &MIB](unsigned Opcode) {
1651-
MIB.buildInstr(Opcode, {MI.getOperand(0)}, {MI.getOperand(2)});
1652-
MI.eraseFromParent();
1653-
return true;
1654-
};
16551650
auto LowerUnaryOp = [&MI, &MIB](unsigned Opcode) {
16561651
MIB.buildInstr(Opcode, {MI.getOperand(0)}, {MI.getOperand(2)});
16571652
MI.eraseFromParent();
@@ -1852,11 +1847,11 @@ bool AArch64LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
18521847
case Intrinsic::aarch64_neon_sdot:
18531848
return LowerTriOp(AArch64::G_SDOT);
18541849
case Intrinsic::aarch64_neon_sqxtn:
1855-
return LowerUnaryOp(AArch64::G_TRUNC_SSAT_S);
1850+
return LowerUnaryOp(TargetOpcode::G_TRUNC_SSAT_S);
18561851
case Intrinsic::aarch64_neon_sqxtun:
1857-
return LowerUnaryOp(AArch64::G_TRUNC_SSAT_U);
1852+
return LowerUnaryOp(TargetOpcode::G_TRUNC_SSAT_U);
18581853
case Intrinsic::aarch64_neon_uqxtn:
1859-
return LowerUnaryOp(AArch64::G_TRUNC_USAT_U);
1854+
return LowerUnaryOp(TargetOpcode::G_TRUNC_USAT_U);
18601855

18611856
case Intrinsic::vector_reverse:
18621857
// TODO: Add support for vector_reverse

0 commit comments

Comments
 (0)