From c2794b62a92f6805723ee1b5bed1622858671478 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 2 Mar 2021 16:48:39 +0000 Subject: [PATCH] Clean up logic for `<<` and `>>` behaviour --- src/ir.cpp | 8 ++++---- src/llvm_backend.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index c54e91f17..810621d67 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4630,8 +4630,8 @@ handle_op: irValue *bits = right; - irValue *max = ir_value_constant(type, exact_value_i64(8*type_size_of(type) - 1)); - irValue *less_equal_width = ir_emit(proc, ir_instr_binary_op(proc, Token_LtEq, bits, max, t_llvm_bool)); + 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 *zero = ir_value_constant(type, exact_value_i64(0)); @@ -4646,8 +4646,8 @@ handle_op: irValue *bits = right; - irValue *max = ir_value_constant(type, exact_value_i64(8*type_size_of(type) - 1)); - irValue *less_equal_width = ir_emit(proc, ir_instr_binary_op(proc, Token_LtEq, bits, max, t_llvm_bool)); + 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)); bits = ir_emit_select(proc, less_equal_width, bits, max); return ir_emit(proc, ir_instr_binary_op(proc, op, left, bits, type)); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 0f34f42b0..3c87293c2 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -5826,9 +5826,9 @@ handle_op: LLVMValueRef lhsval = lhs.value; LLVMValueRef bits = rhs.value; - LLVMValueRef max = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type) - 1, false); + LLVMValueRef max = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type), false); - LLVMValueRef less_equal_width = LLVMBuildICmp(p->builder, LLVMIntULE, bits, max, ""); + LLVMValueRef less_equal_width = LLVMBuildICmp(p->builder, LLVMIntULT, bits, max, ""); res.value = LLVMBuildShl(p->builder, lhsval, bits, ""); LLVMValueRef zero = LLVMConstNull(lb_type(p->module, lhs.type)); @@ -5842,9 +5842,9 @@ handle_op: LLVMValueRef bits = rhs.value; bool is_unsigned = is_type_unsigned(type); - LLVMValueRef max = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type) - 1, false); + LLVMValueRef max = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type), false); - LLVMValueRef less_equal_width = LLVMBuildICmp(p->builder, LLVMIntULE, bits, max, ""); + LLVMValueRef less_equal_width = LLVMBuildICmp(p->builder, LLVMIntULT, bits, max, ""); bits = LLVMBuildSelect(p->builder, less_equal_width, bits, max, ""); if (is_unsigned) {