Skip to content

Commit 272d8e2

Browse files
committed
fix : Inverted Op
1 parent 62e98ae commit 272d8e2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/Dialect/Synth/SynthOps.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ OpFoldResult MajorityInverterOp::fold(FoldAdaptor adaptor) {
7171
// x 1 1 -> 1
7272
// x ~x 1 -> 1
7373
// x 0 0 -> 0
74-
// ~x 0 0 -> 0
7574
// x 1 1 -> 1
76-
// ~x 1 1 -> 1
7775

7876
bool isOpConstant = true;
7977
// for all constant inputs
@@ -103,15 +101,13 @@ OpFoldResult MajorityInverterOp::fold(FoldAdaptor adaptor) {
103101
else
104102
return getOperand(index); // fix if it is a Inverted
105103
}
106-
auto getConstant = [&](unsigned index) -> std::optional<llvm::APInt> {
107-
APInt value;
108-
if (mlir::matchPattern(getInputs()[index], mlir::m_ConstantInt(&value)))
109-
return isInverted(index) ? ~value : value;
110-
return std::nullopt;
111-
};
112104
// Pattern match following cases:
113105
// maj_inv(x, x, y) -> x
114106
// maj_inv(x, y, not y) -> x
107+
auto retIndex = [&](size_t index) {
108+
if (!isInverted(index))
109+
return getOperand(index);
110+
};
115111
for (int i = 0; i < 2; ++i) {
116112
for (int j = i + 1; j < 3; ++j) {
117113
int k = 3 - (i + j);
@@ -120,9 +116,11 @@ OpFoldResult MajorityInverterOp::fold(FoldAdaptor adaptor) {
120116
if (getOperand(i) == getOperand(j)) {
121117
// If they are inverted differently, we can fold to the third.
122118
if (isInverted(i) != isInverted(j)) {
123-
return getOperand(k);
119+
if (!isInverted(k))
120+
return getOperand(k);
124121
}
125-
return getOperand(i);
122+
if (!isInverted(i))
123+
return getOperand(i);
126124
}
127125
}
128126
}

0 commit comments

Comments
 (0)