From af8dee3c213a5c7d5d84c9759eb3de2aad238673 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 26 May 2020 16:30:05 -0400 Subject: [PATCH 181/315] FIXME: simplify maybe_fold_binop --- gcc/analyzer/region-model2.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index 510a1d26394..b7efa94cf84 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -2960,6 +2960,13 @@ region_model2_manager::maybe_fold_binop (tree type, enum tree_code op, || (arg1->get_type () && FLOAT_TYPE_P (arg1->get_type ()))) return NULL; + /* For commutative ops, put any constant on the RHS. */ + if (cst0 && commutative_tree_code (op)) + { + std::swap (arg0, arg1); + std::swap (cst0, cst1); + } + switch (op) { default: @@ -2968,21 +2975,15 @@ region_model2_manager::maybe_fold_binop (tree type, enum tree_code op, /* (VAL + 0) -> VAL. */ if (cst1 && zerop (cst1) && type == arg0->get_type ()) return arg0; - /* (0 + VAL) -> VAL. */ - if (cst0 && zerop (cst0) && type == arg1->get_type ()) - return arg1; break; case MULT_EXPR: - /* (VAL * 0) or (0 * VAL) -> 0. */ - if ((cst1 && zerop (cst1)) || (cst0 && zerop (cst0))) + /* (VAL * 0). */ + if (cst1 && zerop (cst1)) // FIXME: check for integer type return get_or_create_constant_svalue2 (build_int_cst (type, 0)); /* (VAL * 1) -> VAL. */ - if (cst1 && integer_onep (cst1) && type == arg0->get_type ()) + if (cst1 && integer_onep (cst1)) return arg0; - /* (1 * VAL) -> VAL. */ - if (cst0 && integer_onep (cst0) && type == arg1->get_type ()) - return arg1; break; } return NULL; -- 2.26.2