Skip to content

Commit bec4cb6

Browse files
committed
Eliminate redundant reevaluation in try_transform_expr_with_all_rounding_modes
1 parent c037f34 commit bec4cb6

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/analyses/variable-sensitivity/abstract_value_object.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,31 @@ class constants_evaluator
273273

274274
abstract_object_pointert try_transform_expr_with_all_rounding_modes() const
275275
{
276-
std::vector<abstract_object_pointert> possible_results;
276+
abstract_object_pointert last_result;
277+
278+
auto results_differ = [](
279+
const abstract_object_pointert &prev,
280+
const abstract_object_pointert &cur) {
281+
if(prev == nullptr)
282+
return false;
283+
return prev->to_constant() != cur->to_constant();
284+
};
285+
277286
for(auto rounding_mode : all_rounding_modes)
278287
{
279288
auto child_env(environment_with_rounding_mode(rounding_mode));
280289
auto child_operands =
281290
reeval_operands(expression.operands(), child_env, ns);
282291

283-
possible_results.push_back(
284-
constants_evaluator(expression, child_operands, child_env, ns)());
285-
}
292+
auto result =
293+
constants_evaluator(expression, child_operands, child_env, ns)();
286294

287-
auto first = possible_results.front()->to_constant();
288-
for(auto const &possible_result : possible_results)
289-
{
290-
auto current = possible_result->to_constant();
291-
if(current.is_nil() || current != first)
295+
if(result->is_top() || results_differ(last_result, result))
292296
return top(expression.type());
297+
last_result = result;
293298
}
294-
return possible_results.front();
299+
300+
return last_result;
295301
}
296302

297303
abstract_environmentt

0 commit comments

Comments
 (0)