When canonicalizing only erase the operation after calling the 'fold' hook if replacement results were supplied. This fixes a bug where the operation would always get erased, even if it was modified in place.

PiperOrigin-RevId: 232757964
diff --git a/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index 45c57e2..c2adf84 100644
--- a/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -267,9 +267,9 @@
             addToWorklist(operand.getOwner());
           res->replaceAllUsesWith(resultValues[i]);
         }
-      }
 
-      op->erase();
+        op->erase();
+      }
       continue;
     }