Skip to content

Commit 2a46450

Browse files
committed
[AArch64][GlobalISel] Optimize conjunctions of compares to conditional 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
1 parent b09e63b commit 2a46450

File tree

3 files changed

+479
-194
lines changed

3 files changed

+479
-194
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CODEGEN_GLOBALISEL_GENERICMACHINEINSTRS_H
1515
#define LLVM_CODEGEN_GLOBALISEL_GENERICMACHINEINSTRS_H
1616

17+
#include "llvm/IR/Instructions.h"
1718
#include "llvm/CodeGen/MachineInstr.h"
1819
#include "llvm/CodeGen/MachineMemOperand.h"
1920
#include "llvm/CodeGen/TargetOpcodes.h"
@@ -226,6 +227,37 @@ class GSelect : public GenericMachineInstr {
226227
}
227228
};
228229

230+
/// Represent a G_ICMP or G_FCMP.
231+
class GAnyCmp : public GenericMachineInstr {
232+
public:
233+
CmpInst::Predicate getCond() const {
234+
return static_cast<CmpInst::Predicate>(getOperand(1).getPredicate());
235+
}
236+
Register getLHSReg() const { return getReg(2); }
237+
Register getRHSReg() const { return getReg(3); }
238+
239+
static bool classof(const MachineInstr *MI) {
240+
return MI->getOpcode() == TargetOpcode::G_ICMP ||
241+
MI->getOpcode() == TargetOpcode::G_FCMP;
242+
}
243+
};
244+
245+
/// Represent a G_ICMP.
246+
class GICmp : public GAnyCmp {
247+
public:
248+
static bool classof(const MachineInstr *MI) {
249+
return MI->getOpcode() == TargetOpcode::G_ICMP;
250+
}
251+
};
252+
253+
/// Represent a G_FCMP.
254+
class GFCmp : public GAnyCmp {
255+
public:
256+
static bool classof(const MachineInstr *MI) {
257+
return MI->getOpcode() == TargetOpcode::G_FCMP;
258+
}
259+
};
260+
229261
} // namespace llvm
230262

231263
#endif // LLVM_CODEGEN_GLOBALISEL_GENERICMACHINEINSTRS_H

0 commit comments

Comments
 (0)