Skip to content

simplifier: eliminate casts from bool to number #4904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2019

Conversation

kroening
Copy link
Member

This usually enables subsequent simplification, e.g.,

((int)B) != 0

turns into

(B?1:0) != 0

and then into

B?1!=0:0!=0

and then into

B?true:false

which then turns into

B

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@kroening
Copy link
Member Author

This needs #4874.

@tautschnig tautschnig changed the title simplifier: eliminate casts from bool to number simplifier: eliminate casts from bool to number [depends-on: #4874] Jul 13, 2019
tautschnig added a commit that referenced this pull request Jul 14, 2019
Simplifier: new interface, final piece [blocks: #4904]
@kroening kroening force-pushed the simplify_cast_from_boolean branch from 872b51a to 26c1817 Compare July 15, 2019 09:22
Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but needs tests (ideally regression tests)

@tautschnig tautschnig changed the title simplifier: eliminate casts from bool to number [depends-on: #4874] simplifier: eliminate casts from bool to number Jul 15, 2019
@kroening kroening force-pushed the simplify_cast_from_boolean branch 3 times, most recently from fa90683 to dd57506 Compare July 21, 2019 11:59
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️
Passed Diffblue compatibility checks (cbmc commit: dd57506).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/119921169

@codecov-io
Copy link

codecov-io commented Jul 21, 2019

Codecov Report

Merging #4904 into develop will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4904      +/-   ##
===========================================
+ Coverage    69.26%   69.26%   +<.01%     
===========================================
  Files         1307     1307              
  Lines       108089   108125      +36     
===========================================
+ Hits         74868    74893      +25     
- Misses       33221    33232      +11
Impacted Files Coverage Δ
jbmc/unit/util/simplify_expr.cpp 100% <100%> (ø) ⬆️
src/util/simplify_expr.cpp 86.95% <100%> (-0.33%) ⬇️
unit/util/simplify_expr.cpp 100% <100%> (ø) ⬆️
src/util/simplify_expr_int.cpp 80.49% <0%> (-0.56%) ⬇️
src/solvers/smt2/smt2_conv.cpp 59.58% <0%> (-0.45%) ⬇️
src/util/fresh_symbol.cpp 100% <0%> (ø) ⬆️
src/goto-programs/show_symbol_table.cpp 90.66% <0%> (+0.06%) ⬆️
src/pointer-analysis/value_set_fi.cpp 59.29% <0%> (+0.87%) ⬆️
...olvers/strings/string_constraint_instantiation.cpp 93.4% <0%> (+3.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69a9528...ccfba0b. Read the comment docs.

@kroening kroening force-pushed the simplify_cast_from_boolean branch from dd57506 to dbffea7 Compare July 22, 2019 00:27
@kroening kroening assigned smowton and unassigned kroening Jul 22, 2019
@kroening
Copy link
Member Author

@smowton Now with the obvious unit test.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️
Passed Diffblue compatibility checks (cbmc commit: dbffea7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/119946294

symbol_tablet symbol_table;
namespacet ns(symbol_table);

// this checks that ((int)B)==1 turns into B
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding ==0, !=1, !=0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done

This usually enables subsequent simplification, e.g.,

((int)B) != 0

turns into

(B?1:0) != 0

and then into

B?1!=0:0!=0

and then into

B?true:false

which then turns into

B
@kroening kroening force-pushed the simplify_cast_from_boolean branch from dbffea7 to ccfba0b Compare July 24, 2019 09:37
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️
Passed Diffblue compatibility checks (cbmc commit: ccfba0b).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/120426225

@kroening kroening merged commit 24a3d2a into develop Jul 25, 2019
@kroening kroening deleted the simplify_cast_from_boolean branch July 25, 2019 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants