Implemented const folding of ternary op with undef select
authorClifford Wolf <clifford@clifford.at>
Fri, 8 Nov 2013 03:44:09 +0000 (04:44 +0100)
committerClifford Wolf <clifford@clifford.at>
Fri, 8 Nov 2013 03:44:09 +0000 (04:44 +0100)
frontends/ast/simplify.cc

index 5c0130d4281071a951c615b0fbc636fda55c51e2..9fa7f558bae2f649c4ce42b6b36a67a69b7b6535 100644 (file)
@@ -1074,6 +1074,14 @@ skip_dynamic_range_lvalue_expansion:;
                                if (choice != NULL && choice->type == AST_CONSTANT) {
                                        RTLIL::Const y = choice->bitsAsConst(width_hint, sign_hint);
                                        newNode = mkconst_bits(y.bits, sign_hint);
+                               } else if (children[1]->type == AST_CONSTANT && children[2]->type == AST_CONSTANT) {
+                                       RTLIL::Const a = children[1]->bitsAsConst(width_hint, sign_hint);
+                                       RTLIL::Const b = children[2]->bitsAsConst(width_hint, sign_hint);
+                                       assert(a.bits.size() == b.bits.size());
+                                       for (size_t i = 0; i < a.bits.size(); i++)
+                                               if (a.bits[i] != b.bits[i])
+                                                       a.bits[i] = RTLIL::State::Sx;
+                                       newNode = mkconst_bits(a.bits, sign_hint);
                                }
                        }
                        break;