From 49adc5e89ca63f16ff62b92a605e9358ae4a883d Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 5 Dec 2007 17:16:37 +0000 Subject: [PATCH] constant folding for && and || [r18614] --- ast2firm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ast2firm.c b/ast2firm.c index 23bb4ca..f3b7be6 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -1267,6 +1267,19 @@ static ir_node *create_lazy_op(const binary_expression_t *expression) type_t *type = expression->expression.datatype; ir_mode *mode = get_ir_mode(type); + if(is_constant_expression(expression->left)) { + long val = fold_constant(expression->left); + expression_type_t etype = expression->expression.type; + if((etype == EXPR_BINARY_LOGICAL_AND && val != 0) + || (etype == EXPR_BINARY_LOGICAL_OR && val == 0)) { + return expression_to_firm(expression->right); + } else { + assert((etype == EXPR_BINARY_LOGICAL_AND && val == 0) + || (etype == EXPR_BINARY_LOGICAL_OR && val != 0)); + return new_Const(mode, get_mode_one(mode)); + } + } + ir_node *cur_block = get_cur_block(); ir_node *one_block = new_immBlock(); -- 2.20.1