[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:45:49 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
----------------
nikic wrote:
I don't think the commutativity is really the key point here? Doesn't this issue exist regardless of whether the add uses x+y or y+x? It's just that the add is done separately instead of using the intrinsic result. So you should be using m_c_Add below, as the first version of your patch did, and test the add with both operand orders.
https://github.com/llvm/llvm-project/pull/90812
More information about the llvm-commits
mailing list