Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Dec 15, 2025

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.

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.
@arsenm arsenm added the llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes label Dec 15, 2025 — with Graphite App
Copy link
Contributor Author

arsenm commented Dec 15, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm requested review from dtcxzyw and nikic December 15, 2025 16:09
@arsenm arsenm marked this pull request as ready for review December 15, 2025 16:09
@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/172327.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp (+7-4)
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.

Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an NFC. m_c_BinOp always succeeds when m_BinOp succeeds.

@arsenm arsenm merged commit 463c9f0 into main Dec 15, 2025
15 checks passed
@arsenm arsenm deleted the users/arsenm/instcombine/stop-using-m_c_BinOp-noncommutative-ops branch December 15, 2025 16:57
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Dec 19, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants