[llvm] [SLP] Fix isCommutative to check uses of the original instruction instead of the converted instruction. (PR #143094)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 09:36:04 PDT 2025


================
@@ -536,14 +546,17 @@ static bool isCommutative(Instruction *I) {
                           Flag->isOne());
                 })) ||
            (BO->getOpcode() == Instruction::FSub &&
-            !BO->hasNUsesOrMore(UsesLimit) &&
-            all_of(BO->uses(), [](const Use &U) {
+            !InstWithUses->hasNUsesOrMore(UsesLimit) &&
+            all_of(InstWithUses->uses(), [](const Use &U) {
               return match(U.getUser(),
                            m_Intrinsic<Intrinsic::fabs>(m_Specific(U.get())));
             }));
   return I->isCommutative();
 }
 
+/// This is a helper function to check whether \p I is commutative.
----------------
alexey-bataev wrote:

I would add a note, at least, that this function should be used only if the original instruction is checked, not the representation. Or used the original isCommutative for all cases to avoid potential bugs

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


More information about the llvm-commits mailing list