[InstCombine] Handle use count decrement in more cases
authorNikita Popov <npopov@redhat.com>
Wed, 14 Jun 2023 07:18:10 +0000 (09:18 +0200)
committerNikita Popov <npopov@redhat.com>
Wed, 14 Jun 2023 08:03:09 +0000 (10:03 +0200)
These two helpers also decrement the use count of the replaced
operand, so give them the same treatment as eraseInstruction().

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

index 21fbb11..5569bc9 100644 (file)
@@ -441,15 +441,17 @@ public:
 
   /// Replace operand of instruction and add old operand to the worklist.
   Instruction *replaceOperand(Instruction &I, unsigned OpNum, Value *V) {
-    Worklist.addValue(I.getOperand(OpNum));
+    Value *OldOp = I.getOperand(OpNum);
     I.setOperand(OpNum, V);
+    Worklist.handleUseCountDecrement(OldOp);
     return &I;
   }
 
   /// Replace use and add the previously used value to the worklist.
   void replaceUse(Use &U, Value *NewValue) {
-    Worklist.addValue(U);
+    Value *OldOp = U;
     U = NewValue;
+    Worklist.handleUseCountDecrement(OldOp);
   }
 
   /// Combiner aware instruction erasure.