[llvm] [GlobalIsel] Speedup select to integer min/max (PR #92378)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 07:01:09 PDT 2024
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/92378 at github.com>
================
@@ -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); };
----------------
Pierre-vh wrote:
> e.g. allowing the user to write their own combined "match+apply" function in the first place.
Can you open an issue to track this idea? I'm not sure I like it yet, i'd need to think about how the TableGen would look.
https://github.com/llvm/llvm-project/pull/92378
More information about the llvm-commits
mailing list