Description
EDIT: Take https://llvm.org/docs/Frontend/PerformanceTips.html#avoid-loads-and-stores-of-non-byte-sized-types into consideration
Is your refactor request related to a problem? Please describe.
PR #1039 attempted to avoid casting if the types do not differ, which resulted in some IR reduction for branching related stuff because booleans were no longer promoted to i8
e.g.
-%18 = zext i1 %tmpVar7 to i8
-%19 = icmp ne i8 %18, 0
-br label %20
+br label %8
However running with --verify
/ --ir
resulted in panics because of type-mismatches, e.g. here some struct Person is defined as %Person = type { [6 x i8], [6 x i8], i16, i8 }
for which the following initialization IR was generated
-@p = global %Person { [6 x i8] c"Jane\00\00", [6 x i8] c"Row\00\00\00", i16 1988, i8 0 }
+@p = global %Person { [6 x i8] c"Jane\00\00", [6 x i8] c"Row\00\00\00", i16 1988, i1 false }
As such to resolve #1037 a much simpler solution has been implemented without any IR reduction whatsoever.
Describe the solution you'd like
The IR reduction aspect is actually quite nice, so maybe if we further investigate a solution can be found to avoid casting booleans to i8
or keep them as i8
but with the same IR reduction?
Additional context
Booleans are by default i8
because of this commit which contains some more background information as to why
EDIT:
- This PR changed the IR for control statement conditions feat(validation): Assignment suggestions for
=
operator #1049, expanding it - This will result in IR reduction
macro_rules! cast_if_needed {
($generator:expr, $target_type:expr, $value_type:expr, $value:expr, $annotation:expr) => {
+ if $value_type == $target_type {
+ $value
+ } else {
crate::codegen::llvm_typesystem::cast(
$generator.llvm,
$generator.index,
$generator.llvm_index,
$target_type,
$value_type,
$value,
$annotation,
)
+ }
};
}