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

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 08:56:36 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:

I don't think the code is explicitly buggy now, but it seems like an accident waiting to happen. Although it won't be silent (a v explicit segfault), so guess there is no real alarm.

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


More information about the llvm-commits mailing list