@@ -4212,6 +4212,56 @@ SDValue TargetLowering::foldSetCCWithAnd(EVT VT, SDValue N0, SDValue N1,
4212
4212
return SDValue ();
4213
4213
}
4214
4214
4215
+ // / This helper function of SimplifySetCC tries to optimize the comparison when
4216
+ // / either operand of the SetCC node is a bitwise-or instruction.
4217
+ SDValue TargetLowering::foldSetCCWithOr (EVT VT, SDValue N0, SDValue N1,
4218
+ ISD::CondCode Cond, const SDLoc &DL,
4219
+ DAGCombinerInfo &DCI) const {
4220
+ if (N1.getOpcode () == ISD::OR && N0.getOpcode () != ISD::OR)
4221
+ std::swap (N0, N1);
4222
+
4223
+ SelectionDAG &DAG = DCI.DAG ;
4224
+ EVT OpVT = N0.getValueType ();
4225
+ if (N0.getOpcode () != ISD::OR || !OpVT.isInteger () ||
4226
+ (Cond != ISD::SETEQ && Cond != ISD::SETNE))
4227
+ return SDValue ();
4228
+
4229
+ // Match these patterns in any of their permutations:
4230
+ // (X | Y) == Y
4231
+ // (X | Y) != Y
4232
+ SDValue X, Y;
4233
+ if (N0.getOperand (0 ) == N1) {
4234
+ X = N0.getOperand (1 );
4235
+ Y = N0.getOperand (0 );
4236
+ } else if (N0.getOperand (1 ) == N1) {
4237
+ X = N0.getOperand (0 );
4238
+ Y = N0.getOperand (1 );
4239
+ } else {
4240
+ return SDValue ();
4241
+ }
4242
+
4243
+ SDValue Zero = DAG.getConstant (0 , DL, OpVT);
4244
+ if (N0.hasOneUse () && hasAndNotCompare (Y)) {
4245
+ // If the target supports an 'and-not' or 'and-complement' logic operation,
4246
+ // try to use that to make a comparison operation more efficient.
4247
+ // But don't do this transform if the mask is a single bit because there are
4248
+ // more efficient ways to deal with that case (for example, 'bt' on x86 or
4249
+ // 'rlwinm' on PPC).
4250
+
4251
+ // Bail out if the compare operand that we want to turn into a zero is
4252
+ // already a zero (otherwise, infinite loop).
4253
+ if (isNullConstant (Y))
4254
+ return SDValue ();
4255
+
4256
+ // Transform this into: X & ~Y == 0.
4257
+ SDValue NotY = DAG.getNOT (SDLoc (Y), Y, OpVT);
4258
+ SDValue NewAnd = DAG.getNode (ISD::AND, SDLoc (N0), OpVT, X, NotY);
4259
+ return DAG.getSetCC (DL, VT, NewAnd, Zero, Cond);
4260
+ }
4261
+
4262
+ return SDValue ();
4263
+ }
4264
+
4215
4265
// / There are multiple IR patterns that could be checking whether certain
4216
4266
// / truncation of a signed number would be lossy or not. The pattern which is
4217
4267
// / best at IR level, may not lower optimally. Thus, we want to unfold it.
@@ -5507,6 +5557,9 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
5507
5557
5508
5558
if (SDValue V = foldSetCCWithAnd (VT, N0, N1, Cond, dl, DCI))
5509
5559
return V;
5560
+
5561
+ if (SDValue V = foldSetCCWithOr (VT, N0, N1, Cond, dl, DCI))
5562
+ return V;
5510
5563
}
5511
5564
5512
5565
// Fold remainder of division by a constant.
0 commit comments