Skip to content

Commit 305fbc1

Browse files
Revert "[GlobalISel] LegalizationArtifactCombiner: Elide redundant G_AND"
This reverts commit 3686a0b. This seems to have broken some sanitizer tests: https://lab.llvm.org/buildbot/#/builders/184/builds/7721
1 parent b191ff0 commit 305fbc1

File tree

185 files changed

+12287
-11686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+12287
-11686
lines changed

llvm/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ class GISelKnownBitsAnalysis : public MachineFunctionPass {
118118
GISelKnownBitsAnalysis() : MachineFunctionPass(ID) {
119119
initializeGISelKnownBitsAnalysisPass(*PassRegistry::getPassRegistry());
120120
}
121-
GISelKnownBits &get(MachineFunction &MF);
121+
GISelKnownBits &get(MachineFunction &MF) {
122+
if (!Info)
123+
Info = std::make_unique<GISelKnownBits>(MF);
124+
return *Info.get();
125+
}
122126
void getAnalysisUsage(AnalysisUsage &AU) const override;
123127
bool runOnMachineFunction(MachineFunction &MF) override;
124128
void releaseMemory() override { Info.reset(); }

llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class LegalizationArtifactCombiner {
3535
MachineIRBuilder &Builder;
3636
MachineRegisterInfo &MRI;
3737
const LegalizerInfo &LI;
38-
GISelKnownBits *KB;
3938

4039
static bool isArtifactCast(unsigned Opc) {
4140
switch (Opc) {
@@ -51,9 +50,8 @@ class LegalizationArtifactCombiner {
5150

5251
public:
5352
LegalizationArtifactCombiner(MachineIRBuilder &B, MachineRegisterInfo &MRI,
54-
const LegalizerInfo &LI,
55-
GISelKnownBits *KB = nullptr)
56-
: Builder(B), MRI(MRI), LI(LI), KB(KB) {}
53+
const LegalizerInfo &LI)
54+
: Builder(B), MRI(MRI), LI(LI) {}
5755

5856
bool tryCombineAnyExt(MachineInstr &MI,
5957
SmallVectorImpl<MachineInstr *> &DeadInsts,
@@ -133,26 +131,13 @@ class LegalizationArtifactCombiner {
133131
LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
134132
LLT SrcTy = MRI.getType(SrcReg);
135133
APInt MaskVal = APInt::getAllOnes(SrcTy.getScalarSizeInBits());
134+
auto Mask = Builder.buildConstant(
135+
DstTy, MaskVal.zext(DstTy.getScalarSizeInBits()));
136136
if (SextSrc && (DstTy != MRI.getType(SextSrc)))
137137
SextSrc = Builder.buildSExtOrTrunc(DstTy, SextSrc).getReg(0);
138138
if (TruncSrc && (DstTy != MRI.getType(TruncSrc)))
139139
TruncSrc = Builder.buildAnyExtOrTrunc(DstTy, TruncSrc).getReg(0);
140-
APInt ExtMaskVal = MaskVal.zext(DstTy.getScalarSizeInBits());
141-
Register AndSrc = SextSrc ? SextSrc : TruncSrc;
142-
// Elide G_AND and mask constant if possible.
143-
// The G_AND would also be removed by the post-legalize redundant_and
144-
// combine, but in this very common case, eliding early and regardless of
145-
// OptLevel results in significant compile-time and O0 code-size
146-
// improvements. Inserting unnecessary instructions between a boolean def
147-
// and use can also hinder ISel to detect e.g. that reloading a flags
148-
// register is unnecessary.
149-
if (KB && (KB->getKnownZeroes(AndSrc) | ExtMaskVal).isAllOnes()) {
150-
replaceRegOrBuildCopy(DstReg, AndSrc, MRI, Builder, UpdatedDefs,
151-
Observer);
152-
} else {
153-
auto Mask = Builder.buildConstant(DstTy, ExtMaskVal);
154-
Builder.buildAnd(DstReg, AndSrc, Mask);
155-
}
140+
Builder.buildAnd(DstReg, SextSrc ? SextSrc : TruncSrc, Mask);
156141
markInstAndDefDead(MI, *MRI.getVRegDef(SrcReg), DeadInsts);
157142
return true;
158143
}

llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/CodeGen/TargetLowering.h"
2020
#include "llvm/CodeGen/TargetOpcodes.h"
2121
#include "llvm/IR/Module.h"
22-
#include "llvm/Target/TargetMachine.h"
2322

2423
#define DEBUG_TYPE "gisel-known-bits"
2524

@@ -774,12 +773,3 @@ void GISelKnownBitsAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
774773
bool GISelKnownBitsAnalysis::runOnMachineFunction(MachineFunction &MF) {
775774
return false;
776775
}
777-
778-
GISelKnownBits &GISelKnownBitsAnalysis::get(MachineFunction &MF) {
779-
if (!Info) {
780-
unsigned MaxDepth =
781-
MF.getTarget().getOptLevel() == CodeGenOptLevel::None ? 2 : 6;
782-
Info = std::make_unique<GISelKnownBits>(MF, MaxDepth);
783-
}
784-
return *Info.get();
785-
}

llvm/lib/CodeGen/GlobalISel/Legalizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Legalizer::legalizeMachineFunction(MachineFunction &MF, const LegalizerInfo &LI,
218218
// This will keep all the observers notified about new insertions/deletions.
219219
RAIIMFObsDelInstaller Installer(MF, WrapperObserver);
220220
LegalizerHelper Helper(MF, LI, WrapperObserver, MIRBuilder, KB);
221-
LegalizationArtifactCombiner ArtCombiner(MIRBuilder, MRI, LI, KB);
221+
LegalizationArtifactCombiner ArtCombiner(MIRBuilder, MRI, LI);
222222
bool Changed = false;
223223
SmallVector<MachineInstr *, 128> RetryList;
224224
do {

0 commit comments

Comments
 (0)