Fix incorrect condition codes

This commit is contained in:
Dmitry Stogov 2022-08-02 13:04:03 +03:00
parent 6c78558bfe
commit 88b8731c16
7 changed files with 10 additions and 26 deletions

View File

@ -2465,11 +2465,7 @@ static void ir_emit_jcc(ir_ctx *ctx, uint8_t op, int b, ir_ref def, ir_insn *ins
if (true_block == next_block) {
if (int_cmp || (op != IR_GT && op != IR_GE)) {
/* swap to avoid unconditional JMP if this doesn't introduce additional JP instruction */
if (op < IR_LT) {
op ^= 1; // reverse
} else {
op ^= 3; // reverse
}
true_block = false_block;
false_block = 0;
}
@ -4175,11 +4171,7 @@ static void ir_emit_guard_cmp_int(ir_ctx *ctx, int b, ir_ref def, ir_insn *insn)
}
ir_emit_cmp_int_common(ctx, type, op1_reg, op1, op2_reg, op2);
if (op < IR_LT) {
op ^= 1; // reverse
} else {
op ^= 3; // reverse
}
ir_emit_guard_jcc(ctx, op, addr, 1);
}

View File

@ -3642,11 +3642,7 @@ static void ir_emit_jcc(ir_ctx *ctx, uint8_t op, int b, ir_ref def, ir_insn *ins
if (true_block == next_block) {
if (int_cmp || (op != IR_GT && op != IR_GE)) {
/* swap to avoid unconditional JMP if this doesn't introduce additional JP instruction */
if (op < IR_LT) {
op ^= 1; // reverse
} else {
op ^= 3; // reverse
}
true_block = false_block;
false_block = 0;
}
@ -5922,11 +5918,7 @@ static void ir_emit_guard_cmp_int(ir_ctx *ctx, int b, ir_ref def, ir_insn *insn)
}
ir_emit_cmp_int_common(ctx, type, cmp_insn, op1_reg, op1, op2_reg, op2);
if (op < IR_LT) {
op ^= 1; // reverse
} else {
op ^= 3; // reverse
}
ir_emit_guard_jcc(ctx, op, addr, 1);
}

View File

@ -50,11 +50,11 @@ test:
xorl %eax, %eax
.L1:
cmpl $0xa, %ecx
jg .L5
jge .L5
xorl %edx, %edx
.L2:
cmpl $0xa, %edx
jg .L4
jge .L4
cmpl %ecx, %edx
je .L3
leal 1(%rax), %eax

View File

@ -104,7 +104,7 @@ test:
retq
.L3:
cmpl $0x3e8, 0x2c(%rsp)
jl .L4
jle .L4
xorl %eax, %eax
addq $0x70, %rsp
retq

View File

@ -118,7 +118,7 @@ test:
ja .L2
movl (%rax), %ecx
cmpl $0x3e8, %ecx
jl .L1
jle .L1
xorl %eax, %eax
movq %rbp, %rsp
popq %rbp

View File

@ -126,7 +126,7 @@ test:
retq
.L3:
cmpl $0x3e8, 0x30(%rsp)
jl .L4
jle .L4
xorl %eax, %eax
addq $0x68, %rsp
retq

View File

@ -108,7 +108,7 @@ test:
ucomisd .L4(%rip), %xmm0
ja .L2
cmpl $0x3e8, 0x20(%rsp)
jl .L1
jle .L1
xorl %eax, %eax
addq $0x40, %rsp
retq