[llvm] PatternMatch: migrate to CmpPredicate (PR #118534)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 14:36:54 PST 2024


================
@@ -3932,6 +3933,26 @@ std::optional<CmpPredicate> CmpPredicate::getMatching(CmpPredicate A,
   return {};
 }
 
+CmpPredicate CmpPredicate::get(const CmpInst *Cmp) {
+  return TypeSwitch<const CmpInst *, CmpPredicate>(Cmp)
+      .Case<ICmpInst>([](auto *ICI) { return ICI->getCmpPredicate(); })
+      .Case<FCmpInst>([](auto *FCI) { return FCI->getPredicate(); });
+}
+
+CmpPredicate CmpPredicate::getSwapped(CmpPredicate P) {
+  return CmpInst::isIntPredicate(P)
+             ? ICmpInst::getSwappedCmpPredicate(P)
+             : CmpPredicate{CmpInst::getSwappedPredicate(P)};
----------------
nikic wrote:

```suggestion
  return {CmpInst::getSwappedPredicate(P), P.SameSign};
```
Maybe? I don't think we need the branch here.

https://github.com/llvm/llvm-project/pull/118534


More information about the llvm-commits mailing list