[llvm] [InstCombine] Invalidate changes to `DoesConsume` if the first try fails (PR #82973)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 26 09:51:06 PST 2024


================
@@ -2307,9 +2309,11 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses,
   // If `V` is of the form `A ^ ~B` then `~(A ^ ~B)` can be folded
   // into `A ^ B` if we are willing to invert all of the uses.
   if (match(V, m_Xor(m_Value(A), m_Value(B)))) {
+    bool DoesConsumeOldValue = DoesConsume;
     if (auto *BV = getFreelyInvertedImpl(B, B->hasOneUse(), Builder,
                                          DoesConsume, Depth))
       return Builder ? Builder->CreateXor(A, BV) : NonNull;
+    DoesConsume = DoesConsumeOldValue;
     if (auto *AV = getFreelyInvertedImpl(A, A->hasOneUse(), Builder,
                                          DoesConsume, Depth))
       return Builder ? Builder->CreateXor(AV, B) : NonNull;
----------------
goldsteinn wrote:

At the very least should add an assert that `NewIncomingVal != NonNull`

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


More information about the llvm-commits mailing list