Store scalar pair bools as i8 in memory
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.
So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory. When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type. Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
2018-06-15 22:47:54 +00:00
|
|
|
// compile-flags: -O
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
2022-02-05 06:00:37 +00:00
|
|
|
// CHECK: define{{.*}}{ i8, i8 } @pair_bool_bool(i1 noundef zeroext %pair.0, i1 noundef zeroext %pair.1)
|
Store scalar pair bools as i8 in memory
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.
So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory. When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type. Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
2018-06-15 22:47:54 +00:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn pair_bool_bool(pair: (bool, bool)) -> (bool, bool) {
|
|
|
|
pair
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:55:05 +00:00
|
|
|
// CHECK: define{{.*}}{ i8, i32 } @pair_bool_i32(i1 noundef zeroext %pair.0, i32 noundef %pair.1)
|
Store scalar pair bools as i8 in memory
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.
So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory. When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type. Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
2018-06-15 22:47:54 +00:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn pair_bool_i32(pair: (bool, i32)) -> (bool, i32) {
|
|
|
|
pair
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:55:05 +00:00
|
|
|
// CHECK: define{{.*}}{ i32, i8 } @pair_i32_bool(i32 noundef %pair.0, i1 noundef zeroext %pair.1)
|
Store scalar pair bools as i8 in memory
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.
So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory. When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type. Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
2018-06-15 22:47:54 +00:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
|
|
|
|
pair
|
|
|
|
}
|
|
|
|
|
2022-02-05 06:00:37 +00:00
|
|
|
// CHECK: define{{.*}}{ i8, i8 } @pair_and_or(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
|
Store scalar pair bools as i8 in memory
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.
So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory. When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type. Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
2018-06-15 22:47:54 +00:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
|
|
|
|
// Make sure it can operate directly on the unpacked args
|
2020-08-18 22:11:02 +00:00
|
|
|
// (but it might not be using simple and/or instructions)
|
|
|
|
// CHECK-DAG: %_1.0
|
|
|
|
// CHECK-DAG: %_1.1
|
Store scalar pair bools as i8 in memory
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.
So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory. When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type. Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
2018-06-15 22:47:54 +00:00
|
|
|
(a && b, a || b)
|
|
|
|
}
|
2018-07-05 21:22:09 +00:00
|
|
|
|
2022-02-05 06:00:37 +00:00
|
|
|
// CHECK: define{{.*}}void @pair_branches(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
|
2018-07-05 21:22:09 +00:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn pair_branches((a, b): (bool, bool)) {
|
|
|
|
// Make sure it can branch directly on the unpacked bool args
|
2019-09-13 16:25:05 +00:00
|
|
|
// CHECK: br i1 %_1.0
|
2018-07-05 21:22:09 +00:00
|
|
|
if a {
|
|
|
|
println!("Hello!");
|
|
|
|
}
|
2019-09-13 16:25:05 +00:00
|
|
|
// CHECK: br i1 %_1.1
|
2018-07-05 21:22:09 +00:00
|
|
|
if b {
|
|
|
|
println!("Goodbye!");
|
|
|
|
}
|
|
|
|
}
|