Lunderberg commented on code in PR #12266:
URL: https://github.com/apache/tvm/pull/12266#discussion_r938953546


##########
src/tir/transforms/remove_store_undef.cc:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file remove_store_undef.cc
+ * \brief Remove stores of tir::builtin::undef
+ */
+#include <tvm/runtime/registry.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/builtin.h>
+#include <tvm/tir/op.h>
+#include <tvm/tir/stmt.h>
+#include <tvm/tir/stmt_functor.h>
+#include <tvm/tir/transform.h>
+
+namespace tvm {
+namespace tir {
+
+class StoreUndefLocator : public StmtExprVisitor {
+ public:
+  static std::unordered_set<const BufferStoreNode*> Locate(Stmt stmt) {
+    StoreUndefLocator locator;
+    locator(std::move(stmt));
+    return locator.undef_stores_;
+  }
+
+ private:
+  StoreUndefLocator() = default;
+
+  void VisitStmt_(const BufferStoreNode* op) final {
+    bool stash_undef = false;
+    std::swap(has_undef_, stash_undef);
+    StmtExprVisitor::VisitExpr(op->value);

Review Comment:
   Good point.  I had avoided it to avoid re-walking the tree after looking for 
the `T.undef()`, but safety is the better option here.  Updated both here and 
in the `LetStmtNode` handler to verify that the expression has no other side 
effects.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to