From f3d8ebe827f9a9e224c18c37bfcbf6f4e89215a0 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 15 Dec 2025 17:05:40 +0100 Subject: [PATCH] InstCombine: Stop using m_c_BinOp for non-commutative ops The previous flow tried both m_BinOp and m_c_BinOp for noncommutative ops. Seems to have worked out OK though, since there are no test changes. --- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index c00551bc1f939..de7d9c8cde9ed 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -96,10 +96,13 @@ static Instruction *foldSelectBinOpIdentity(SelectInst &Sel, // Last, match the compare variable operand with a binop operand. Value *Y; - if (!BO->isCommutative() && !match(BO, m_BinOp(m_Value(Y), m_Specific(X)))) - return nullptr; - if (!match(BO, m_c_BinOp(m_Value(Y), m_Specific(X)))) - return nullptr; + if (BO->isCommutative()) { + if (!match(BO, m_c_BinOp(m_Value(Y), m_Specific(X)))) + return nullptr; + } else { + if (!match(BO, m_BinOp(m_Value(Y), m_Specific(X)))) + return nullptr; + } // +0.0 compares equal to -0.0, and so it does not behave as required for this // transform. Bail out if we can not exclude that possibility.