diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs
index 3a675752fba91..af9514ed6bb5b 100644
--- a/compiler/rustc_mir_transform/src/ssa.rs
+++ b/compiler/rustc_mir_transform/src/ssa.rs
@@ -78,14 +78,10 @@ impl SsaLocals {
             visitor.assignments[local] = Set1::One(LocationExtended::Arg);
         }
 
-        if body.basic_blocks.len() > 2 {
-            for (bb, data) in traversal::reverse_postorder(body) {
-                visitor.visit_basic_block_data(bb, data);
-            }
-        } else {
-            for (bb, data) in body.basic_blocks.iter_enumerated() {
-                visitor.visit_basic_block_data(bb, data);
-            }
+        // For SSA assignments, a RPO visit will see the assignment before it sees any use.
+        // We only visit reachable nodes: computing `dominates` on an unreachable node ICEs.
+        for (bb, data) in traversal::reverse_postorder(body) {
+            visitor.visit_basic_block_data(bb, data);
         }
 
         for var_debug_info in &body.var_debug_info {
diff --git a/tests/mir-opt/ssa_unreachable_116212.rs b/tests/mir-opt/ssa_unreachable_116212.rs
new file mode 100644
index 0000000000000..f588665876c87
--- /dev/null
+++ b/tests/mir-opt/ssa_unreachable_116212.rs
@@ -0,0 +1,14 @@
+// Regression test for issue #116212.
+
+#![feature(never_type)]
+
+use std::mem::MaybeUninit;
+
+struct Foo {
+    x: u8,
+    y: !,
+}
+
+fn main() {
+    let foo = unsafe { MaybeUninit::<Foo>::uninit().assume_init() };
+}