Skip to content

Commit 9869470

Browse files
committed
fix a rare comparison problem with two immediates
1 parent 05a4bc8 commit 9869470

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

backends/asm/outasm.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,9 +2508,17 @@ CompileBasicBoolExpression(IRList *irl, AST *expr)
25082508
/* note that lhs cannot be a constant */
25092509
if (lhs && lhs->kind == IMM_INT) {
25102510
Operand *tmp = lhs;
2511-
lhs = rhs;
2512-
rhs = tmp;
2513-
cond = FlipSides(cond);
2511+
if (rhs && rhs->kind == IMM_INT) {
2512+
// we have to put lhs into a temp register
2513+
tmp = NewFunctionTempRegister();
2514+
EmitMove(irl, tmp, lhs, expr);
2515+
lhs = tmp;
2516+
} else {
2517+
// flip left and right to save a move
2518+
lhs = rhs;
2519+
rhs = tmp;
2520+
cond = FlipSides(cond);
2521+
}
25142522
}
25152523
// If comparing with constant, try for a condition that only uses C
25162524
// but only if it's correct and it won't horribly pessimize everything

0 commit comments

Comments
 (0)