Skip to content

Commit

Permalink
[Comb] Fold mux if both arms are same constant
Browse files Browse the repository at this point in the history
If both arms of a `comb.mux` evaluate to the same constant, fold the mux
to that same constant. Right now this is only done if the SSA value is
identical. Some constant propagation algorithms will call `fold` to
propagate lattice constants, which isn't covered by just comparing SSA
values.

Short: also check adaptor's true and false value for folding, not just
the op's true and false value.
  • Loading branch information
fabianschuiki committed Jan 31, 2024
1 parent eac2a5e commit 2a41164
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Dialect/Comb/CombFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,9 @@ OpFoldResult MuxOp::fold(FoldAdaptor adaptor) {
// mux (c, b, b) -> b
if (getTrueValue() == getFalseValue())
return getTrueValue();
if (auto tv = adaptor.getTrueValue())
if (tv == adaptor.getFalseValue())
return tv;

// mux(0, a, b) -> b
// mux(1, a, b) -> a
Expand Down

0 comments on commit 2a41164

Please sign in to comment.