[mlir:DataFlowAnalysis] Reprocess the arguments of already executable edges
authorRiver Riddle <riddleriver@gmail.com>
Wed, 22 Sep 2021 20:07:05 +0000 (20:07 +0000)
committerRiver Riddle <riddleriver@gmail.com>
Wed, 22 Sep 2021 20:14:55 +0000 (20:14 +0000)
This fixes a bug where we discover new information about the arguments of an
already executable edge, but don't visit the arguments. We only visit the arguments, and not the block itself, so this commit shouldn't really affect performance at all.

Fixes PR#51871

Differential Revision: https://reviews.llvm.org/D110197

mlir/lib/Analysis/DataFlowAnalysis.cpp
mlir/test/Transforms/sccp.mlir

index b5a5e17fd2c354081b8a0a6b41b89ed9c8f707d7..b91d2de602fe79b137414df2921f9c417d5160ec 100644 (file)
@@ -722,8 +722,7 @@ bool ForwardDataFlowSolver::isBlockExecutable(Block *block) const {
 }
 
 void ForwardDataFlowSolver::markEdgeExecutable(Block *from, Block *to) {
-  if (!executableEdges.insert(std::make_pair(from, to)).second)
-    return;
+  executableEdges.insert(std::make_pair(from, to));
 
   // Mark the destination as executable, and reprocess its arguments if it was
   // already executable.
index 39d9acd7bf04236d708a0874b7b8fa8f5c96082d..29499f3bb173bb381cde105bc695e4f5c9de9a00 100644 (file)
@@ -178,3 +178,23 @@ func @simple_loop_overdefined(%arg0 : i32, %cond1 : i1) -> i32 {
 
   return %arg : i32
 }
+
+// Check that we reprocess executable edges when information changes.
+
+// CHECK-LABEL: func @recheck_executable_edge
+func @recheck_executable_edge(%cond0: i1) -> (i1, i1) {
+  %true = constant true
+  %false = constant false
+  cond_br %cond0, ^bb_1a, ^bb2(%false : i1)
+^bb_1a:
+  br ^bb2(%true : i1)
+
+^bb2(%x: i1):
+  // CHECK: ^bb2(%[[X:.*]]: i1):
+  br ^bb3(%x : i1)
+
+^bb3(%y: i1):
+  // CHECK: ^bb3(%[[Y:.*]]: i1):
+  // CHECK: return %[[X]], %[[Y]]
+  return %x, %y : i1, i1
+}