forked from OSchip/llvm-project
[DAGCombiner] visitIMINMAX - use general SelectionDAG::FoldConstantArithmetic
This handles all the constant splat / opaque testing for us instead of the ConstantSDNode variant where we have to do it ourselves.
This commit is contained in:
parent
e5edd641fd
commit
48bd6a0986
|
@ -4321,6 +4321,7 @@ SDValue DAGCombiner::visitIMINMAX(SDNode *N) {
|
||||||
SDValue N0 = N->getOperand(0);
|
SDValue N0 = N->getOperand(0);
|
||||||
SDValue N1 = N->getOperand(1);
|
SDValue N1 = N->getOperand(1);
|
||||||
EVT VT = N0.getValueType();
|
EVT VT = N0.getValueType();
|
||||||
|
unsigned Opcode = N->getOpcode();
|
||||||
|
|
||||||
// fold vector ops
|
// fold vector ops
|
||||||
if (VT.isVector())
|
if (VT.isVector())
|
||||||
|
@ -4328,19 +4329,16 @@ SDValue DAGCombiner::visitIMINMAX(SDNode *N) {
|
||||||
return FoldedVOp;
|
return FoldedVOp;
|
||||||
|
|
||||||
// fold operation with constant operands.
|
// fold operation with constant operands.
|
||||||
ConstantSDNode *N0C = getAsNonOpaqueConstant(N0);
|
if (SDValue C = DAG.FoldConstantArithmetic(Opcode, SDLoc(N), VT, {N0, N1}))
|
||||||
ConstantSDNode *N1C = getAsNonOpaqueConstant(N1);
|
return C;
|
||||||
if (N0C && N1C)
|
|
||||||
return DAG.FoldConstantArithmetic(N->getOpcode(), SDLoc(N), VT, N0C, N1C);
|
|
||||||
|
|
||||||
// canonicalize constant to RHS
|
// canonicalize constant to RHS
|
||||||
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
|
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
|
||||||
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
|
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
|
||||||
return DAG.getNode(N->getOpcode(), SDLoc(N), VT, N1, N0);
|
return DAG.getNode(N->getOpcode(), SDLoc(N), VT, N1, N0);
|
||||||
|
|
||||||
// Is sign bits are zero, flip between UMIN/UMAX and SMIN/SMAX.
|
// Is sign bits are zero, flip between UMIN/UMAX and SMIN/SMAX.
|
||||||
// Only do this if the current op isn't legal and the flipped is.
|
// Only do this if the current op isn't legal and the flipped is.
|
||||||
unsigned Opcode = N->getOpcode();
|
|
||||||
if (!TLI.isOperationLegal(Opcode, VT) &&
|
if (!TLI.isOperationLegal(Opcode, VT) &&
|
||||||
(N0.isUndef() || DAG.SignBitIsZero(N0)) &&
|
(N0.isUndef() || DAG.SignBitIsZero(N0)) &&
|
||||||
(N1.isUndef() || DAG.SignBitIsZero(N1))) {
|
(N1.isUndef() || DAG.SignBitIsZero(N1))) {
|
||||||
|
|
Loading…
Reference in New Issue