fortrangoingonforty/armfortas / e51d444

Browse files

Make o2_removes_dead_seed test unroll-tolerant: check store-of-const-zero pattern

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e51d4449747d592c9c2bce9d14139d830756b5de
Parents
8f2a8dd
Tree
cf30195

1 changed file

StatusFile+-
M tests/gvn_dse_audit_29_11.rs 37 3
tests/gvn_dse_audit_29_11.rsmodified
@@ -213,9 +213,43 @@ fn o2_removes_dead_seed_store_across_noalias_call() {
213213
         "raw loop body should still contain the seed store and the real fill store:\n{}",
214214
         raw_body
215215
     );
216
+    // Detect "seed-zero" pattern: a store whose value is a `const_int 0`.
217
+    // This invariant is robust to loop transformations like partial
218
+    // unrolling that multiply store counts — DSE removing the dead
219
+    // seed eliminates the const-zero feeding any store.
220
+    fn count_store_of_zero(func_section: &str) -> usize {
221
+        use std::collections::HashSet;
222
+        // Collect every value id defined as `const_int 0`.
223
+        let zeros: HashSet<&str> = func_section
224
+            .lines()
225
+            .filter_map(|l| {
226
+                let t = l.trim();
227
+                let after_eq = t.strip_prefix("%")?;
228
+                let (id, rest) = after_eq.split_once(" = const_int 0 ")?;
229
+                let _ = rest;
230
+                Some(id)
231
+            })
232
+            .collect();
233
+        // Count `store %ID, ...` where %ID is one of those.
234
+        func_section
235
+            .lines()
236
+            .filter_map(|l| l.trim().strip_prefix("store %"))
237
+            .filter(|rest| {
238
+                let id = rest.split(',').next().unwrap_or("").trim();
239
+                zeros.contains(id)
240
+            })
241
+            .count()
242
+    }
243
+    let raw_zeros = count_store_of_zero(raw_fill);
244
+    let opt_zeros = count_store_of_zero(opt_fill);
216245
     assert!(
217
-        opt_body.matches("store ").count() < raw_body.matches("store ").count(),
218
-        "O2 should remove the dead seed store while keeping the real fill:\n{}",
219
-        opt_body
246
+        raw_zeros >= 1,
247
+        "raw seed_and_fill should have at least one store-of-zero (the dead seed):\n{}",
248
+        raw_fill
249
+    );
250
+    assert_eq!(
251
+        opt_zeros, 0,
252
+        "O2 DSE should remove the dead store-of-zero (raw had {}):\n{}",
253
+        raw_zeros, opt_fill
220254
     );
221255
 }