Skip to content

Commit 8a5ff54

Browse files
committed
Tell LLVM about a hole in niche_variants range
This should help with get discr codegen in cases where untagged_variant is not 0.
1 parent be76b42 commit 8a5ff54

File tree

1 file changed

+8
-7
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+8
-7
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,14 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
290290
bx.unchecked_uadd(tag, diff)
291291
}
292292
};
293-
294-
let niche_discr = bx.sub(tag, diff);
295-
let discr = bx.select(
296-
is_untagged,
297-
bx.cx().const_uint(niche_llty, untagged_variant.as_u32() as u64),
298-
niche_discr,
299-
);
293+
let untagged_discr =
294+
bx.cx().const_uint(niche_llty, untagged_variant.as_u32() as u64);
295+
if untagged_variant >= *niche_variants.start() {
296+
let tagged_never_untagged =
297+
bx.icmp(IntPredicate::IntNE, untagged_discr, niche_discr);
298+
bx.assume(tagged_never_untagged);
299+
}
300+
let discr = bx.select(is_untagged, untagged_discr, niche_discr);
300301

301302
bx.intcast(discr, cast_to, false)
302303
}

0 commit comments

Comments
 (0)