[llvm] [GISel] Support narrowing G_ICMP with more than 2 parts. (PR #119335)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 15:39:16 PST 2024
================
@@ -1776,19 +1771,59 @@ LegalizerHelper::LegalizeResult LegalizerHelper::narrowScalar(MachineInstr &MI,
Or = MIRBuilder.buildOr(NarrowTy, Or, Xors[I]);
MIRBuilder.buildICmp(Pred, Dst, Or, Zero);
} else {
- // TODO: Handle non-power-of-two types.
- assert(LHSPartRegs.size() == 2 && "Expected exactly 2 LHS part regs?");
- assert(RHSPartRegs.size() == 2 && "Expected exactly 2 RHS part regs?");
- Register LHSL = LHSPartRegs[0];
- Register LHSH = LHSPartRegs[1];
- Register RHSL = RHSPartRegs[0];
- Register RHSH = RHSPartRegs[1];
- MachineInstrBuilder CmpH = MIRBuilder.buildICmp(Pred, ResTy, LHSH, RHSH);
- MachineInstrBuilder CmpHEQ =
- MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, ResTy, LHSH, RHSH);
- MachineInstrBuilder CmpLU = MIRBuilder.buildICmp(
- ICmpInst::getUnsignedPredicate(Pred), ResTy, LHSL, RHSL);
- MIRBuilder.buildSelect(Dst, CmpHEQ, CmpLU, CmpH);
+ Register CmpIn;
+ for (unsigned I = 0, E = LHSPartRegs.size(); I != E; ++I) {
+ Register CmpOut;
+ CmpInst::Predicate PartPred;
+
+ if (I == E - 1 && LHSLeftoverRegs.empty()) {
+ PartPred = Pred;
+ CmpOut = Dst;
+ } else {
+ PartPred = ICmpInst::getUnsignedPredicate(Pred);
+ CmpOut = MRI.createGenericVirtualRegister(ResTy);
+ }
+
----------------
arsenm wrote:
Maybe could preserve samesign for the high pieces but maybe it's not worth the effort
https://github.com/llvm/llvm-project/pull/119335
More information about the llvm-commits
mailing list