Skip to content

simplify i1 comparisons against boolean constants (#1417)#2548

Open
shema-boris wants to merge 5 commits into
EnzymeAD:mainfrom
shema-boris:fix-compare-bool-const
Open

simplify i1 comparisons against boolean constants (#1417)#2548
shema-boris wants to merge 5 commits into
EnzymeAD:mainfrom
shema-boris:fix-compare-bool-const

Conversation

@shema-boris

Copy link
Copy Markdown

Summary

Adds a CompareBoolConst simplification to --enzyme-hlo-opt so that
comparisons of an i1 (boolean) tensor against a boolean constant are folded
away. Fixes #1417 .

Problem

For boolean tensors, enzyme-hlo-opt left redundant comparisons in the IR. The
motivating case from the issue:

%lt = stablehlo.compare LT, %arg0, %cst, FLOAT : (...) -> tensor<...xi1>
%r  = stablehlo.compare NE, %lt, %false, UNSIGNED : (...) -> tensor<...xi1>

@wsmoses wsmoses left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good, can you also add it to the transform dialect registration [see the dev docs for info]?

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 28.62%. Comparing base (689f721) to head (d3bcb4e).
⚠️ Report is 45 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2548      +/-   ##
==========================================
+ Coverage   25.67%   28.62%   +2.95%     
==========================================
  Files         221      225       +4     
  Lines       44799    44316     -483     
==========================================
+ Hits        11502    12686    +1184     
+ Misses      33297    31630    -1667     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shema-boris

Copy link
Copy Markdown
Author

@wsmoses , I added it!!

@wsmoses

wsmoses commented Jun 12, 2026

Copy link
Copy Markdown
Member

clang-format ci fails

@shema-boris

Copy link
Copy Markdown
Author

I can work on that as well, let me run the clang-format on fomatted lines and push a fix shortly

@shema-boris

Copy link
Copy Markdown
Author

@wsmoses Clang-Format was successful

@wsmoses wsmoses left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sorry one more thing:

can you add the newly added pattern to:

list.push_back("compare_op_canon<16>");

also compare_ext is missing, we should add that there too

@shema-boris

Copy link
Copy Markdown
Author

Registered both of them.

@shema-boris

Copy link
Copy Markdown
Author

@wsmoses Is there anything else I should do? I have added all the patterns to EnzymeXLA.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

x != false and others

2 participants