[llvm] [InstCombine] Allow overflowing selects to work on commutative arguments (PR #90812)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 21:41:55 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))))
----------------
nikic wrote:
If you're using m_AddLike you also need to add tests for disjoint or. But THB I don't think using AddLike here makes sense.
https://github.com/llvm/llvm-project/pull/90812
More information about the llvm-commits
mailing list