[llvm] r316602 - Make the combiner check if shifts are legal before creating them
Aditya Nandakumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 25 11:49:18 PDT 2017
Author: aditya_nandakumar
Date: Wed Oct 25 11:49:18 2017
New Revision: 316602
URL: http://llvm.org/viewvc/llvm-project?rev=316602&view=rev
Log:
Make the combiner check if shifts are legal before creating them
Summary: Make sure shifts are legal/specified by the legalizerinfo before creating it
Reviewers: qcolombet, dsanders, rovka, t.p.northover
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D39264
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerCombiner.h
llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerCombiner.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerCombiner.h?rev=316602&r1=316601&r2=316602&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerCombiner.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerCombiner.h Wed Oct 25 11:49:18 2017
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GlobalISel/Legalizer.h"
+#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -24,10 +25,12 @@ namespace llvm {
class LegalizerCombiner {
MachineIRBuilder &Builder;
MachineRegisterInfo &MRI;
+ const LegalizerInfo &LI;
public:
- LegalizerCombiner(MachineIRBuilder &B, MachineRegisterInfo &MRI)
- : Builder(B), MRI(MRI) {}
+ LegalizerCombiner(MachineIRBuilder &B, MachineRegisterInfo &MRI,
+ const LegalizerInfo &LI)
+ : Builder(B), MRI(MRI), LI(LI) {}
bool tryCombineAnyExt(MachineInstr &MI,
SmallVectorImpl<MachineInstr *> &DeadInsts) {
@@ -54,12 +57,15 @@ public:
return false;
MachineInstr *DefMI = MRI.getVRegDef(MI.getOperand(1).getReg());
if (DefMI->getOpcode() == TargetOpcode::G_TRUNC) {
+ unsigned DstReg = MI.getOperand(0).getReg();
+ LLT DstTy = MRI.getType(DstReg);
+ if (isInstUnsupported(TargetOpcode::G_AND, DstTy) ||
+ isInstUnsupported(TargetOpcode::G_CONSTANT, DstTy))
+ return false;
DEBUG(dbgs() << ".. Combine MI: " << MI;);
Builder.setInstr(MI);
- unsigned DstReg = MI.getOperand(0).getReg();
unsigned ZExtSrc = MI.getOperand(1).getReg();
LLT ZExtSrcTy = MRI.getType(ZExtSrc);
- LLT DstTy = MRI.getType(DstReg);
APInt Mask = APInt::getAllOnesValue(ZExtSrcTy.getSizeInBits());
auto MaskCstMIB = Builder.buildConstant(DstTy, Mask.getZExtValue());
unsigned TruncSrc = DefMI->getOperand(1).getReg();
@@ -79,10 +85,13 @@ public:
return false;
MachineInstr *DefMI = MRI.getVRegDef(MI.getOperand(1).getReg());
if (DefMI->getOpcode() == TargetOpcode::G_TRUNC) {
- DEBUG(dbgs() << ".. Combine MI: " << MI;);
- Builder.setInstr(MI);
unsigned DstReg = MI.getOperand(0).getReg();
LLT DstTy = MRI.getType(DstReg);
+ if (isInstUnsupported(TargetOpcode::G_SHL, DstTy) ||
+ isInstUnsupported(TargetOpcode::G_ASHR, DstTy))
+ return false;
+ DEBUG(dbgs() << ".. Combine MI: " << MI;);
+ Builder.setInstr(MI);
unsigned SExtSrc = MI.getOperand(1).getReg();
LLT SExtSrcTy = MRI.getType(SExtSrc);
unsigned SizeDiff = DstTy.getSizeInBits() - SExtSrcTy.getSizeInBits();
@@ -202,6 +211,13 @@ private:
if (MRI.hasOneUse(DefMI.getOperand(0).getReg()))
DeadInsts.push_back(&DefMI);
}
+ /// Checks if the target legalizer info has specified anything about the
+ /// instruction, or if unsupported.
+ bool isInstUnsupported(unsigned Opcode, const LLT &DstTy) const {
+ auto Action = LI.getAction({Opcode, 0, DstTy});
+ return Action.first == LegalizerInfo::LegalizeAction::Unsupported ||
+ Action.first == LegalizerInfo::LegalizeAction::NotFound;
+ }
};
} // namespace llvm
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h?rev=316602&r1=316601&r2=316602&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h Wed Oct 25 11:49:18 2017
@@ -89,6 +89,9 @@ public:
/// functions
MachineIRBuilder MIRBuilder;
+ /// Expose LegalizerInfo so the clients can re-use.
+ const LegalizerInfo &getLegalizerInfo() const { return LI; }
+
private:
/// Helper function to split a wide generic register into bitwise blocks with
Modified: llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp?rev=316602&r1=316601&r2=316602&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/Legalizer.cpp Wed Oct 25 11:49:18 2017
@@ -97,7 +97,8 @@ bool Legalizer::runOnMachineFunction(Mac
}
});
WorkList.insert(&*MI);
- LegalizerCombiner C(Helper.MIRBuilder, MF.getRegInfo());
+ LegalizerCombiner C(Helper.MIRBuilder, MF.getRegInfo(),
+ Helper.getLegalizerInfo());
bool Changed = false;
LegalizerHelper::LegalizeResult Res;
do {
@@ -158,7 +159,7 @@ bool Legalizer::runOnMachineFunction(Mac
MachineRegisterInfo &MRI = MF.getRegInfo();
MachineIRBuilder MIRBuilder(MF);
- LegalizerCombiner C(MIRBuilder, MRI);
+ LegalizerCombiner C(MIRBuilder, MRI, Helper.getLegalizerInfo());
for (auto &MBB : MF) {
for (auto MI = MBB.begin(); MI != MBB.end(); MI = NextMI) {
// Get the next Instruction before we try to legalize, because there's a
More information about the llvm-commits
mailing list