[InstCombine] Fix worklist management in varargs transform
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 29 Mar 2020 15:38:23 +0000 (17:38 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 29 Mar 2020 16:04:12 +0000 (18:04 +0200)
Add a replaceUse() helper to mirror replaceOperand() for the
rare cases where we're working directly on uses.

NFC apart from worklist order changes.

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

index b28da94..d9e2c52 100644 (file)
@@ -4573,7 +4573,7 @@ Instruction *InstCombiner::visitCallBase(CallBase &Call) {
          I != E; ++I, ++ix) {
       CastInst *CI = dyn_cast<CastInst>(*I);
       if (CI && isSafeToEliminateVarargsCast(Call, DL, CI, ix)) {
-        *I = CI->getOperand(0);
+        replaceUse(*I, CI->getOperand(0));
 
         // Update the byval type to match the argument type.
         if (Call.isByValArgument(ix)) {
index d6053c2..f21c7d1 100644 (file)
@@ -686,6 +686,12 @@ public:
     return &I;
   }
 
+  /// Replace use and add the previously used value to the worklist.
+  void replaceUse(Use &U, Value *NewValue) {
+    Worklist.addValue(U);
+    U = NewValue;
+  }
+
   /// Creates a result tuple for an overflow intrinsic \p II with a given
   /// \p Result and a constant \p Overflow value.
   Instruction *CreateOverflowTuple(IntrinsicInst *II, Value *Result,
index e697b99..77a8410 100644 (file)
@@ -87,9 +87,7 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
   Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known,
                                           Depth, I);
   if (!NewVal) return false;
-  // Add the old operand back to the worklist.
-  Worklist.addValue(U.get());
-  U = NewVal;
+  replaceUse(U, NewVal);
   return true;
 }