[llvm] [InstCombine] Allow overflowing selects to work on commutative arguments (PR #90812)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 3 04:35: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)))) {
+ // Commutative 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_AddLike(m_Specific(Y), m_Specific(X))))
----------------
AtariDreams wrote:
It was a suggestion from another maintainer actually
https://github.com/llvm/llvm-project/pull/90812
More information about the llvm-commits
mailing list