| ... | ... | @@ -7349,6 +7349,39 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 7349 | 7349 | return ira->codegen->builtin_types.entry_bool; |
| 7350 | 7350 | } |
| 7351 | 7351 | |
| 7352 | // some comparisons with unsigned numbers can be evaluated |
| 7353 | if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) { |
| 7354 | ConstExprValue *known_left_val; |
| 7355 | IrBinOp flipped_op_id; |
| 7356 | if (value_is_comptime(op1_val)) { |
| 7357 | known_left_val = op1_val; |
| 7358 | flipped_op_id = op_id; |
| 7359 | } else if (value_is_comptime(op2_val)) { |
| 7360 | known_left_val = op2_val; |
| 7361 | if (op_id == IrBinOpCmpLessThan) { |
| 7362 | flipped_op_id = IrBinOpCmpGreaterThan; |
| 7363 | } else if (op_id == IrBinOpCmpGreaterThan) { |
| 7364 | flipped_op_id = IrBinOpCmpLessThan; |
| 7365 | } else if (op_id == IrBinOpCmpLessOrEq) { |
| 7366 | flipped_op_id = IrBinOpCmpGreaterOrEq; |
| 7367 | } else if (op_id == IrBinOpCmpGreaterOrEq) { |
| 7368 | flipped_op_id = IrBinOpCmpLessOrEq; |
| 7369 | } else { |
| 7370 | flipped_op_id = op_id; |
| 7371 | } |
| 7372 | } else { |
| 7373 | known_left_val = nullptr; |
| 7374 | } |
| 7375 | if (known_left_val != nullptr && known_left_val->data.x_bignum.data.x_uint == 0 && |
| 7376 | (flipped_op_id == IrBinOpCmpLessOrEq || flipped_op_id == IrBinOpCmpGreaterThan)) |
| 7377 | { |
| 7378 | bool answer = (flipped_op_id == IrBinOpCmpLessOrEq); |
| 7379 | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 7380 | out_val->data.x_bool = answer; |
| 7381 | return ira->codegen->builtin_types.entry_bool; |
| 7382 | } |
| 7383 | } |
| 7384 | |
| 7352 | 7385 | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 7353 | 7386 | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 7354 | 7387 | |