| 3033 | } |
| 3034 | |
| 3035 | std::optional<bool> GetBoolConstantKind(const analysis::Constant* c) { |
| 3036 | if (!c) { |
| 3037 | return {}; |
| 3038 | } |
| 3039 | if (auto composite = c->AsCompositeConstant()) { |
| 3040 | auto& components = composite->GetComponents(); |
| 3041 | if (components.empty()) { |
| 3042 | return {}; |
| 3043 | } |
| 3044 | auto first = GetBoolConstantKind(components[0]); |
| 3045 | if (!first) { |
| 3046 | return {}; |
| 3047 | } |
| 3048 | if (std::all_of(std::begin(components) + 1, std::end(components), |
| 3049 | [first](const analysis::Constant* c2) { |
| 3050 | return GetBoolConstantKind(c2) == first; |
| 3051 | })) { |
| 3052 | return first; |
| 3053 | } |
| 3054 | return {}; |
| 3055 | } else if (c->AsNullConstant()) { |
| 3056 | return false; |
| 3057 | } else if (c->AsBoolConstant()) { |
| 3058 | return c->AsBoolConstant()->value(); |
| 3059 | } |
| 3060 | return {}; |
| 3061 | } |
| 3062 | |
| 3063 | // Fold OpSelect instructions which have constant booleans as their result. |
| 3064 | // x ? true : false = x |
no test coverage detected