Skip to content

Commit 76f482c

Browse files
committed
Emit assume(false) as store i1 true, ptr poison, align 1
Store to poison is the canonical form for non-terminator unreachable.
1 parent d9284af commit 76f482c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,20 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
566566
}
567567

568568
fn assume(&mut self, val: Self::Value) {
569-
self.call_intrinsic("llvm.assume", &[val]);
569+
match self.const_to_opt_uint(val) {
570+
Some(0) => {
571+
// See https://github.com/llvm/llvm-project/blob/1347b9a3aa671d610e812579ab5e5f05870586cf/llvm/docs/Frontend/PerformanceTips.rst?plain=1#L204-L211.
572+
self.store(
573+
self.const_bool(true),
574+
self.const_poison(self.type_ptr()),
575+
self.tcx().data_layout.i1_align.abi,
576+
);
577+
}
578+
Some(_) => {}
579+
None => {
580+
self.call_intrinsic("llvm.assume", &[val]);
581+
}
582+
}
570583
}
571584

572585
fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value {

0 commit comments

Comments
 (0)