[InstCombine] Return instruction from replaceUse()
authorNikita Popov <npopov@redhat.com>
Tue, 14 Mar 2023 15:50:31 +0000 (16:50 +0100)
committerNikita Popov <npopov@redhat.com>
Tue, 14 Mar 2023 15:53:03 +0000 (16:53 +0100)
Same as with other replacement methods, it's generally necessary
to report a change on the instruction itself, e.g. by returning
it from the visit method (or possibly explicitly adding it to the
worklist).

Return Instruction * from replaceUse() to encourage the usual
"return replaceXYZ" pattern.

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

index a876385581e7274fd5d167d9277c7f49e3a7bce9..4236544d3ecc4a849fd7bb76eeddf3f8b394c7c8 100644 (file)
@@ -446,9 +446,10 @@ public:
   }
 
   /// Replace use and add the previously used value to the worklist.
-  void replaceUse(Use &U, Value *NewValue) {
+  Instruction *replaceUse(Use &U, Value *NewValue) {
     Worklist.addValue(U);
     U = NewValue;
+    return cast<Instruction>(U.getUser());
   }
 
   /// Combiner aware instruction erasure.
index 01249613d47a06259e92fdbe6b271ae132f33a43..94d3f99156852ecfe5505ddcf995349bc300fe8c 100644 (file)
@@ -2436,8 +2436,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
       assert(isa<AssumeInst>(Assume));
       if (isAssumeWithEmptyBundle(*cast<AssumeInst>(II)))
         return eraseInstFromFunction(CI);
-      replaceUse(II->getOperandUse(0), ConstantInt::getTrue(II->getContext()));
-      return nullptr;
+      return replaceUse(II->getOperandUse(0),
+                        ConstantInt::getTrue(II->getContext()));
     };
     // Remove an assume if it is followed by an identical assume.
     // TODO: Do we need this? Unless there are conflicting assumptions, the
@@ -2964,10 +2964,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     }
     // Can remove shuffle iff just shuffled elements, no repeats, undefs, or
     // other changes.
-    if (UsedIndices.all()) {
-      replaceUse(II->getOperandUse(ArgIdx), V);
-      return nullptr;
-    }
+    if (UsedIndices.all())
+      return replaceUse(II->getOperandUse(ArgIdx), V);
     break;
   }
   case Intrinsic::is_fpclass: {
index 1f2441bc9fcf9cb4c42661fde72c03a7f96d21db..fbaf798a0cea87dd09d00a40e060271c44f650c0 100644 (file)
@@ -1251,7 +1251,7 @@ static bool replaceInInstruction(Value *V, Value *Old, Value *New,
   bool Changed = false;
   for (Use &U : I->operands()) {
     if (U == Old) {
-      IC.replaceUse(U, New);
+      IC.addToWorklist(IC.replaceUse(U, New));
       Changed = true;
     } else {
       Changed |= replaceInInstruction(U, Old, New, IC, Depth + 1);