Skip to content

Commit f8f2b4f

Browse files
committed
Add and (rot X, Y), Z ==/!= -1 --> (and X, Z) ==/!= -1 to foldSetCCWithRotate
1 parent 740da00 commit f8f2b4f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4567,7 +4567,6 @@ static SDValue foldSetCCWithRotate(EVT VT, SDValue N0, SDValue N1,
45674567
// or (rot X, Y), Z ==/!= 0 --> (or X, Z) ==/!= 0
45684568
// or Z, (rot X, Y) ==/!= 0 --> (or X, Z) ==/!= 0
45694569
//
4570-
// TODO: Add the 'and' with -1 sibling.
45714570
// TODO: Recurse through a series of 'or' ops to find the rotate.
45724571
EVT OpVT = N0.getValueType();
45734572
if (N0.hasOneUse() && N0.getOpcode() == ISD::OR && C1->isZero()) {
@@ -4581,6 +4580,21 @@ static SDValue foldSetCCWithRotate(EVT VT, SDValue N0, SDValue N1,
45814580
}
45824581
}
45834582

4583+
// and (rot X, Y), Z ==/!= -1 --> (and X, Z) ==/!= -1
4584+
// and Z, (rot X, Y) ==/!= -1 --> (and X, Z) ==/!= -1
4585+
//
4586+
// TODO: Recursively peek through a series of 'and' ops to find the rotate.
4587+
if (N0.hasOneUse() && N0.getOpcode() == ISD::AND && C1->isAllOnes()) {
4588+
if (SDValue R = getRotateSource(N0.getOperand(0))) {
4589+
SDValue NewAnd = DAG.getNode(ISD::AND, dl, OpVT, R, N0.getOperand(1));
4590+
return DAG.getSetCC(dl, VT, NewAnd, N1, Cond);
4591+
}
4592+
if (SDValue R = getRotateSource(N0.getOperand(1))) {
4593+
SDValue NewAnd = DAG.getNode(ISD::AND, dl, OpVT, R, N0.getOperand(0));
4594+
return DAG.getSetCC(dl, VT, NewAnd, N1, Cond);
4595+
}
4596+
}
4597+
45844598
return SDValue();
45854599
}
45864600

0 commit comments

Comments
 (0)