[llvm] [GlobalIsel] Speedup select to integer min/max (PR #92378)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 06:45:55 PDT 2024
================
@@ -6775,62 +6772,46 @@ bool CombinerHelper::tryFoldSelectToIntMinMax(GSelect *Select,
if (CmpInst::isEquality(Pred))
return false;
- Register CmpLHS = Cmp->getLHSReg();
- Register CmpRHS = Cmp->getRHSReg();
-
- // We can swap CmpLHS and CmpRHS for higher hitrate.
- if (True == CmpRHS && False == CmpLHS) {
- std::swap(CmpLHS, CmpRHS);
- Pred = CmpInst::getSwappedPredicate(Pred);
- }
+ [[maybe_unused]] Register CmpLHS = Cmp->getLHSReg();
+ [[maybe_unused]] Register CmpRHS = Cmp->getRHSReg();
// (icmp X, Y) ? X : Y -> integer minmax.
// see matchSelectPattern in ValueTracking.
// Legality between G_SELECT and integer minmax can differ.
- if (True == CmpLHS && False == CmpRHS) {
- switch (Pred) {
- case ICmpInst::ICMP_UGT:
- case ICmpInst::ICMP_UGE: {
- if (!isLegalOrBeforeLegalizer({TargetOpcode::G_UMAX, DstTy}))
- return false;
- MatchInfo = [=](MachineIRBuilder &B) {
- B.buildUMax(DstReg, True, False);
- };
- return true;
- }
- case ICmpInst::ICMP_SGT:
- case ICmpInst::ICMP_SGE: {
- if (!isLegalOrBeforeLegalizer({TargetOpcode::G_SMAX, DstTy}))
- return false;
- MatchInfo = [=](MachineIRBuilder &B) {
- B.buildSMax(DstReg, True, False);
- };
- return true;
- }
- case ICmpInst::ICMP_ULT:
- case ICmpInst::ICMP_ULE: {
- if (!isLegalOrBeforeLegalizer({TargetOpcode::G_UMIN, DstTy}))
- return false;
- MatchInfo = [=](MachineIRBuilder &B) {
- B.buildUMin(DstReg, True, False);
- };
- return true;
- }
- case ICmpInst::ICMP_SLT:
- case ICmpInst::ICMP_SLE: {
- if (!isLegalOrBeforeLegalizer({TargetOpcode::G_SMIN, DstTy}))
- return false;
- MatchInfo = [=](MachineIRBuilder &B) {
- B.buildSMin(DstReg, True, False);
- };
- return true;
- }
- default:
+ assert(True == CmpLHS && False == CmpRHS && "unexpected MIR pattern");
+
+ switch (Pred) {
+ case ICmpInst::ICMP_UGT:
+ case ICmpInst::ICMP_UGE: {
+ if (!isLegalOrBeforeLegalizer({TargetOpcode::G_UMAX, DstTy}))
return false;
- }
+ MatchInfo = [=](MachineIRBuilder &B) { B.buildUMax(DstReg, True, False); };
----------------
tschuett wrote:
I would still need to pass `DstReg`, `True`, and `False`. I really like this lambda pattern with capture rules.
https://github.com/llvm/llvm-project/pull/92378
More information about the llvm-commits
mailing list