diff options
| author | gingerBill <bill@gingerbill.org> | 2021-03-29 23:15:31 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-03-29 23:15:31 +0100 |
| commit | 439e2c92426c59f84d51bfb594e9ac86d496c708 (patch) | |
| tree | 1c2095758e9b8ff910f030ec5a6bf2248c85049a /src/ir.cpp | |
| parent | 6fb086851782c23e0b6d1f5f708b1b1b4c3ef29d (diff) | |
Fix shifting limits and LLVM code gen bug relating to shifts
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 96595c38d..090967ad8 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4639,13 +4639,13 @@ handle_op: irValue *bits = right; - irValue *max = ir_value_constant(type, exact_value_i64(8*type_size_of(type))); - irValue *less_equal_width = ir_emit(proc, ir_instr_binary_op(proc, Token_Lt, bits, max, t_llvm_bool)); + irValue *bit_size = ir_value_constant(type, exact_value_i64(8*type_size_of(type))); + irValue *width_test = ir_emit(proc, ir_instr_binary_op(proc, Token_Lt, bits, bit_size, t_llvm_bool)); irValue *zero = ir_value_constant(type, exact_value_i64(0)); irValue *res = ir_emit(proc, ir_instr_binary_op(proc, op, left, bits, type)); - return ir_emit_select(proc, less_equal_width, res, zero); + return ir_emit_select(proc, width_test, res, zero); } case Token_Shr: { @@ -4655,10 +4655,11 @@ handle_op: irValue *bits = right; - irValue *max = ir_value_constant(type, exact_value_i64(8*type_size_of(type))); - irValue *less_equal_width = ir_emit(proc, ir_instr_binary_op(proc, Token_Lt, bits, max, t_llvm_bool)); + irValue *bit_size = ir_value_constant(type, exact_value_i64(8*type_size_of(type))); + irValue *max = ir_value_constant(type, exact_value_i64(8*type_size_of(type)-1)); + irValue *width_test = ir_emit(proc, ir_instr_binary_op(proc, Token_Lt, bits, bit_size, t_llvm_bool)); - bits = ir_emit_select(proc, less_equal_width, bits, max); + bits = ir_emit_select(proc, width_test, bits, max); return ir_emit(proc, ir_instr_binary_op(proc, op, left, bits, type)); } |