@@ -5165,17 +5165,19 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
5165
5165
}
5166
5166
5167
5167
// fold (and c1, c2) -> c1&c2
5168
- ConstantSDNode *N0C = getAsNonOpaqueConstant(N0);
5169
5168
ConstantSDNode *N1C = isConstOrConstSplat(N1);
5170
- if (N0C && N1C && !N1C->isOpaque())
5171
- return DAG.FoldConstantArithmetic(ISD::AND, SDLoc(N), VT, N0C, N1C);
5169
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::AND, SDLoc(N), VT, {N0, N1}))
5170
+ return C;
5171
+
5172
5172
// canonicalize constant to RHS
5173
5173
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
5174
5174
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
5175
5175
return DAG.getNode(ISD::AND, SDLoc(N), VT, N1, N0);
5176
+
5176
5177
// fold (and x, -1) -> x
5177
5178
if (isAllOnesConstant(N1))
5178
5179
return N0;
5180
+
5179
5181
// if (and x, c) is known to be zero, return 0
5180
5182
unsigned BitWidth = VT.getScalarSizeInBits();
5181
5183
if (N1C && DAG.MaskedValueIsZero(SDValue(N, 0),
@@ -5866,17 +5868,19 @@ SDValue DAGCombiner::visitOR(SDNode *N) {
5866
5868
}
5867
5869
5868
5870
// fold (or c1, c2) -> c1|c2
5869
- ConstantSDNode *N0C = getAsNonOpaqueConstant(N0);
5870
5871
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
5871
- if (N0C && N1C && !N1C->isOpaque())
5872
- return DAG.FoldConstantArithmetic(ISD::OR, SDLoc(N), VT, N0C, N1C);
5872
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::OR, SDLoc(N), VT, {N0, N1}))
5873
+ return C;
5874
+
5873
5875
// canonicalize constant to RHS
5874
5876
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
5875
5877
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
5876
5878
return DAG.getNode(ISD::OR, SDLoc(N), VT, N1, N0);
5879
+
5877
5880
// fold (or x, 0) -> x
5878
5881
if (isNullConstant(N1))
5879
5882
return N0;
5883
+
5880
5884
// fold (or x, -1) -> -1
5881
5885
if (isAllOnesConstant(N1))
5882
5886
return N1;
@@ -7021,20 +7025,22 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
7021
7025
SDLoc DL(N);
7022
7026
if (N0.isUndef() && N1.isUndef())
7023
7027
return DAG.getConstant(0, DL, VT);
7028
+
7024
7029
// fold (xor x, undef) -> undef
7025
7030
if (N0.isUndef())
7026
7031
return N0;
7027
7032
if (N1.isUndef())
7028
7033
return N1;
7034
+
7029
7035
// fold (xor c1, c2) -> c1^c2
7030
- ConstantSDNode *N0C = getAsNonOpaqueConstant(N0);
7031
- ConstantSDNode *N1C = getAsNonOpaqueConstant(N1);
7032
- if (N0C && N1C)
7033
- return DAG.FoldConstantArithmetic(ISD::XOR, DL, VT, N0C, N1C);
7036
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::XOR, DL, VT, {N0, N1}))
7037
+ return C;
7038
+
7034
7039
// canonicalize constant to RHS
7035
7040
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
7036
7041
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
7037
7042
return DAG.getNode(ISD::XOR, DL, VT, N1, N0);
7043
+
7038
7044
// fold (xor x, 0) -> x
7039
7045
if (isNullConstant(N1))
7040
7046
return N0;
0 commit comments