[llvm] [SelectOpt] Refactor to prepare for support more select-like operations (PR #115745)

Igor Kirillov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 04:22:13 PST 2024


================
@@ -227,72 +176,55 @@ class SelectOptimizeImpl {
         return Sel->getFalseValue();
       // Or(zext) case - return the operand which is not the zext.
       if (auto *BO = dyn_cast<BinaryOperator>(I)) {
-        Value *X;
-        if (PatternMatch::match(BO->getOperand(0),
-                                m_OneUse(m_ZExt(m_Value(X)))))
-          return BO->getOperand(1);
-        if (PatternMatch::match(BO->getOperand(1),
-                                m_OneUse(m_ZExt(m_Value(X)))))
-          return BO->getOperand(0);
+        // Return non-dependant on condition operand
----------------
igogo-x86 wrote:

BinaryOperator is select-like instruction where one operand depends on a condition, with the index of that operand being `CondIdx`. `non-dependant on condition operand` is the other operand. On the branch where the condition is 0, BinaryOperator doesn't do anything, so we can just return the other operand.

I feel like matching condition-depending operand with ZExt was not entirely correct - for example, what if both operands are ZExts? And late, after adding `LShr` and `AShr` support, it would get even messier.


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


More information about the llvm-commits mailing list