From fc857247e467ec8a66cdac7ef87a1688393588fb Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 14 Dec 2017 17:16:19 -0600 Subject: [PATCH] Fix overlaps_def for dead live ranges. A dead live range ends at the same point it is defined, but it is still considered to overlap a def at the same program point. --- lib/cretonne/src/regalloc/liverange.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cretonne/src/regalloc/liverange.rs b/lib/cretonne/src/regalloc/liverange.rs index 60079b3705..7d7d6a8775 100644 --- a/lib/cretonne/src/regalloc/liverange.rs +++ b/lib/cretonne/src/regalloc/liverange.rs @@ -407,6 +407,11 @@ impl GenLiveRange { ebb: Ebb, ctx: LiveRangeContext, ) -> bool { + // Two defs at the same program point always overlap, even if one is dead. + if def == self.def_begin.into() { + return true; + } + // Check for an overlap with the local range. if ctx.order.cmp(def, self.def_begin) != Ordering::Less && ctx.order.cmp(def, self.def_end) == Ordering::Less @@ -549,7 +554,9 @@ mod tests { #[test] fn dead_def_range() { let v0 = Value::new(0); + let e0 = Ebb::new(0); let i1 = Inst::new(1); + let i2 = Inst::new(2); let e2 = Ebb::new(2); let lr = GenLiveRange::new(v0, i1.into(), Default::default()); let forest = &bforest::MapForest::new(); @@ -560,6 +567,11 @@ mod tests { assert_eq!(lr.def_local_end(), i1.into()); assert_eq!(lr.livein_local_end(e2, ctx), None); PO.validate(&lr, ctx.forest); + + // A dead live range overlaps its own def program point. + assert!(lr.overlaps_def(i1.into(), e0, ctx)); + assert!(!lr.overlaps_def(i2.into(), e0, ctx)); + assert!(!lr.overlaps_def(e0.into(), e0, ctx)); } #[test]