Skip to content

Commit a2d0301

Browse files
authored
[AIG] feat : and_inv fold (llvm#8958)
The commit adds a folder `and_inv x, 1 -> x` and `and_inv x, 0 -> 0`.
1 parent 292918f commit a2d0301

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/Dialect/Synth/SynthOps.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ LogicalResult MajorityInverterOp::canonicalize(MajorityInverterOp op,
153153
OpFoldResult AndInverterOp::fold(FoldAdaptor adaptor) {
154154
if (getNumOperands() == 1 && !isInverted(0))
155155
return getOperand(0);
156+
157+
auto inputs = adaptor.getInputs();
158+
if (inputs.size() == 2 && inputs[1]) {
159+
auto value = cast<IntegerAttr>(inputs[1]).getValue();
160+
if (isInverted(1))
161+
value = ~value;
162+
if (value.isZero())
163+
return IntegerAttr::get(
164+
IntegerType::get(getContext(), value.getBitWidth()), value);
165+
if (value.isAllOnes()) {
166+
if (isInverted(0))
167+
return {};
168+
169+
return getOperand(0);
170+
}
171+
}
156172
return {};
157173
}
158174

0 commit comments

Comments
 (0)