[llvm] [InstCombine] Teach foldSelectOpOp about samesign (PR #122723)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 09:43:42 PST 2025


================
@@ -428,10 +428,10 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
     CmpPredicate TPred, FPred;
     if (match(TI, m_ICmp(TPred, m_Value(), m_Value())) &&
         match(FI, m_ICmp(FPred, m_Value(), m_Value()))) {
-      // FIXME: Use CmpPredicate::getMatching here.
-      CmpInst::Predicate T = TPred, F = FPred;
-      if (T == F || T == ICmpInst::getSwappedCmpPredicate(F)) {
-        bool Swapped = T != F;
+      bool Swapped = ICmpInst::isRelational(FPred) &&
+                     CmpPredicate::getMatching(
+                         TPred, ICmpInst::getSwappedCmpPredicate(FPred));
+      if (CmpPredicate::getMatching(TPred, FPred) || Swapped) {
----------------
artagnon wrote:

Thanks a lot for the investigation and test case: I was sick over the last few days, and couldn't do it myself :(
Will post a re-land shortly.

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


More information about the llvm-commits mailing list