aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-01-17 19:27:13 +0000
committergingerBill <bill@gingerbill.org>2018-01-17 19:27:13 +0000
commit876af6fb029c9f32d674e96b7a5ef263ba74bba5 (patch)
tree0a1bf003241cd7babf61e98aeb48debe07531869 /src/ir.cpp
parentb3734a5f771e46df1d8bde4a187fb8a4e93e6612 (diff)
Modify boolean conversion in IR
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index c151a52cf..8853a47e1 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -3023,8 +3023,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
}
// integer -> integer
- if ((is_type_integer(src) && is_type_integer(dst)) ||
- (is_type_boolean(src) && is_type_boolean(dst))) {
+ if (is_type_integer(src) && is_type_integer(dst)) {
GB_ASSERT(src->kind == Type_Basic &&
dst->kind == Type_Basic);
i64 sz = type_size_of(proc->module->allocator, default_type(src));
@@ -3048,6 +3047,16 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
return ir_emit(proc, ir_instr_conv(proc, kind, value, src_type, t));
}
+ // boolean -> boolean
+ if (is_type_boolean(src) && is_type_boolean(dst)) {
+ GB_ASSERT(src->kind == Type_Basic &&
+ dst->kind == Type_Basic);
+ GB_ASSERT(src != t_llvm_bool);
+
+ irValue *b = ir_emit(proc, ir_instr_binary_op(proc, Token_NotEq, value, v_zero, t_llvm_bool));
+ return ir_emit(proc, ir_instr_conv(proc, irConv_zext, b, t_llvm_bool, t));
+ }
+
// boolean -> integer
if (is_type_boolean(src) && is_type_integer(dst)) {