From c52fa3e6e05b5aeec3fc5da55abfd1b326f549a0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 4 Jul 2023 12:15:38 +0300 Subject: [PATCH] Clenaup and new folding rules --- ir_fold.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/ir_fold.h b/ir_fold.h index 976e889..9f86fb6 100644 --- a/ir_fold.h +++ b/ir_fold.h @@ -479,10 +479,6 @@ IR_FOLD(ABS(C_FLOAT)) IR_FOLD_CONST_F(fabsf(op1_insn->val.f)); } - -//IR_FOLD(CAST(CONST)) -//TODO: type casting - IR_FOLD(ADD_OV(C_U8, C_U8)) IR_FOLD(ADD_OV(C_U16, C_U16)) IR_FOLD(ADD_OV(C_U32, C_U32)) @@ -1184,7 +1180,7 @@ IR_FOLD(COND(C_I64, _)) IR_FOLD(COND(C_DOUBLE, _)) IR_FOLD(COND(C_FLOAT, _)) { - if (op1_insn->val.u64) { // TODO: ??? + if (ir_const_is_true(op1_insn)) { IR_FOLD_COPY(op2); } else { IR_FOLD_COPY(op3); @@ -1201,7 +1197,6 @@ IR_FOLD(ABS(ABS)) IR_FOLD(ABS(NEG)) { /* abs(neg(y)) => abs(y) */ - // TODO: PHIBARIER ??? op1 = op1_insn->op1; IR_FOLD_RESTART; } @@ -1989,6 +1984,27 @@ IR_FOLD(XOR(XOR, C_I64)) IR_FOLD_NEXT; } +IR_FOLD(AND(AND, _)) +IR_FOLD(OR(OR, _)) +IR_FOLD(MIN(MIN, _)) +IR_FOLD(MAX(MAX, _)) +{ + if (op1_insn->op1 == op2 || op1_insn->op2 == op2) { + IR_FOLD_COPY(op2); + } + IR_FOLD_NEXT; +} + +IR_FOLD(XOR(XOR, _)) +{ + if (op1_insn->op1 == op2) { + IR_FOLD_COPY(op1_insn->op2); + } else if (op1_insn->op2 == op2) { + IR_FOLD_COPY(op1_insn->op1); + } + IR_FOLD_NEXT; +} + /* Swap operands (move lower ref to op2) for better CSE */ IR_FOLD(ADD(_, _)) IR_FOLD(MUL(_, _))