[llvm] [InstCombine] Allow overflowing selects to work on communative arguments (PR #90812)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 09:17:23 PDT 2024


================
@@ -2075,12 +2075,23 @@ foldOverflowingAddSubSelect(SelectInst &SI, InstCombiner::BuilderTy &Builder) {
   Value *FalseVal = SI.getFalseValue();
 
   WithOverflowInst *II;
-  if (!match(CondVal, m_ExtractValue<1>(m_WithOverflowInst(II))) ||
-      !match(FalseVal, m_ExtractValue<0>(m_Specific(II))))
+  if (!match(CondVal, m_ExtractValue<1>(m_WithOverflowInst(II))))
     return nullptr;
 
   Value *X = II->getLHS();
   Value *Y = II->getRHS();
+  if (!match(FalseVal, m_ExtractValue<0>(m_Specific(II)))) {
+    // Communinative adds can get missed, so check for X and Y being swapped
+    switch (II->getIntrinsicID()) {
+    case Intrinsic::uadd_with_overflow:
+    case Intrinsic::sadd_with_overflow:
+      if (!match(FalseVal, m_Add(m_Specific(Y), m_Specific(X))))
----------------
goldsteinn wrote:

m_AddLike

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


More information about the llvm-commits mailing list