Skip to content

Commit

Permalink
[AArch64][GlobalISel] Optimize conjunctions of compares to conditiona…
Browse files Browse the repository at this point in the history
…l compares.

This is a partial port of the same optimization from AArch64ISelLowering,
although the original handles more cases when generating regular compares
instead of this one which just does it when selecting G_SELECTs.

For more detailed comments see the original comments for
emitConditionalComparison() in AArch64ISelLowering.

Gives minor code size improvements.

Differential Revision: https://reviews.llvm.org/D117166
  • Loading branch information
aemerson committed Feb 20, 2022
1 parent b09e63b commit 2a46450
Show file tree
Hide file tree
Showing 3 changed files with 479 additions and 194 deletions.
32 changes: 32 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/GenericMachineInstrs.h
Expand Up @@ -14,6 +14,7 @@
#ifndef LLVM_CODEGEN_GLOBALISEL_GENERICMACHINEINSTRS_H
#define LLVM_CODEGEN_GLOBALISEL_GENERICMACHINEINSTRS_H

#include "llvm/IR/Instructions.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/TargetOpcodes.h"
Expand Down Expand Up @@ -226,6 +227,37 @@ class GSelect : public GenericMachineInstr {
}
};

/// Represent a G_ICMP or G_FCMP.
class GAnyCmp : public GenericMachineInstr {
public:
CmpInst::Predicate getCond() const {
return static_cast<CmpInst::Predicate>(getOperand(1).getPredicate());
}
Register getLHSReg() const { return getReg(2); }
Register getRHSReg() const { return getReg(3); }

static bool classof(const MachineInstr *MI) {
return MI->getOpcode() == TargetOpcode::G_ICMP ||
MI->getOpcode() == TargetOpcode::G_FCMP;
}
};

/// Represent a G_ICMP.
class GICmp : public GAnyCmp {
public:
static bool classof(const MachineInstr *MI) {
return MI->getOpcode() == TargetOpcode::G_ICMP;
}
};

/// Represent a G_FCMP.
class GFCmp : public GAnyCmp {
public:
static bool classof(const MachineInstr *MI) {
return MI->getOpcode() == TargetOpcode::G_FCMP;
}
};

} // namespace llvm

#endif // LLVM_CODEGEN_GLOBALISEL_GENERICMACHINEINSTRS_H

0 comments on commit 2a46450

Please sign in to comment.