Skip to content

Commit 557736b

Browse files
committed
Update scalar pairs per review comments
1 parent e578976 commit 557736b

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/librustc_codegen_llvm/mir/operand.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::indexed_vec::Idx;
1818
use rustc_data_structures::sync::Lrc;
1919

2020
use base;
21-
use common::{self, CodegenCx, C_null, C_undef, C_usize};
21+
use common::{CodegenCx, C_null, C_undef, C_usize};
2222
use builder::{Builder, MemFlags};
2323
use value::Value;
2424
use type_of::LayoutLlvmExt;
@@ -310,10 +310,6 @@ impl<'a, 'tcx> OperandValue {
310310
OperandValue::Pair(a, b) => {
311311
for (i, &x) in [a, b].iter().enumerate() {
312312
let llptr = bx.struct_gep(dest.llval, i as u64);
313-
// Make sure to always store i1 as i8.
314-
if common::val_ty(x) == Type::i1(bx.cx) {
315-
assert_eq!(common::val_ty(llptr), Type::i8p(bx.cx));
316-
}
317313
let val = base::from_immediate(bx, x);
318314
bx.store_with_flags(val, llptr, dest.align, flags);
319315
}

src/librustc_codegen_llvm/mir/place.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::mir::tcx::PlaceTy;
1616
use rustc_data_structures::indexed_vec::Idx;
1717
use base;
1818
use builder::Builder;
19-
use common::{CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big, val_ty};
19+
use common::{CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big};
2020
use consts;
2121
use type_of::LayoutLlvmExt;
2222
use type_::Type;
@@ -128,10 +128,6 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
128128
} else if let layout::Abi::ScalarPair(ref a, ref b) = self.layout.abi {
129129
let load = |i, scalar: &layout::Scalar| {
130130
let llptr = bx.struct_gep(self.llval, i as u64);
131-
// Make sure to always load i1 as i8.
132-
if scalar.is_bool() {
133-
assert_eq!(val_ty(llptr), Type::i8p(bx.cx));
134-
}
135131
let load = bx.load(llptr, self.align);
136132
scalar_load_metadata(load, scalar);
137133
if scalar.is_bool() {

src/librustc_codegen_llvm/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
363363

364364
// Make sure to return the same type `immediate_llvm_type` would when
365365
// dealing with an immediate pair. This means that `(bool, bool)` is
366-
// effectively represented as `{i8, i8}` in memory and `{i1, i1}` as an
366+
// effectively represented as `{i8, i8}` in memory and two `i1`s as an
367367
// immediate, just like `bool` is typically `i8` in memory and only `i1`
368368
// when immediate. We need to load/store `bool` as `i8` to avoid
369369
// crippling LLVM optimizations or triggering other LLVM bugs with `i1`.

src/test/codegen/scalar-pair-bool.rs

+14
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@ pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
3838
// CHECK: or i1 %arg0.0, %arg0.1
3939
(a && b, a || b)
4040
}
41+
42+
// CHECK: define void @pair_branches(i1 zeroext %arg0.0, i1 zeroext %arg0.1)
43+
#[no_mangle]
44+
pub fn pair_branches((a, b): (bool, bool)) {
45+
// Make sure it can branch directly on the unpacked bool args
46+
// CHECK: br i1 %arg0.0
47+
if a {
48+
println!("Hello!");
49+
}
50+
// CHECK: br i1 %arg0.1
51+
if b {
52+
println!("Goodbye!");
53+
}
54+
}

0 commit comments

Comments
 (0)