[llvm] [RISCV][GISel] Select G_SELECT (G_ICMP, A, B) (PR #68247)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 18:32:25 PDT 2023
================
@@ -376,6 +391,120 @@ bool RISCVInstructionSelector::selectSExtInreg(MachineInstr &MI,
return true;
}
+/// Returns the RISCVCC::CondCode that corresponds to the CmpInst::Predicate CC.
+/// CC Must be an ICMP Predicate.
+static RISCVCC::CondCode getRISCVCCFromICMP(CmpInst::Predicate CC) {
+ switch (CC) {
+ default:
+ llvm_unreachable("Expected ICMP CmpInst::Predicate.");
+ case CmpInst::Predicate::ICMP_EQ:
+ return RISCVCC::COND_EQ;
+ case CmpInst::Predicate::ICMP_NE:
+ return RISCVCC::COND_NE;
+ case CmpInst::Predicate::ICMP_ULT:
+ return RISCVCC::COND_LTU;
+ case CmpInst::Predicate::ICMP_SLT:
+ return RISCVCC::COND_LT;
+ case CmpInst::Predicate::ICMP_UGE:
+ return RISCVCC::COND_GEU;
+ case CmpInst::Predicate::ICMP_SGE:
+ return RISCVCC::COND_GE;
+ }
+}
+
+void RISCVInstructionSelector::getICMPOperandsForBranch(
+ MachineInstr &MI, MachineIRBuilder &MIB, MachineRegisterInfo &MRI,
+ RISCVCC::CondCode &CC, Register &LHS, Register &RHS) const {
+ assert(MI.getOpcode() == TargetOpcode::G_ICMP);
+ CmpInst::Predicate ICMPCC =
+ static_cast<CmpInst::Predicate>(MI.getOperand(1).getPredicate());
+ LHS = MI.getOperand(2).getReg();
+ RHS = MI.getOperand(3).getReg();
+
+ // Adjust comparisons to use comparison with 0 if possible.
+ MachineInstr *MaybeConstant = MRI.getVRegDef(RHS);
+ if (MaybeConstant && MaybeConstant->getOpcode() == TargetOpcode::G_CONSTANT) {
----------------
michaelmaitland wrote:
Did we come to agreement on whether to use look through or not?
https://github.com/llvm/llvm-project/pull/68247
More information about the llvm-commits
mailing list